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;
}
writer.SetOpenAction(new PdfAction(PdfAction.PRINTDIALOG))
is a hint or suggestion to the PDF renderer that you would like to have the print dialog shown upon opening. Implementation of this hint is optional. iTextSharp really has nothing to do with printing since it is not a renderer. So the first question is, what PDF renderer are you using? There's nothing in the PDF standard about "not showing a PDF", that'll have to be specific to whatever renderer you are using. – Chris Haas