Add page-ranges for office documents
This commit is contained in:
parent
f36488c1b7
commit
905745714c
3 changed files with 56 additions and 16 deletions
|
@ -13,6 +13,7 @@ Page {
|
||||||
property var printer
|
property var printer
|
||||||
property var jobParams: new Object();
|
property var jobParams: new Object();
|
||||||
property string selectedFile
|
property string selectedFile
|
||||||
|
property string selectedFileType: Mimer.get_type(selectedFile)
|
||||||
|
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
|
@ -90,7 +91,7 @@ Page {
|
||||||
valid: utils.isValid(name)
|
valid: utils.isValid(name)
|
||||||
choices: utils.getChoices(name)
|
choices: utils.getChoices(name)
|
||||||
default_choice: utils.getDefaultChoice(name)
|
default_choice: utils.getDefaultChoice(name)
|
||||||
mime_type: Mimer.get_type(selectedFile)
|
mime_type: selectedFileType
|
||||||
|
|
||||||
onChoiceChanged: page.choiceMade(name, tag, choice)
|
onChoiceChanged: page.choiceMade(name, tag, choice)
|
||||||
}
|
}
|
||||||
|
@ -101,7 +102,7 @@ Page {
|
||||||
valid: utils.isValid(name)
|
valid: utils.isValid(name)
|
||||||
choices: utils.getChoices(name)
|
choices: utils.getChoices(name)
|
||||||
default_choice: utils.getDefaultChoice(name)
|
default_choice: utils.getDefaultChoice(name)
|
||||||
mime_type: Mimer.get_type(selectedFile)
|
mime_type: selectedFileType
|
||||||
|
|
||||||
onChoiceChanged: page.choiceMade(name, tag, choice)
|
onChoiceChanged: page.choiceMade(name, tag, choice)
|
||||||
}
|
}
|
||||||
|
@ -123,7 +124,7 @@ Page {
|
||||||
valid: utils.isValid(name)
|
valid: utils.isValid(name)
|
||||||
choices: utils.getChoices(name)
|
choices: utils.getChoices(name)
|
||||||
default_choice: utils.getDefaultChoice(name)
|
default_choice: utils.getDefaultChoice(name)
|
||||||
mime_type: Mimer.get_type(selectedFile)
|
mime_type: selectedFileType
|
||||||
|
|
||||||
onChoiceChanged: page.choiceMade(name, tag, choice)
|
onChoiceChanged: page.choiceMade(name, tag, choice)
|
||||||
}
|
}
|
||||||
|
@ -131,7 +132,8 @@ Page {
|
||||||
tag: IppMsg.IntegerRange
|
tag: IppMsg.IntegerRange
|
||||||
name: "page-ranges"
|
name: "page-ranges"
|
||||||
prettyName: qsTr("Page range")
|
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)
|
property var pdfpages: ConvertChecker.pdfPages(selectedFile)
|
||||||
high: name=="page-ranges" ? (pdfpages == 0 ? 65535 : pdfpages) : 0
|
high: name=="page-ranges" ? (pdfpages == 0 ? 65535 : pdfpages) : 0
|
||||||
|
@ -145,7 +147,7 @@ Page {
|
||||||
valid: utils.isValid(name)
|
valid: utils.isValid(name)
|
||||||
choices: utils.getChoices(name)
|
choices: utils.getChoices(name)
|
||||||
default_choice: utils.getDefaultChoice(name)
|
default_choice: utils.getDefaultChoice(name)
|
||||||
mime_type: Mimer.get_type(selectedFile)
|
mime_type: selectedFileType
|
||||||
|
|
||||||
onChoiceChanged: page.choiceMade(name, tag, choice)
|
onChoiceChanged: page.choiceMade(name, tag, choice)
|
||||||
}
|
}
|
||||||
|
@ -156,7 +158,7 @@ Page {
|
||||||
valid: utils.isValid(name)
|
valid: utils.isValid(name)
|
||||||
choices: utils.getChoices(name)
|
choices: utils.getChoices(name)
|
||||||
default_choice: utils.getDefaultChoice(name)
|
default_choice: utils.getDefaultChoice(name)
|
||||||
mime_type: Mimer.get_type(selectedFile)
|
mime_type: selectedFileType
|
||||||
|
|
||||||
onChoiceChanged: page.choiceMade(name, tag, choice)
|
onChoiceChanged: page.choiceMade(name, tag, choice)
|
||||||
}
|
}
|
||||||
|
@ -167,7 +169,7 @@ Page {
|
||||||
valid: utils.isValid(name)
|
valid: utils.isValid(name)
|
||||||
choices: utils.getChoices(name)
|
choices: utils.getChoices(name)
|
||||||
default_choice: utils.getDefaultChoice(name)
|
default_choice: utils.getDefaultChoice(name)
|
||||||
mime_type: Mimer.get_type(selectedFile)
|
mime_type: selectedFileType
|
||||||
|
|
||||||
onChoiceChanged: page.choiceMade(name, tag, choice)
|
onChoiceChanged: page.choiceMade(name, tag, choice)
|
||||||
}
|
}
|
||||||
|
@ -178,7 +180,7 @@ Page {
|
||||||
valid: utils.isValid(name)
|
valid: utils.isValid(name)
|
||||||
choices: utils.getChoices(name)
|
choices: utils.getChoices(name)
|
||||||
default_choice: utils.getDefaultChoice(name)
|
default_choice: utils.getDefaultChoice(name)
|
||||||
mime_type: Mimer.get_type(selectedFile)
|
mime_type: selectedFileType
|
||||||
|
|
||||||
onChoiceChanged: page.choiceMade(name, tag, choice)
|
onChoiceChanged: page.choiceMade(name, tag, choice)
|
||||||
}
|
}
|
||||||
|
@ -189,7 +191,7 @@ Page {
|
||||||
valid: utils.isValid(name)
|
valid: utils.isValid(name)
|
||||||
choices: utils.getChoices(name)
|
choices: utils.getChoices(name)
|
||||||
default_choice: utils.getDefaultChoice(name)
|
default_choice: utils.getDefaultChoice(name)
|
||||||
mime_type: Mimer.get_type(selectedFile)
|
mime_type: selectedFileType
|
||||||
|
|
||||||
onChoiceChanged: page.choiceMade(name, tag, choice)
|
onChoiceChanged: page.choiceMade(name, tag, choice)
|
||||||
}
|
}
|
||||||
|
|
|
@ -502,7 +502,7 @@ try {
|
||||||
PageRangeLow=1;
|
PageRangeLow=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(PageRangeHigh==0)
|
if(PageRangeHigh==0 || PageRangeHigh > pages)
|
||||||
{
|
{
|
||||||
PageRangeHigh=pages;
|
PageRangeHigh=pages;
|
||||||
}
|
}
|
||||||
|
@ -515,12 +515,50 @@ try {
|
||||||
if(targetFormat == Mimer::PDF)
|
if(targetFormat == Mimer::PDF)
|
||||||
{
|
{
|
||||||
|
|
||||||
// TODO Page ranges
|
if(PageRangeLow != 1 || PageRangeHigh != pages)
|
||||||
|
{
|
||||||
|
qDebug() << "adjusting pages in PDF" << PageRangeLow << PageRangeHigh;
|
||||||
|
|
||||||
QFile tempfileAsFile(tempfile->fileName());
|
QProcess* PdftoCairo = new QProcess(this);
|
||||||
tempfileAsFile.open(QIODevice::Append);
|
PdftoCairo->setProgram("pdftocairo");
|
||||||
tempfileAsFile.write(tmpPdfFile.readAll());
|
QStringList PdfToCairoArgs = {"-pdf"};
|
||||||
tempfileAsFile.close();
|
|
||||||
|
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)
|
else if(targetFormat == Mimer::Postscript)
|
||||||
|
|
|
@ -464,7 +464,7 @@ void IppPrinter::print(QJsonObject attrs, QString filename, bool alwaysConvert,
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Sides = getAttrOrDefault(attrs, "sides").toString();
|
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
|
{ // Effected locally
|
||||||
attrs.remove("page-ranges");
|
attrs.remove("page-ranges");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue