> 백엔드 개발 > C++ > PDF를 특정 프린터 대기열로 자동 인쇄하는 방법은 무엇입니까?

PDF를 특정 프린터 대기열로 자동 인쇄하는 방법은 무엇입니까?

DDD
풀어 주다: 2025-01-23 22:07:08
원래의
1081명이 탐색했습니다.

How to Automatically Print PDFs to a Specific Printer Queue?

지정된 프린터로 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;
    }
}
로그인 후 복사

주요 고려 사항:

  • 이 라이브러리를 활용하려면 PdfiumViewer NuGet 패키지를 설치하세요.
  • 필요에 따라 다양한 인쇄 매수와 프린터 구성을 수용하도록 코드를 조정하세요.
  • PdfiumViewer의 오픈 소스 특성(Apache 2.0 라이센스)은 다양한 애플리케이션에 적합합니다. 강력한 오류 관리를 위해 잠재적인 예외를 처리하는 것을 잊지 마세요.

위 내용은 PDF를 특정 프린터 대기열로 자동 인쇄하는 방법은 무엇입니까?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿