-2

我目前正在使用以下代码从数据库中打印 pdf 文件。我使用 pdfium 来查看 pdf 文件和打印我使用 PrintDialog 框。我只能在一个副本中打印 pdf 文件,但在多个副本中我没有得到它

这是我的代码:

        PrintDialog PrintDialog1 = new PrintDialog();
        PrintDialog1.ShowDialog();

        PrintDocument pd = new PrintDocument();

        int pageForPrint = 0;

        pd.PrintPage += (s, z) =>
        {
            using (PdfBitmap bmp = new PdfBitmap((int)z.PageSettings.PrintableArea.Width, (int)z.PageSettings.PrintableArea.Height, true))
            {

                //Render to PdfBitmap using page's Render method with FPDF_PRINTING flag
                pdfViewer1.Document.Pages[pageForPrint].Render
                    (bmp,
                    0,
                    0,
                    (int)z.PageSettings.PrintableArea.Width,
                    (int)z.PageBounds.Height,
                    Patagames.Pdf.Enums.PageRotate.Normal, Patagames.Pdf.Enums.RenderFlags.FPDF_PRINTING);

                //Draw rendered image to printer's graphics surface
                z.Graphics.DrawImageUnscaled(bmp.Image,
                    (int)z.PageSettings.PrintableArea.X,
                    (int)z.PageSettings.PrintableArea.Y);

                //Print next page
                if (pageForPrint < pdfViewer1.Document.Pages.Count)
                {
                    pageForPrint++;
                    z.HasMorePages = true;
                }
               ;
            }
        };

        //start printing routine
        pd.Print();

}

4

2 回答 2

0

使用 PrinterSettings 并通过

pd.PrinterSettings.Copies = [numberofpages]
于 2018-02-08T13:25:44.757 回答
0

您可以使用 PrintToPrinter 选项如下

public virtual void PrintToPrinter (
    int nCopies,
    bool collated,
    int startPageN,
    int endPageN
)

Parameters
nCopies
Indicates the number of copies to print.
collated
Indicates whether to collate the pages.
startPageN
Indicates the first page to print.
endPageN
Indicates the last page to print.

https://docs.microsoft.com/en-us/previous-versions/ms226031(v=vs.90)
于 2021-04-29T09:15:39.123 回答