From 1be145529bc34621a26b134ed0da1f2c6888229f Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Sun, 5 Oct 2014 18:11:09 +1030 Subject: [PATCH 5/5] pdftocairo: add a -setupdlg option that will the show printer properties dialog when printing to a win32 printer. --- utils/pdftocairo-win32.cc | 22 +++++++++++++++++++--- utils/pdftocairo-win32.h | 3 ++- utils/pdftocairo.1 | 5 +++++ utils/pdftocairo.cc | 24 ++++++++++++++++-------- 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/utils/pdftocairo-win32.cc b/utils/pdftocairo-win32.cc index dcabb69..de7da57 100644 --- a/utils/pdftocairo-win32.cc +++ b/utils/pdftocairo-win32.cc @@ -139,6 +139,7 @@ cairo_surface_t *win32BeginDocument(GooString *inputFileName, GooString *outputF double w, double h, GooString *printer, GooString *printOpt, + GBool setupdlg, GBool duplex) { if (printer->getCString()[0] == 0) { @@ -165,12 +166,26 @@ cairo_surface_t *win32BeginDocument(GooString *inputFileName, GooString *outputF fprintf(stderr, "Error: Printer \"%s\" not found\n", printerName); exit(99); } + + // Update devmode with selected print options fillCommonPrinterOptions(w, h, duplex); fillPrinterOptions(duplex, printOpt); - if (DocumentPropertiesA(NULL, NULL, printerName, devmode, devmode, DM_IN_BUFFER | DM_OUT_BUFFER) < 0) { + + // Call DocumentProperties again so the driver can update its private data + // with the modified print options. This will also display the printer + // properties dialog if setupdlg is true. + int ret; + DWORD mode = DM_IN_BUFFER | DM_OUT_BUFFER; + if (setupdlg) + mode |= DM_IN_PROMPT; + ret = DocumentPropertiesA(NULL, NULL, printerName, devmode, devmode, mode); + if (ret < 0) { fprintf(stderr, "Error: Printer \"%s\" not found\n", printerName); exit(99); } + if (setupdlg && ret == IDCANCEL) + exit(0); + hdc = CreateDCA(NULL, printerName, NULL, devmode); if (!hdc) { fprintf(stderr, "Error: Printer \"%s\" not found\n", printerName); @@ -194,9 +209,10 @@ cairo_surface_t *win32BeginDocument(GooString *inputFileName, GooString *outputF return cairo_win32_printing_surface_create(hdc); } -void win32BeginPage(double *w, double *h, GBool useFullPage) +void win32BeginPage(double *w, double *h, GBool changePageSize, GBool useFullPage) { - fillPagePrinterOptions(*w, *h); + if (changePageSize) + fillPagePrinterOptions(*w, *h); if (DocumentPropertiesA(NULL, NULL, printerName, devmode, devmode, DM_IN_BUFFER | DM_OUT_BUFFER) < 0) { fprintf(stderr, "Error: Printer \"%s\" not found\n", printerName); exit(99); diff --git a/utils/pdftocairo-win32.h b/utils/pdftocairo-win32.h index 07e200c..3f797b4 100644 --- a/utils/pdftocairo-win32.h +++ b/utils/pdftocairo-win32.h @@ -14,8 +14,9 @@ cairo_surface_t *win32BeginDocument(GooString *inputFileName, GooString *outputF double w, double h, GooString *printer, GooString *printOpt, + GBool setupdlg, GBool duplex); -void win32BeginPage(double *w, double *h, GBool useFullPage); +void win32BeginPage(double *w, double *h, GBool changePageSize, GBool useFullPage); void win32EndPage(GooString *imageFileName); void win32EndDocument(); diff --git a/utils/pdftocairo.1 b/utils/pdftocairo.1 index 00d93c4..1045436 100644 --- a/utils/pdftocairo.1 +++ b/utils/pdftocairo.1 @@ -220,6 +220,11 @@ PostScript file (PS only). This tells the print manager to enable duplexing. .B WINDOWS PRINTER OPTIONS for the available options. .TP +.BI \-setupdlg +(Windows only). When used with \-print, the printer properties dialog is displayed +allowing the print settings to be modified before printing. The paper size selected +in the print properties dialog will be used except when -origpagesizes is specified. +.TP .BI \-opw " password" Specify the owner password for the PDF file. Providing this will bypass all security restrictions. diff --git a/utils/pdftocairo.cc b/utils/pdftocairo.cc index b0a689e..0c25b14 100644 --- a/utils/pdftocairo.cc +++ b/utils/pdftocairo.cc @@ -124,10 +124,9 @@ static GBool quiet = gFalse; static GBool printVersion = gFalse; static GBool printHelp = gFalse; -#ifdef CAIRO_HAS_WIN32_SURFACE static GooString printer; static GooString printOpt; -#endif +static GBool setupdlg = gFalse; static const ArgDesc argDesc[] = { #if ENABLE_LIBPNG @@ -165,6 +164,8 @@ static const ArgDesc argDesc[] = { "printer name or use default if this option is not specified"}, {"-printopt", argGooString, &printOpt, 0, "printer options, with format =[,=]*"}, + {"-setupdlg", argFlag, &setupdlg, 0, + "show printer setup dialog before printing"}, #endif {"-f", argInt, &firstPage, 0, @@ -262,6 +263,7 @@ static const ArgDesc argDesc[] = { static cairo_surface_t *surface; static GBool printing; static FILE *output_file; +static GBool usePDFPageSize; #if USE_CMS static unsigned char *icc_data; @@ -435,7 +437,7 @@ static void getOutputSize(double page_w, double page_h, double *width, double *h { if (printing) { - if (origPageSizes) { + if (usePDFPageSize) { *width = page_w; *height = page_h; } else { @@ -539,7 +541,7 @@ static void beginDocument(GooString *inputFileName, GooString *outputFileName, d } #ifdef CAIRO_HAS_WIN32_SURFACE if (printToWin32) - surface = win32BeginDocument(inputFileName, outputFileName, w, h, &printer, &printOpt, duplex); + surface = win32BeginDocument(inputFileName, outputFileName, w, h, &printer, &printOpt, setupdlg, duplex); #endif } } @@ -565,8 +567,12 @@ static void beginPage(double *w, double *h) #endif #ifdef CAIRO_HAS_WIN32_SURFACE - if (printToWin32) - win32BeginPage(w, h, noShrink); // w,h will be changed to actual size used + if (printToWin32) { + GBool changePageSize = gTrue; + if (setupdlg && !origPageSizes) + changePageSize = gFalse; + win32BeginPage(w, h, changePageSize, noShrink); // w,h will be changed to actual size used + } #endif cairo_surface_set_fallback_resolution (surface, x_resolution, y_resolution); @@ -936,8 +942,10 @@ int main(int argc, char *argv[]) { exit(99); } } - if (paperWidth < 0 || paperHeight < 0) - origPageSizes = gTrue; + if (origPageSizes || paperWidth < 0 || paperHeight < 0) + usePDFPageSize = gTrue; + else + usePDFPageSize = gFalse; globalParams = new GlobalParams(); if (quiet) { -- 2.1.1