如何在c#

时间:2018-02-08 13:13:17

标签: c# winforms printdialog pdfium

我目前正在使用以下代码从数据库打印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();

}

2 个答案:

答案 0 :(得分:0)

使用PrinterSettings并传递

pd.PrinterSettings.Copies = [numberofpages]

答案 1 :(得分: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)