From aa6315acadb063117af548d903295c1f0bd137c0 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Sun, 26 Nov 2017 20:43:15 +1030 Subject: [PATCH 4/8] pdftocairo: add -fl, -ll options for specify page range using page labels Bug #103912 --- utils/pdftocairo.1 | 9 +++++++++ utils/pdftocairo.cc | 32 +++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/utils/pdftocairo.1 b/utils/pdftocairo.1 index 158a21e5..bded4875 100644 --- a/utils/pdftocairo.1 +++ b/utils/pdftocairo.1 @@ -110,6 +110,12 @@ Specifies the first page to convert. .BI \-l " number" Specifies the last page to convert. .TP +.BI \-fl " label" +Specifies the first page label to convert. +.TP +.BI \-ll " label" +Specifies the last page label to convert. +.TP .B \-o Generates only the odd numbered pages. .TP @@ -307,6 +313,9 @@ Error related to PDF permissions. 4 Error related to ICC profile. .TP +5 +Invalid page label. +.TP 99 Other error. .SH JPEG OPTIONS diff --git a/utils/pdftocairo.cc b/utils/pdftocairo.cc index 9c452421..1b53b330 100644 --- a/utils/pdftocairo.cc +++ b/utils/pdftocairo.cc @@ -87,8 +87,10 @@ static GBool printdlg = gFalse; static GBool svg = gFalse; static GBool tiff = gFalse; -static int firstPage = 1; +static int firstPage = 0; static int lastPage = 0; +static GooString firstPageLabel; +static GooString lastPageLabel; static GBool printOnlyOdd = gFalse; static GBool printOnlyEven = gFalse; static GBool singleFile = gFalse; @@ -189,6 +191,10 @@ static const ArgDesc argDesc[] = { "first page to print"}, {"-l", argInt, &lastPage, 0, "last page to print"}, + {"-fl", argGooString, &firstPageLabel, 0, + "first page label to print"}, + {"-ll", argGooString, &lastPageLabel, 0, + "last page label to print"}, {"-o", argFlag, &printOnlyOdd, 0, "print only odd pages"}, {"-e", argFlag, &printOnlyEven, 0, @@ -995,6 +1001,16 @@ int main(int argc, char *argv[]) { fprintf(stderr, "Error: use only one of the output format options (-png, -jpeg, -ps, -eps, -pdf, -printdlg, -print, -svg).\n"); exit(99); } + + if (firstPage != 0 && firstPageLabel.getLength() > 0) { + fprintf(stderr, "Error: use only one of the '-f' and '-fp' options.\n"); + exit(99); + } + if (lastPage != 0 && lastPageLabel.getLength() > 0) { + fprintf(stderr, "Error: use only one of the '-l' and '-lp' options.\n"); + exit(99); + } + if (png || jpeg || tiff) printing = gFalse; else @@ -1183,6 +1199,20 @@ int main(int argc, char *argv[]) { #endif // get page range + if (firstPageLabel.getLength() > 0) { + if (!doc->getCatalog()->labelToIndex(&firstPageLabel, &firstPage)) { + fprintf(stderr, "Error: unknown page label \"%s\"\n", firstPageLabel.getCString()); + exit(5); + } + firstPage++; // labelToIndex() uses 0 based page numbers + } + if (lastPageLabel.getLength() > 0) { + if (!doc->getCatalog()->labelToIndex(&lastPageLabel, &lastPage)) { + fprintf(stderr, "Error: unknown page label \"%s\"\n", lastPageLabel.getCString()); + exit(5); + } + lastPage++; // labelToIndex() uses 0 based page numbers + } if (firstPage < 1) firstPage = 1; if (singleFile && lastPage < 1) -- 2.11.0