diff --git a/qml/pages/PrinterPage.qml b/qml/pages/PrinterPage.qml index 7f9ce90..7be41c3 100644 --- a/qml/pages/PrinterPage.qml +++ b/qml/pages/PrinterPage.qml @@ -13,6 +13,7 @@ Page { property var printer property var jobParams: new Object(); property string selectedFile + property string selectedFileType: Mimer.get_type(selectedFile) Connections { @@ -90,7 +91,7 @@ Page { valid: utils.isValid(name) choices: utils.getChoices(name) default_choice: utils.getDefaultChoice(name) - mime_type: Mimer.get_type(selectedFile) + mime_type: selectedFileType onChoiceChanged: page.choiceMade(name, tag, choice) } @@ -101,7 +102,7 @@ Page { valid: utils.isValid(name) choices: utils.getChoices(name) default_choice: utils.getDefaultChoice(name) - mime_type: Mimer.get_type(selectedFile) + mime_type: selectedFileType onChoiceChanged: page.choiceMade(name, tag, choice) } @@ -123,7 +124,7 @@ Page { valid: utils.isValid(name) choices: utils.getChoices(name) default_choice: utils.getDefaultChoice(name) - mime_type: Mimer.get_type(selectedFile) + mime_type: selectedFileType onChoiceChanged: page.choiceMade(name, tag, choice) } @@ -131,7 +132,8 @@ Page { tag: IppMsg.IntegerRange name: "page-ranges" prettyName: qsTr("Page range") - valid: (utils.isValid(name) || ConvertChecker.pdf) && Mimer.get_type(selectedFile) == "application/pdf" + valid: (utils.isValid(name) || ConvertChecker.pdf) && + (selectedFileType == "application/pdf" || Mimer.isOffice(selectedFileType)) property var pdfpages: ConvertChecker.pdfPages(selectedFile) high: name=="page-ranges" ? (pdfpages == 0 ? 65535 : pdfpages) : 0 @@ -145,7 +147,7 @@ Page { valid: utils.isValid(name) choices: utils.getChoices(name) default_choice: utils.getDefaultChoice(name) - mime_type: Mimer.get_type(selectedFile) + mime_type: selectedFileType onChoiceChanged: page.choiceMade(name, tag, choice) } @@ -156,7 +158,7 @@ Page { valid: utils.isValid(name) choices: utils.getChoices(name) default_choice: utils.getDefaultChoice(name) - mime_type: Mimer.get_type(selectedFile) + mime_type: selectedFileType onChoiceChanged: page.choiceMade(name, tag, choice) } @@ -167,7 +169,7 @@ Page { valid: utils.isValid(name) choices: utils.getChoices(name) default_choice: utils.getDefaultChoice(name) - mime_type: Mimer.get_type(selectedFile) + mime_type: selectedFileType onChoiceChanged: page.choiceMade(name, tag, choice) } @@ -178,7 +180,7 @@ Page { valid: utils.isValid(name) choices: utils.getChoices(name) default_choice: utils.getDefaultChoice(name) - mime_type: Mimer.get_type(selectedFile) + mime_type: selectedFileType onChoiceChanged: page.choiceMade(name, tag, choice) } @@ -189,7 +191,7 @@ Page { valid: utils.isValid(name) choices: utils.getChoices(name) default_choice: utils.getDefaultChoice(name) - mime_type: Mimer.get_type(selectedFile) + mime_type: selectedFileType onChoiceChanged: page.choiceMade(name, tag, choice) } diff --git a/src/convertworker.cpp b/src/convertworker.cpp index 4f42527..ec470fd 100644 --- a/src/convertworker.cpp +++ b/src/convertworker.cpp @@ -502,7 +502,7 @@ try { PageRangeLow=1; } - if(PageRangeHigh==0) + if(PageRangeHigh==0 || PageRangeHigh > pages) { PageRangeHigh=pages; } @@ -515,12 +515,50 @@ try { if(targetFormat == Mimer::PDF) { - // TODO Page ranges + if(PageRangeLow != 1 || PageRangeHigh != pages) + { + qDebug() << "adjusting pages in PDF" << PageRangeLow << PageRangeHigh; - QFile tempfileAsFile(tempfile->fileName()); - tempfileAsFile.open(QIODevice::Append); - tempfileAsFile.write(tmpPdfFile.readAll()); - tempfileAsFile.close(); + QProcess* PdftoCairo = new QProcess(this); + PdftoCairo->setProgram("pdftocairo"); + QStringList PdfToCairoArgs = {"-pdf"}; + + PdfToCairoArgs << QStringList {"-f", QString::number(PageRangeLow), "-l", QString::number(PageRangeHigh)}; + + PdfToCairoArgs << QStringList {tmpPdfFile.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() << "PdftoCairo Starting"; + + if(!PdftoCairo->waitForStarted()) + { + qDebug() << "pdftocairo died"; + throw ConvertFailedException(); + } + + qDebug() << "PdftoCairo Started"; + + if(!PdftoCairo->waitForFinished(-1)) + { + qDebug() << "pdftocairo failed"; + throw ConvertFailedException(); + } + + } + else + { + QFile tempfileAsFile(tempfile->fileName()); + tempfileAsFile.open(QIODevice::Append); + tempfileAsFile.write(tmpPdfFile.readAll()); + tempfileAsFile.close(); + } } else if(targetFormat == Mimer::Postscript) diff --git a/src/ippprinter.cpp b/src/ippprinter.cpp index cfa8fff..23619b7 100644 --- a/src/ippprinter.cpp +++ b/src/ippprinter.cpp @@ -464,7 +464,7 @@ void IppPrinter::print(QJsonObject attrs, QString filename, bool alwaysConvert, } QString Sides = getAttrOrDefault(attrs, "sides").toString(); - if(documentFormat == Mimer::PWG || documentFormat == Mimer::URF || documentFormat == Mimer::Postscript) + if(documentFormat == Mimer::PWG || documentFormat == Mimer::URF || documentFormat == Mimer::Postscript || Mimer::isOffice(mimeType)) { // Effected locally attrs.remove("page-ranges"); }