Spire.PDFViewer is a powerful PDF Viewer component for .NET. It allows developers to load PDF document from stream, file and byte array.

Thu Sep 13, 2018 6:19 pm

Hi,

Document prints immediately when I click print button, I want to show the print dialog first. How to do that?


Thanks,

Jeisma

jeisma
 
Posts: 10
Joined: Mon May 14, 2018 10:23 pm

Fri Sep 14, 2018 3:38 am

Hello Jeisma,

Thanks for your inquiry.
You could refer to below sample code to show print dialog, and the version I used is Spire.PDFViewer Pack(Hotfix) Version:3.6.3. If there is any question, just feel free to write back.
Code: Select all
private void btnPrint_Click(object sender, EventArgs e)
{
    if (this.pdfDocumentViewer1.PageCount > 0)
    {
        //Set the print dialog
        PrintDialog dialogPrint = new PrintDialog();
        dialogPrint.AllowPrintToFile = true;
        dialogPrint.AllowSomePages = true;
        dialogPrint.PrinterSettings.MinimumPage = 1;
        dialogPrint.PrinterSettings.MaximumPage = this.pdfDocumentViewer1.PageCount;
        dialogPrint.PrinterSettings.FromPage = 1;
        dialogPrint.PrinterSettings.ToPage = this.pdfDocumentViewer1.PageCount;
        dialogPrint.PrinterSettings.PrinterName = "Microsoft XPS Document Writer";
        if (dialogPrint.ShowDialog() == DialogResult.OK)
        {
            //Set the pagenumber which you choose to print
            this.pdfDocumentViewer1.PrintSettings.SelectPageRange(dialogPrint.PrinterSettings.FromPage, dialogPrint.PrinterSettings.ToPage);
            this.pdfDocumentViewer1.PrintSettings.PrinterName = dialogPrint.PrinterSettings.PrinterName;
            this.pdfDocumentViewer1.PrintDoc();
        }
    }
}

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1137
Joined: Wed Apr 25, 2018 3:20 am

Tue Sep 18, 2018 3:09 am

Hello Jeisma,

Greetings from E-iceblue.
Did my code help you? Your feedback will be greatly appreciated.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1137
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.PDFViewer