Allow the page range setting in more cases
=if the attribute is supported or pdf processing tools are installed
This commit is contained in:
parent
741d10120a
commit
f6d6b51b9f
3 changed files with 72 additions and 12 deletions
|
@ -115,7 +115,7 @@ Page {
|
|||
})
|
||||
break
|
||||
case IppMsg.IntegerRange:
|
||||
var valid = printer.attrs.hasOwnProperty(name+"-supported") &&
|
||||
var valid = (printer.attrs.hasOwnProperty(name+"-supported") || ConvertChecker.pdf)&&
|
||||
name=="page-ranges" && Mimer.get_type(selectedFile) == "application/pdf";
|
||||
var pdfpages = ConvertChecker.pdfPages(selectedFile);
|
||||
loader.setSource("../components/RangeSetting.qml",
|
||||
|
|
|
@ -63,6 +63,7 @@ void ConvertWorker::convertPdf(QNetworkRequest request, QString filename, QTempo
|
|||
|
||||
bool urf = false;
|
||||
bool ps = false;
|
||||
bool pdf = false;
|
||||
|
||||
if(targetFormat == "image/urf")
|
||||
{
|
||||
|
@ -76,6 +77,10 @@ void ConvertWorker::convertPdf(QNetworkRequest request, QString filename, QTempo
|
|||
{
|
||||
ps = true;
|
||||
}
|
||||
else if (targetFormat == "application/pdf")
|
||||
{
|
||||
pdf = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
emit failed(tr("Unsupported target format"));
|
||||
|
@ -130,6 +135,7 @@ void ConvertWorker::convertPdf(QNetworkRequest request, QString filename, QTempo
|
|||
}
|
||||
PdfToPsArgs << QStringList {"-paper", ShortPaperSize, filename, "-"};
|
||||
|
||||
qDebug() << "pdftops args is " << PdfToPsArgs;
|
||||
pdftops->setArguments(PdfToPsArgs);
|
||||
|
||||
pdftops->setStandardOutputFile(tempfile->fileName(), QIODevice::Append);
|
||||
|
@ -157,6 +163,46 @@ void ConvertWorker::convertPdf(QNetworkRequest request, QString filename, QTempo
|
|||
return;
|
||||
}
|
||||
}
|
||||
else if(pdf)
|
||||
{
|
||||
QProcess* pdftocairo = new QProcess(this);
|
||||
pdftocairo->setProgram("pdftocairo");
|
||||
QStringList PdfToCairoArgs = {"-pdf"};
|
||||
|
||||
if(PageRangeLow != 0)
|
||||
{
|
||||
PdfToCairoArgs << QStringList {"-f", QString::number(PageRangeLow), "-l", QString::number(PageRangeHigh)};
|
||||
}
|
||||
PdfToCairoArgs << QStringList {"-paper", ShortPaperSize, filename, "-"};
|
||||
|
||||
qDebug() << "pdftocairo args is " << PdfToCairoArgs;
|
||||
pdftocairo->setArguments(PdfToCairoArgs);
|
||||
|
||||
pdftocairo->setStandardOutputFile(tempfile->fileName(), QIODevice::Append);
|
||||
connect(pdftocairo, SIGNAL(finished(int, QProcess::ExitStatus)), pdftocairo, SLOT(deleteLater()));
|
||||
|
||||
pdftocairo->start();
|
||||
|
||||
qDebug() << "Starting";
|
||||
|
||||
if(!pdftocairo->waitForStarted())
|
||||
{
|
||||
qDebug() << "pdftocairo died";
|
||||
tempfile->deleteLater();
|
||||
emit failed(tr("Conversion error"));
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug() << "Started";
|
||||
|
||||
if(!pdftocairo->waitForFinished(10000+5000*pages))
|
||||
{
|
||||
qDebug() << "pdftocairo failed";
|
||||
tempfile->deleteLater();
|
||||
emit failed(tr("Conversion error"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
|
|
@ -422,6 +422,7 @@ void IppPrinter::print(QJsonObject attrs, QString filename,
|
|||
|
||||
QString PrintColorMode = getAttrOrDefault(attrs, "print-color-mode").toString();
|
||||
quint32 Colors = PrintColorMode.contains("color") ? 3 : PrintColorMode.contains("monochrome") ? 1 : 0;
|
||||
bool pdfPageRangeAdjustNeeded = false;
|
||||
|
||||
if(!PaperSizes.contains(PaperSize))
|
||||
{
|
||||
|
@ -429,26 +430,34 @@ void IppPrinter::print(QJsonObject attrs, QString filename,
|
|||
return;
|
||||
}
|
||||
|
||||
quint32 PageRangeLow = 0;
|
||||
quint32 PageRangeHigh = 0;
|
||||
if(attrs.contains("page-ranges"))
|
||||
{
|
||||
QJsonObject PageRanges = getAttrOrDefault(attrs, "page-ranges").toObject();
|
||||
PageRangeLow = PageRanges["low"].toInt();
|
||||
PageRangeHigh = PageRanges["high"].toInt();
|
||||
}
|
||||
|
||||
QString Sides = getAttrOrDefault(attrs, "sides").toString();
|
||||
if(removeRedundantConvertAttrs && (documentFormat=="image/pwg-raster" ||
|
||||
documentFormat=="image/urf"))
|
||||
documentFormat=="image/urf"))
|
||||
{
|
||||
attrs.remove("sides");
|
||||
attrs.remove("print-color-mode");
|
||||
attrs.remove("page-ranges");
|
||||
}
|
||||
if(removeRedundantConvertAttrs && documentFormat == "application/postscript")
|
||||
else if(removeRedundantConvertAttrs && documentFormat == "application/postscript")
|
||||
{
|
||||
attrs.remove("sides");
|
||||
attrs.remove("page-ranges");
|
||||
}
|
||||
quint32 PageRangeLow = 0;
|
||||
quint32 PageRangeHigh = 0;
|
||||
if(mimeType == "application/pdf" && documentFormat != "application/pdf")
|
||||
else if (documentFormat == "application/pdf")
|
||||
{
|
||||
if(attrs.contains("page-ranges"))
|
||||
if(attrs.contains("page-ranges") && !_attrs.contains("page-ranges-supported"))
|
||||
{
|
||||
QJsonObject PageRanges = getAttrOrDefault(attrs, "page-ranges").toObject();
|
||||
PageRangeLow = PageRanges["low"].toInt();
|
||||
PageRangeHigh = PageRanges["high"].toInt();
|
||||
pdfPageRangeAdjustNeeded = true;
|
||||
attrs.remove("page-ranges");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -457,8 +466,13 @@ void IppPrinter::print(QJsonObject attrs, QString filename,
|
|||
|
||||
IppMsg job = mk_msg(o, attrs);
|
||||
QByteArray contents = job.encode(IppMsg::PrintJob);
|
||||
// Always convert non-jpeg images to get resizing
|
||||
if((mimeType == documentFormat) && (documentFormat == "image/jpeg" || !mimeType.contains("image")))
|
||||
|
||||
// Non-jpeg images, Postscript and PDF (when not adjusting pages locally)
|
||||
// Always convert non-jpeg images to get resizing
|
||||
// TODO: make this sane
|
||||
if((mimeType == documentFormat)
|
||||
&& (documentFormat == "image/jpeg" || !mimeType.contains("image"))
|
||||
&& !((documentFormat == "application/pdf") && pdfPageRangeAdjustNeeded))
|
||||
{
|
||||
QByteArray filedata = file.readAll();
|
||||
contents = contents.append(filedata);
|
||||
|
|
Loading…
Reference in a new issue