From 767e4b52fb6222c8dcd23ed51d7af224d59d61d8 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Mon, 30 Dec 2013 17:59:09 +1030 Subject: [PATCH 6/7] pdftocairo: ensure page size and crop box works the same as pdftops Bug 72312 --- utils/pdftocairo.1 | 26 +++++++++----------------- utils/pdftocairo.cc | 20 +++++++++++++++----- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/utils/pdftocairo.1 b/utils/pdftocairo.1 index 7d17eef..c903ffa 100644 --- a/utils/pdftocairo.1 +++ b/utils/pdftocairo.1 @@ -147,7 +147,7 @@ Specifies the height of crop area in pixels (image output) or points (vector out Specifies the size of crop square in pixels (image output) or points (vector output) (sets \-W and \-H) .TP .B \-cropbox -Uses the crop box rather than media box when generating the files +Uses the crop box rather than media box when generating the files (PNG/JPEG/TIFF only) .TP .B \-mono Generate a monochrome file (PNG and TIFF only). @@ -169,32 +169,24 @@ Generate Level 3 PostScript (PS only). This enables all Level 2 features plus shading patterns and masked images. This is the default setting. .TP .B \-origpagesizes -Generate a file with variable page sizes and orientations (PS and PDF -only). The size of each page will be the original page in the PDF -file. If the output is PS the file will contain %%DocumentMedia and -%%PageMedia DSC comments specifying the size of each page. Any -specification of the page size via \-paper, \-paperw, or \-paperh will -get overridden as long as each page of the PDF file has a defined -paper size. +This option is the same as "\-paper match". .TP .BI \-paper " size" Set the paper size to one of "letter", "legal", "A4", or "A3" (PS,PDF,SVG only). This can also be set to "match", which will set -the paper size to match the size specified in the PDF -file. \-origpagesizes overrides this setting if the PDF file has -defined page sizes. +the paper size of each page to match the size specified in the PDF +file. If none the \-paper, \-paperw, or \-paperh options are +specified the default is to match the paper size. .TP .BI \-paperw " size" -Set the paper width, in points (PS,PDF,SVG only). \-origpagesizes overrides this setting -if the PDF file has defined page sizes. +Set the paper width, in points (PS,PDF,SVG only). .TP .BI \-paperh " size" -Set the paper height, in points (PS,PDF,SVG only). \-origpagesizes overrides this setting -if the PDF file has defined page sizes. +Set the paper height, in points (PS,PDF,SVG only). .TP .B \-nocrop -By default, output is cropped to the CropBox specified in the PDF -file. This option disables cropping. +By default, printing output is cropped to the CropBox specified in the PDF +file. This option disables cropping (PS,PDF,SVG only). .TP .B \-expand Expand PDF pages smaller than the paper to fill the paper (PS,PDF,SVG only). By diff --git a/utils/pdftocairo.cc b/utils/pdftocairo.cc index 6c677bd..b8bddb2 100644 --- a/utils/pdftocairo.cc +++ b/utils/pdftocairo.cc @@ -104,7 +104,7 @@ static GooString icc; static GBool level2 = gFalse; static GBool level3 = gFalse; -static GBool doOrigPageSizes = gFalse; +static GBool origPageSizes = gFalse; static char paperSize[15] = ""; static int paperWidth = -1; static int paperHeight = -1; @@ -203,7 +203,7 @@ static const ArgDesc argDesc[] = { "generate Level 2 PostScript (PS, EPS)"}, {"-level3", argFlag, &level3, 0, "generate Level 3 PostScript (PS, EPS)"}, - {"-origpagesizes",argFlag, &doOrigPageSizes,0, + {"-origpagesizes",argFlag, &origPageSizes,0, "conserve original page sizes (PS, PDF, SVG)"}, {"-paper", argString, paperSize, sizeof(paperSize), "paper size (letter, legal, A4, A3, match)"}, @@ -420,7 +420,7 @@ static void getOutputSize(double page_w, double page_h, double *width, double *h { if (printing) { - if (doOrigPageSizes) { + if (origPageSizes) { *width = page_w; *height = page_h; } else { @@ -828,10 +828,11 @@ int main(int argc, char *argv[]) { checkInvalidPrintOption(transp, "-transp"); checkInvalidPrintOption(icc.getCString()[0], "-icc"); checkInvalidPrintOption(singleFile, "-singlefile"); + checkInvalidPrintOption(useCropBox, "-cropbox"); } else { checkInvalidImageOption(level2, "-level2"); checkInvalidImageOption(level3, "-level3"); - checkInvalidImageOption(doOrigPageSizes, "-origpagesizes"); + checkInvalidImageOption(origPageSizes, "-origpagesizes"); checkInvalidImageOption(paperSize[0], "-paper"); checkInvalidImageOption(paperWidth > 0, "-paperw"); checkInvalidImageOption(paperHeight > 0, "-paperh"); @@ -842,6 +843,9 @@ int main(int argc, char *argv[]) { checkInvalidImageOption(duplex, "-duplex"); } + if (printing) + useCropBox = !noCrop; + if (icc.getCString()[0] && !png) { fprintf(stderr, "Error: -icc may only be used with png output.\n"); exit(99); @@ -874,17 +878,23 @@ int main(int argc, char *argv[]) { if (!level2 && !level3) level3 = gTrue; - if (eps && (doOrigPageSizes || paperSize[0] || paperWidth > 0 || paperHeight > 0)) { + if (eps && (origPageSizes || paperSize[0] || paperWidth > 0 || paperHeight > 0)) { fprintf(stderr, "Error: page size options may not be used with eps output.\n"); exit(99); } if (paperSize[0]) { + if (origPageSizes) { + fprintf(stderr, "Error: -origpagesizes and -paper may not be used together.\n"); + exit(99); + } if (!setPSPaperSize(paperSize, paperWidth, paperHeight)) { fprintf(stderr, "Invalid paper size\n"); exit(99); } } + if (paperWidth < 0 || paperHeight < 0) + origPageSizes = gTrue; globalParams = new GlobalParams(); if (quiet) { -- 1.8.3.2