Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Thu Apr 09, 2020 5:12 am

Based on PrintDialog print-setting result,
I would like to print the pdf file to A4-size paper and landscape/portrait and selected pages accordingly.
So, the following code is right? (pls pay attention to the marked red)

pdfdoc=new PdfDocument();
pd=new PrintDialog();
...
pdfdoc.PageSettings.Orientation=(pd.PrinterSettings.DefaultPageSettings.Landscape)?PdfPageOrientation.Landscape:PdfPageOrientation.Portrait;
papersize=new PaperSize("A4",(int)PdfPageSize.A4.Width,(int)PdfPageSize.A4.Height);
papersize.RawKind=(int)PaperKind.A4;
pdfdoc.PrintSettings.PaperSize=papersize;
pdfdoc.PrintSettings.SetPaperMargins(0,0,0,0);
pdfdoc.PrintSettings.SelectSinglePageLayout(Spire.Pdf.Print.PdfSinglePageScalingMode.ActualSize,false,100f);
pdfdoc.PrintSettings.PrintController=new StandardPrintController();
pdfdoc.Print();

grchen168
 
Posts: 32
Joined: Sat Jan 24, 2015 4:48 pm

Thu Apr 09, 2020 9:09 am

Hello,

Thanks for your inquiry.
Do you want to set the properties such as paper size and printing orientation through the print dialog? If so, please refer to the below code to print with the print dialog.
Kindly note that if properties such as paper size are set in the print dialog, there is no need to add additional settings in the code. The printer will directly print according to the properties set in the print dialog.
Code: Select all
    PdfDocument pdfdoc = new PdfDocument();
    pdfdoc.LoadFromFile("print.pdf");

    PrintDialog dialogPrint = new PrintDialog();
    dialogPrint.AllowPrintToFile = true;
    dialogPrint.AllowSomePages = true;
    dialogPrint.PrinterSettings.FromPage = 1;
    dialogPrint.PrinterSettings.ToPage = pdfdoc.Pages.Count;

    if (dialogPrint.ShowDialog() == DialogResult.OK)
    {
        //Print
        pdfdoc.PrintSettings.SelectPageRange(dialogPrint.PrinterSettings.FromPage, dialogPrint.PrinterSettings.ToPage);
        pdfdoc.PrintSettings.PrinterName = dialogPrint.PrinterSettings.PrinterName;
        pdfdoc.PrintSettings.PrintController = new StandardPrintController();
        pdfdoc.Print();
    }

If there is any misunderstanding, please describe your needs in detail.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Thu Apr 09, 2020 10:47 am

Thanks.

grchen168
 
Posts: 32
Joined: Sat Jan 24, 2015 4:48 pm

Fri Apr 10, 2020 1:02 am

Hello,

You are welcome.
If you need further assistance, please feel free to contact us.
Have a nice day!

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.PDF