지정된 프린터로 PDF 인쇄 자동화
문제: 사용자 데스크톱에서 생성된 PDF 파일을 사용자가 시작한 작업에 따라 어떻게 자동으로 특정 로컬 프린터 대기열로 보낼 수 있습니까?
해결책: PdfiumViewer 라이브러리 활용
Google Pdfium 라이브러리는 .NET 래퍼 PdfiumViewer와 함께 간단한 솔루션을 제공합니다. 다음은 사용자 정의 가능한 설정으로 자동 PDF 인쇄를 보여주는 예입니다.
public bool PrintPDF(string printerName, string paperSizeName, string filePath, int numberOfCopies) { try { // Configure printer settings var printerSettings = new PrinterSettings { PrinterName = printerName, Copies = (short)numberOfCopies }; // Configure page settings var pageSettings = new PageSettings(printerSettings) { Margins = new Margins(0, 0, 0, 0) // Set margins to zero }; // Find the specified paper size foreach (PaperSize paperSize in printerSettings.PaperSizes) { if (paperSize.PaperName == paperSizeName) { pageSettings.PaperSize = paperSize; break; } } // Initiate PDF printing using (var pdfDocument = PdfDocument.Load(filePath)) using (var printDocument = pdfDocument.CreatePrintDocument()) { printDocument.PrinterSettings = printerSettings; printDocument.DefaultPageSettings = pageSettings; printDocument.PrintController = new StandardPrintController(); //Ensures standard printing behavior printDocument.Print(); } return true; } catch (Exception ex) { //Handle exceptions appropriately (log, display error message, etc.) return false; } }
주요 고려 사항:
위 내용은 PDF를 특정 프린터 대기열로 자동 인쇄하는 방법은 무엇입니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!