Add pdf->postscript conversions

This commit is contained in:
Anton Thomasson 2020-06-06 15:47:43 +02:00
parent 5419ec2c30
commit bfd496138d
3 changed files with 116 additions and 64 deletions

View file

@ -3,7 +3,10 @@ function supported_formats(printer, ConvertChecker)
var formats = printer.attrs["document-format-supported"].value+printer.additionalDocumentFormats;
var mimetypes = [];
var supported = [];
if(has(formats, "application/pdf") || (ConvertChecker.pdf && ( has(formats, "image/pwg-raster") || has(formats, "image/urf"))) )
if(has(formats, "application/pdf") ||
(ConvertChecker.pdf && ( has(formats, "application/postscript") ||
has(formats, "image/pwg-raster") ||
has(formats, "image/urf"))) )
{
mimetypes.push("application/pdf");
supported.push("PDF");
@ -125,7 +128,7 @@ function endsWith(ending, string)
function canConvertPdfTo(type)
{
var targets = ["application/octet-stream", "application/pdf", "image/pwg-raster", "image/urf"];
var targets = ["application/octet-stream", "application/pdf", "application/postscript", "image/pwg-raster", "image/urf"];
return has(targets, type)
}

View file

@ -69,6 +69,7 @@ void ConvertWorker::convertPdf(QNetworkRequest request, QString filename, QTempo
}
bool urf = false;
bool ps = false;
if(targetFormat == "image/urf")
{
@ -78,6 +79,10 @@ void ConvertWorker::convertPdf(QNetworkRequest request, QString filename, QTempo
{
//ok
}
else if(targetFormat == "application/postscript")
{
ps = true;
}
else
{
emit failed(tr("Unsupported target format"));
@ -117,6 +122,41 @@ void ConvertWorker::convertPdf(QNetworkRequest request, QString filename, QTempo
return;
}
if(ps)
{
QProcess* pdftops = new QProcess(this);
pdftops->setProgram("pdftops");
// -duplex?
pdftops->setArguments({"-paper", ShortPaperSize, filename, "-"});
pdftops->setStandardOutputFile(tempfile->fileName(), QIODevice::Append);
connect(pdftops, SIGNAL(finished(int, QProcess::ExitStatus)), pdftops, SLOT(deleteLater()));
pdftops->start();
qDebug() << "Starting";
if(!pdftops->waitForStarted())
{
qDebug() << "pdftops died";
tempfile->deleteLater();
emit failed(tr("Conversion error"));
return;
}
qDebug() << "Started";
if(!pdftops->waitForFinished())
{
qDebug() << "pdftops failed";
tempfile->deleteLater();
emit failed(tr("Conversion error"));
return;
}
}
else
{
QProcess* pdftocairo = new QProcess(this);
pdftocairo->setProgram("pdftocairo");
pdftocairo->setArguments({"-pdf", "-paper", ShortPaperSize, filename, "-"});
@ -181,7 +221,16 @@ void ConvertWorker::convertPdf(QNetworkRequest request, QString filename, QTempo
}
qDebug() << "All started";
ppm2pwg->waitForFinished();
if(!ppm2pwg->waitForFinished())
{
qDebug() << "ppm2pwg failed";
tempfile->deleteLater();
emit failed(tr("Conversion error"));
return;
}
}
qDebug() << "Finished";

View file

@ -286,7 +286,7 @@ QString targetFormatIfAuto(QString documentFormat, QString mimeType, QJsonArray
{
if(mimeType == "application/pdf")
{
return firstMatch(supportedMimeTypes, {"application/pdf", "image/pwg-raster", "image/urf" /*, "application/postscript"*/ });
return firstMatch(supportedMimeTypes, {"application/pdf", "application/postscript", "image/pwg-raster", "image/urf" });
}
else if (mimeType.contains("image"))
{