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 formats = printer.attrs["document-format-supported"].value+printer.additionalDocumentFormats;
var mimetypes = []; var mimetypes = [];
var supported = []; 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"); mimetypes.push("application/pdf");
supported.push("PDF"); supported.push("PDF");
@ -125,7 +128,7 @@ function endsWith(ending, string)
function canConvertPdfTo(type) 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) return has(targets, type)
} }

View file

@ -69,6 +69,7 @@ void ConvertWorker::convertPdf(QNetworkRequest request, QString filename, QTempo
} }
bool urf = false; bool urf = false;
bool ps = false;
if(targetFormat == "image/urf") if(targetFormat == "image/urf")
{ {
@ -78,6 +79,10 @@ void ConvertWorker::convertPdf(QNetworkRequest request, QString filename, QTempo
{ {
//ok //ok
} }
else if(targetFormat == "application/postscript")
{
ps = true;
}
else else
{ {
emit failed(tr("Unsupported target format")); emit failed(tr("Unsupported target format"));
@ -117,71 +122,115 @@ void ConvertWorker::convertPdf(QNetworkRequest request, QString filename, QTempo
return; return;
} }
QProcess* pdftocairo = new QProcess(this); if(ps)
pdftocairo->setProgram("pdftocairo");
pdftocairo->setArguments({"-pdf", "-paper", ShortPaperSize, filename, "-"});
QProcess* pdftoppm = new QProcess(this);
pdftoppm->setProgram("pdftoppm");
QStringList Pdf2PpmArgs = {"-rx", QString::number(HwResX), "-ry", QString::number(HwResY)};
if(Colors != 3)
{ {
Pdf2PpmArgs.append("-gray"); 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;
}
} }
pdftoppm->setArguments(Pdf2PpmArgs); else
QProcess* ppm2pwg = new QProcess(this);
// Yo dawg, I heard you like programs...
ppm2pwg->setProgram("harbour-seaprint");
ppm2pwg->setArguments({"ppm2pwg"});
QStringList env;
ppm2PwgEnv(env, urf, Quality, PaperSize, HwResX, HwResY, TwoSided, Tumble, pages);
qDebug() << "ppm2pwg env is " << env;
ppm2pwg->setEnvironment(env);
pdftocairo->setStandardOutputProcess(pdftoppm);
pdftoppm->setStandardOutputProcess(ppm2pwg);
ppm2pwg->setStandardOutputFile(tempfile->fileName(), QIODevice::Append);
connect(pdftocairo, SIGNAL(finished(int, QProcess::ExitStatus)), pdftocairo, SLOT(deleteLater()));
connect(pdftoppm, SIGNAL(finished(int, QProcess::ExitStatus)), pdftoppm, SLOT(deleteLater()));
connect(ppm2pwg, SIGNAL(finished(int, QProcess::ExitStatus)), ppm2pwg, SLOT(deleteLater()));
qDebug() << "All connected";
pdftocairo->start();
pdftoppm->start();
ppm2pwg->start();
qDebug() << "Starting";
if(!pdftocairo->waitForStarted())
{ {
qDebug() << "pdftocairo died";
tempfile->deleteLater();
emit failed(tr("Conversion error"));
return;
}
if(!pdftoppm->waitForStarted())
{
qDebug() << "pdftoppm died";
tempfile->deleteLater();
emit failed(tr("Conversion error"));
return;
}
if(!ppm2pwg->waitForStarted())
{
qDebug() << "ppm2pwg died";
tempfile->deleteLater();
emit failed(tr("Conversion error"));
return;
}
qDebug() << "All started";
ppm2pwg->waitForFinished(); QProcess* pdftocairo = new QProcess(this);
pdftocairo->setProgram("pdftocairo");
pdftocairo->setArguments({"-pdf", "-paper", ShortPaperSize, filename, "-"});
QProcess* pdftoppm = new QProcess(this);
pdftoppm->setProgram("pdftoppm");
QStringList Pdf2PpmArgs = {"-rx", QString::number(HwResX), "-ry", QString::number(HwResY)};
if(Colors != 3)
{
Pdf2PpmArgs.append("-gray");
}
pdftoppm->setArguments(Pdf2PpmArgs);
QProcess* ppm2pwg = new QProcess(this);
// Yo dawg, I heard you like programs...
ppm2pwg->setProgram("harbour-seaprint");
ppm2pwg->setArguments({"ppm2pwg"});
QStringList env;
ppm2PwgEnv(env, urf, Quality, PaperSize, HwResX, HwResY, TwoSided, Tumble, pages);
qDebug() << "ppm2pwg env is " << env;
ppm2pwg->setEnvironment(env);
pdftocairo->setStandardOutputProcess(pdftoppm);
pdftoppm->setStandardOutputProcess(ppm2pwg);
ppm2pwg->setStandardOutputFile(tempfile->fileName(), QIODevice::Append);
connect(pdftocairo, SIGNAL(finished(int, QProcess::ExitStatus)), pdftocairo, SLOT(deleteLater()));
connect(pdftoppm, SIGNAL(finished(int, QProcess::ExitStatus)), pdftoppm, SLOT(deleteLater()));
connect(ppm2pwg, SIGNAL(finished(int, QProcess::ExitStatus)), ppm2pwg, SLOT(deleteLater()));
qDebug() << "All connected";
pdftocairo->start();
pdftoppm->start();
ppm2pwg->start();
qDebug() << "Starting";
if(!pdftocairo->waitForStarted())
{
qDebug() << "pdftocairo died";
tempfile->deleteLater();
emit failed(tr("Conversion error"));
return;
}
if(!pdftoppm->waitForStarted())
{
qDebug() << "pdftoppm died";
tempfile->deleteLater();
emit failed(tr("Conversion error"));
return;
}
if(!ppm2pwg->waitForStarted())
{
qDebug() << "ppm2pwg died";
tempfile->deleteLater();
emit failed(tr("Conversion error"));
return;
}
qDebug() << "All started";
if(!ppm2pwg->waitForFinished())
{
qDebug() << "ppm2pwg failed";
tempfile->deleteLater();
emit failed(tr("Conversion error"));
return;
}
}
qDebug() << "Finished"; qDebug() << "Finished";

View file

@ -286,7 +286,7 @@ QString targetFormatIfAuto(QString documentFormat, QString mimeType, QJsonArray
{ {
if(mimeType == "application/pdf") 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")) else if (mimeType.contains("image"))
{ {