2

I am trying to print a PDF from file silently. I have tried numerous suggestions from other posts on the web, but none have seemed to work. What is the best way of doing this?

If printing from a file is the problem, I could print straight from a MemoryStream. I initially convert to PDF from HTML using a library. This renders the PDF exactly how I want it.

Ry-
  • 218,210
  • 55
  • 464
  • 476
Hesky
  • 787
  • 3
  • 8
  • 14

4 Answers4

2

I've used Foxit to do this in the past. Check out my question/solution here: Printing a PDF Silently with Adobe Acrobat

Community
  • 1
  • 1
Cole W
  • 15,123
  • 6
  • 51
  • 85
  • This is what i ended up using. It completes the printout completely silenty which is exactly what i wanted – Hesky Aug 25 '11 at 09:42
1

If you are trying to have a client browser automatically send a pdf from a link to their local printer then you are out of luck. There's not a browser on the planet that would let you do this.

If you are trying to send a file to a printer that is local to the server, through it's own printer drivers, then see Cole W's answer.

NotMe
  • 87,343
  • 27
  • 171
  • 245
1

I used this solution.

Document pdf = new Document(PageSize.LETTER);
PdfWriter writer = PdfWriter.GetInstance(pdf, 
new FileStream(Request.PhysicalApplicationPath + "~1.pdf", FileMode.Create));
pdf.Open();

//This action leads directly to printer dialogue
PdfAction jAction = PdfAction.JavaScript("this.print(true);\r", writer);
writer.AddJavaScript(jAction);

pdf.Add(new Paragraph("My first PDF on line"));
pdf.Close();

//Open the pdf in the frame
frame1.Attributes["src"] = "~1.pdf";

The PdfAction.JavaScript("this.print(true);\r", writer); could be changed sending the false parameter like this PdfAction.JavaScript("this.print(false);\r", writer);

I haven't tried it but could be an approach.

Community
  • 1
  • 1
Nelson Miranda
  • 5,484
  • 5
  • 33
  • 54
0

You may try Aspose.Pdf.kit to print the PDF file to either physical or virtual printer while hiding the print dialog. In order to hide the print dialog, you only need to set PrintPageDialog property to false.

Disclosure: I work as developer evangelist at Aspose.

Shahzad Latif
  • 1,408
  • 12
  • 29