I have to print a pdf document, on the click of the print button. Also I need to show the print dialog, but should not display the actual pdf to the user. And based on the print dialog properties selected, the pdf should get printed in the user selected printer.
To the generated pdf , I am able to add the printdialog properties using the below code:-
writer.SetOpenAction(new PdfAction(PdfAction.PRINTDIALOG));
But I am not able to get the pdf printed when the button is selected. can you please provide me some pointers to achieve this.
Full code:- (PDF is passed as a memorystream to the print button view).
using (MemoryStream m1 = new MemoryStream())
{
// MemoryStream m1 = new MemoryStream();
Int32 i = 0;
PdfWriter writer = PdfWriter.GetInstance(document, m1);
document.Open();
PdfContentByte content = writer.DirectContent;
document.NewPage();
PdfImportedPage page = writer.GetImportedPage(reader, i + 1);
content.AddTemplate(page, 0, 0);
writer.SetOpenAction(new PdfAction(PdfAction.PRINTDIALOG));
document.Close();
return m1;
}