gpt4 book ai didi

c# - 如何在没有对话框的情况下打印 XPS?

转载 作者:太空宇宙 更新时间:2023-11-03 23:45:25 28 4
gpt4 key购买 nike

我尝试打印到 XPS 打印机(它不是我的默认打印机),但程序打开了一个对话框。我可以跳过对话框吗?这是代码:

            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();

最佳答案

您可以使用 Aspose API 将 PDF 打印到 XPS 而无需对话框 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();

关于c# - 如何在没有对话框的情况下打印 XPS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27729123/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com