Search code examples
pdfsharpmigradoc

Auto print with MigraDoc / PdfSharp


Porting some code from iTextSharp to PdfSharp. In iTextSharp we did this to make the print dialog automatically open when the pdf document is opened in a web browser:

pdfW.AddJavaScript(PdfAction.JavaScript("this.print(true);\r", pdfW));

where pdfW is a PdfWriter

I found this where one of the answers shows opening an existing file with PdfSharp and adding the "open action".

Generate a PDF that automatically prints

I would like to add the open action using MigraDoc to the pdf as its generated. I am using MigraDoc because its at a higher level than PdfSharp. (sections, paragraphs, etc) instead of drawing text and lines)

Also, the pdf is displayed to the user in a browser. Its being sent from an ASP.NET application where the response is the pdf file.


Solution

  • MigraDoc uses PDFsharp to generate the PDF file. You will have to use PDFsharp for special requirements like yours.

    You can make the changes after rendering the PDF file with MigraDoc, but before saving it, so the file will be saved only once.
    Use the PdfDocument property of the PdfDocumentRenderer class.