简体   繁体   中英

How can I print XPS without dialog?

I try to print to XPS printer (it's not my default printer), but the program opens me a dialog. Can I skip the dialog? This is the code:

            pSettings = new PrinterSettings();                
            pSettings.PrintFileName = "test.xps";       
            RawPrinterHelper.SendStringToPrinter(pSettings.PrinterName, toSend);                
            spcn = new StandardPrintController();
            printDocument1.PrinterSettings.PrinterName = "Microsoft XPS Document Writer";
            printDocument1.PrintController = spcn;                                    
            printDocument1.PrintPage +=
                new PrintPageEventHandler(printDocument1_PrintPage);
            printDocument1.Print();                     

You can print PDF to XPS without a dialog using Aspose API Aspose API

//Create PdfViewer object and bind PDF file
PdfViewer pdfViewer = new PdfViewer();
pdfViewer.OpenPdfFile("input.pdf");

//Set PrinterSettings and PageSettings
System.Drawing.Printing.PrinterSettings printerSetttings = new System.Drawing.Printing.PrinterSettings();
printerSetttings.Copies = 1;
printerSetttings.PrinterName = "Microsoft XPS Document Writer";

//Set output file name and PrintToFile attribute
printerSetttings.PrintFileName = "C:\\tempfiles\\printoutput.xps";
printerSetttings.PrintToFile = true;

**//Disable print page dialog**
**pdfViewer.PrintPageDialog = false;**

//Pass printer settings object to the method
pdfViewer.PrintDocumentWithSettings(printerSetttings);
pdfViewer.ClosePdfFile();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM