Add page-ranges for office documents

This commit is contained in:
Anton Thomasson 2021-03-06 17:20:51 +01:00
parent f36488c1b7
commit 905745714c
3 changed files with 56 additions and 16 deletions

View file

@ -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)
}

View file

@ -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)

View file

@ -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");
}