Commit d8fe025c authored by Adrian Johnson's avatar Adrian Johnson

pdftocairo: add a -setupdlg option that will the show printer properties

dialog when printing to a win32 printer.
parent c091aa14
......@@ -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);
......
......@@ -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();
......
......@@ -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.
......
......@@ -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 <opt1>=<val1>[,<optN>=<valN>]*"},
{"-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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment