2

I ran into an interesting PDF file which has some custom javascript that triggers the print window function automatically when the file is opened.

The annoyance comes when the file is uploaded into a web app and every time the file is previewed or opened it fires up the print dialog.

The only information I found was about cleaning the file in a PDF creator/reader software or blocking the default print dialog on the page with javascript, but that seems to interfere with normal print options.

Has anyone run into this combination before and found a way to block the print dialog on PDF files (only) without disrupting the usual print options for the browser?

Ionko Gueorguiev
  • 302
  • 4
  • 18
  • If you are in control of the PDF you could conditionally trigger the print dialog by adding your own javascript to not print if a specific query string is visible. – Marie May 16 '19 at 20:02
  • I am not in control of the PDF. or I should say, it's a user uploaded PDF. – Ionko Gueorguiev May 16 '19 at 20:06
  • I looked around a bit, this seems like it might be a duplicate of [this](https://stackoverflow.com/questions/22867341/removing-javascript-print-code-embedded-in-pdf) question but I am not sure. See if that helps at all? – Marie May 16 '19 at 20:15
  • Thanks Marie, but editing/altering the PDF isn't really an option for me. I am more hopeful for a solution that can cover any PDF file and not have to worry about specific nonsense that someone might embed into their PDFs :( – Ionko Gueorguiev May 16 '19 at 20:23
  • If the PDF format uses a standard start/stop header for javascript it would be pretty trivial to replace the entire contents programatically. Beyond that maybe you would have luck with some premade tool, e.g. [iTextSharp](https://stackoverflow.com/questions/5137222/editing-javascript-in-a-pdf-with-net) for .NET – Marie May 16 '19 at 20:26

0 Answers0