From adefcdb71caf57dd9b5466b7f5fa6f3497f861f1 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Sun, 7 Sep 2014 20:18:36 +0930 Subject: [PATCH 5/9] pdftocairo: Allow an output file for win32 printing to be specified Can be used for testing win32 print output without wasting paper. Select a PS printer and view the output with GSview. --- utils/pdftocairo-win32.cc | 12 ++++++++---- utils/pdftocairo.1 | 4 ++++ utils/pdftocairo.cc | 13 +++++++------ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/utils/pdftocairo-win32.cc b/utils/pdftocairo-win32.cc index 515ffa7..195e6ad 100644 --- a/utils/pdftocairo-win32.cc +++ b/utils/pdftocairo-win32.cc @@ -136,7 +136,7 @@ static void fillPrinterOptions(DEVMODEA *devmode) } } -static void win32BeginDocument(GooString *outputFileName, double w, double h) +static void win32BeginDocument(GooString *inputFileName, GooString *outputFileName, double w, double h) { if (!print) return; @@ -182,10 +182,14 @@ static void win32BeginDocument(GooString *outputFileName, double w, double h) DOCINFOA docinfo; memset(&docinfo, 0, sizeof(docinfo)); docinfo.cbSize = sizeof(docinfo); - if (outputFileName->cmp("fd://0") == 0) + if (inputFileName->cmp("fd://0") == 0) { docinfo.lpszDocName = "pdftocairo "; - else - docinfo.lpszDocName = outputFileName->getCString(); + } else { + docinfo.lpszDocName = inputFileName->getCString(); + } + if (outputFileName) { + docinfo.lpszOutput = outputFileName->getCString(); + } if (StartDocA(hdc, &docinfo) <=0) { fprintf(stderr, "Error: StartDoc failed"); exit(99); diff --git a/utils/pdftocairo.1 b/utils/pdftocairo.1 index 7747409..8725722 100644 --- a/utils/pdftocairo.1 +++ b/utils/pdftocairo.1 @@ -23,6 +23,8 @@ PostScript (PS) Encapsulated PostScript (EPS) .IP \(bu Scalable Vector Graphics (SVG) +.IP \(bu +Windows Printer .PP .B pdftocairo reads the PDF file, @@ -82,6 +84,8 @@ Generates a PDF file .TP .BI \-print (Windows only) Prints to a system printer. See also \-printer and \-printeropt. + If an output file is not specified, the output will be sent to the printer. + The output file '-' can not be used with this option. .TP .BI \-ps Generate a PS file diff --git a/utils/pdftocairo.cc b/utils/pdftocairo.cc index 79d71d9..65d7c23 100644 --- a/utils/pdftocairo.cc +++ b/utils/pdftocairo.cc @@ -500,7 +500,7 @@ static cairo_status_t writeStream(void *closure, const unsigned char *data, unsi return CAIRO_STATUS_WRITE_ERROR; } -static void beginDocument(GooString *outputFileName, double w, double h) +static void beginDocument(GooString *inputFileName, GooString *outputFileName, double w, double h) { if (printing) { if (!print) { @@ -541,7 +541,7 @@ static void beginDocument(GooString *outputFileName, double w, double h) #endif } #ifdef CAIRO_HAS_WIN32_SURFACE - win32BeginDocument(outputFileName, w, h); + win32BeginDocument(inputFileName, outputFileName, w, h); #endif } } @@ -731,7 +731,7 @@ static GooString *getOutputFileName(GooString *fileName, GooString *outputName) if (outputName) { if (outputName->cmp("-") == 0) { - if (!printing && !singleFile) { + if (print || (!printing && !singleFile)) { fprintf(stderr, "Error: stdout may only be used with the ps, eps, pdf, svg output options or if -singlefile is used.\n"); exit(99); } @@ -740,8 +740,9 @@ static GooString *getOutputFileName(GooString *fileName, GooString *outputName) return new GooString(outputName); } - if (print) - return fileName; //it will be used as the job name + if (print) { + return NULL; // No output file means print to printer + } if (fileName->cmp("fd://0") == 0) { fprintf(stderr, "Error: an output filename or '-' must be supplied when the PDF file is stdin.\n"); @@ -1090,7 +1091,7 @@ int main(int argc, char *argv[]) { getOutputSize(pg_w, pg_h, &output_w, &output_h); if (pg == firstPage) - beginDocument(outputFileName, output_w, output_h); + beginDocument(fileName, outputFileName, output_w, output_h); beginPage(output_w, output_h); renderPage(doc, cairoOut, pg, pg_w, pg_h, output_w, output_h); endPage(imageFileName); -- 2.1.0