2

我正在使用PdfiumViewer打印 PDF 文件:

using (PdfDocument document = PdfDocument.Load(pdfFileName))
{
    using (PrintDocument printDocument = document.CreatePrintDocument())
    {
        printDocument.BeginPrint += PrintDocument_BeginPrint;
        printDocument.EndPrint += PrintDocument_EndPrint;
        printDocument.PrintPage += PrintDocument_PrintPage;
        printDocument.QueryPageSettings += PrintDocument_QueryPageSettings;

        printDocument.PrintController = new StandardPrintController();
        printDocument.Print();
    }
}

在我printDocument BeginPrintEndPrintPrintPageQueryPageSettings事件中,我什么也没做,只是将一些日志记录到文件中。

PDF 文件已打印,但文档每页的左右边距被截断,因此我尝试将每个 PDF 文档页面调整为默认打印机中当前默认选择的纸张尺寸。我怎样才能做到这一点?

4

1 回答 1

3

最后,我通过初始化CreatePrintDocument构造函数解决了这个问题PdfPrintMode.ShrinkToMargin

using (PdfDocument document = PdfDocument.Load(pdfFileName))
{
    using (PrintDocument printDocument = document.CreatePrintDocument(PdfPrintMode.ShrinkToMargin))
    {
        printDocument.BeginPrint += PrintDocument_BeginPrint;
        printDocument.EndPrint += PrintDocument_EndPrint;
        printDocument.PrintPage += PrintDocument_PrintPage;
        printDocument.QueryPageSettings += PrintDocument_QueryPageSettings;

        printDocument.PrintController = new StandardPrintController();
        printDocument.Print();
    }
}
于 2018-07-09T14:58:11.493 回答