summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorAdrian Johnson <ajohnson@redneon.com>2014-09-07 20:18:36 +0930
committerAdrian Johnson <ajohnson@redneon.com>2014-10-21 22:04:23 +1030
commit700205af19ef1ae5f2c713d118ebd5dd4a0afba3 (patch)
treeab05bdf272fdaa1418210220060332574cf06d62 /utils
parent40d3ae87befad489fd8c0b38ff2561a0782cae0b (diff)
pdftocairo: Allow an output file for win32 printing to be specified
Can be used for testing win32 print output without wasting paper.
Diffstat (limited to 'utils')
-rw-r--r--utils/pdftocairo-win32.cc12
-rw-r--r--utils/pdftocairo.14
-rw-r--r--utils/pdftocairo.cc13
3 files changed, 19 insertions, 10 deletions
diff --git a/utils/pdftocairo-win32.cc b/utils/pdftocairo-win32.cc
index 515ffa72..195e6ad7 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 <stdin>";
- 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 77474094..87257228 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 79d71d9b..65d7c231 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);