1

I am trying to print using the below c# and iTextSharp code, can some one help me. It does not get printed.

var document = new iTextSharp.text.Document();             
PdfWriter writer = PdfWriter.GetInstance(document, memStream);
document.Open();
var reader = new PdfReader("C:\\test1.pdf");
PdfContentByte content = writer.DirectContent;

Int32 i;
int pageCount = 1;
for (i = 0; i <= pageCount - 1; i++)
{
    document.NewPage();
    PdfImportedPage page = writer.GetImportedPage(reader, i + 1);
    content.AddTemplate(page, 0, 0);
}
writer.SetOpenAction(new PdfAction(PdfAction.PRINTDIALOG));
document.Close();
gunr2171
  • 16,104
  • 25
  • 61
  • 88
user389667
  • 45
  • 8
  • possible duplicate of [How can I send a file document to the printer and have it print?](http://stackoverflow.com/questions/6103705/how-can-i-send-a-file-document-to-the-printer-and-have-it-print) – Tsukasa Jul 16 '14 at 20:55
  • @Tsukasa, thanks for your flag. However it would be good to still note what you said in your answer: "iTextSharp can't print". – gunr2171 Jul 16 '14 at 20:57
  • The posted code asks a conforming PDF renderer to automatically prompt the user to print the PDF when opened. It will not automatically print. As noted above, iTextSharp cannot print because iTextSharp is not a renderer. – Chris Haas Jul 16 '14 at 21:00

1 Answers1

0

You can use Ghostscript library to print the pdf file.

If yo need a Ghostscript wrapper for .NET you can take a look at Ghostscript.NET library.

Printing sample via Ghostscript.NET can be found here: https://ghostscriptnet.codeplex.com/discussions/470946

HABJAN
  • 9,212
  • 3
  • 35
  • 59