How to display print preview and then print the pdf

Hi
I need a sample code to preview a PDF file first and then click on print button on Preview the print dialoge box should display and from there i need to print my pdf.I need a sample code.I got some documents but its not working for me as per my requirement

Hello Ajeesh,

Thanks for your interest in our products.

Please note that we have a class named PdfViewer present under Aspose.Pdf.Facades namespace which provides the capability to print PDF documents. It enables you to display PageSetup and PrinterSettings dialog and then you can press Print button to print the selected file. But I am afraid it does not support the feature to display/preview the PDF file it self. Please visit the following link for information on Working with PDF printing - Facades

In case it does not satisfy your requirement or you have any further query, please feel free to contact.

Hi

Thanks for your reply and i already got the above link but am not understand it.If possible can you give a working code or working example so that it will help me

HI

Thanks for your reply and i already got the above link but am not understand it.If possible can you give a working code or working example so that it will help me

Hi Ajeesh,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

I think you can try the following sample code to setup the page settings:

//create PdfViewer object

PdfViewer viewer = new PdfViewer();

//open input PDF file

viewer.OpenPdfFile(@"E:\AP Data\March2012\Test6.pdf");

//set attributes for printing

viewer.AutoResize = true; //print the file with adjusted size

viewer.AutoRotate = true; //print the file with adjusted rotation

viewer.PrintPageDialog = true; //page dialog when printing

viewer.PrintDocumentWithSetup();

//close the PDF file after priting

viewer.ClosePdfFile();

Please let us know if it fits your needs.

Thank You & Best Regards,

Hi

Thanks for your reply.The above code you have given is working,but i need a dialogue box like the attachment i given this.please check my attachment.And one more thing is the print dialogue box is not comming front ,i can see the dialogue box only when i click Alt + Tab.

Hi Ajeesh,

Thanks for sharing the details. I am afraid the requested feature is currently not supported. However for the sake of implmentation, I have logged this requirement as PDFNEWNET-33349 in our issue tracking system. We will further look into the details of this requirement and will keep you updated on the status of correction .We are sorry for this inconvenience.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Hello Ajeesh,


Thanks for your patience.

In order to display PrintDialog while printing the document, please try using the following code snippet.

[C#]

Aspose.Pdf.Facades.PdfViewer
viewer = new Aspose.Pdf.Facades.PdfViewer();<o:p></o:p>

viewer.BindPdf("c:/pdftest/OPAN300.PROUT.PDF");

viewer.AutoResize = true;

viewer.Resolution = 600;

viewer.AutoRotate = true;

viewer.PrintPageDialog = true;

PrintDialog printDialog = new PrintDialog();

if (printDialog.ShowDialog() == DialogResult.OK)

{

System.Drawing.Printing.PrinterSettings ps = printDialog.PrinterSettings;

System.Drawing.Printing.PageSettings pgs = new System.Drawing.Printing.PageSettings();

pgs.PaperSize = new System.Drawing.Printing.PaperSize("A4", 827, 1169);

pgs.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);

viewer.PrintDocumentWithSettings(pgs, ps);

}

viewer.Close();


In the event of any further query, please feel free to contact.