Avatar of patricktcooke
patricktcooke
Flag for United States of America asked on

Add Javascript to Open Print Dialog to PDF

I've read several places that it is possible to add javascript code to a pdf to have it open up the print dialog box when the pdf is displayed.

https://www.experts-exchange.com/questions/21683457/Print-Multiple-PDF-Files-to-Client-PC-from-Web-Server.html?sfQueryTermInfo=1+10+30+activex+auto+pdf+print

"We are also using a blank PDF document called print.pdf (download it from my example page).  This is a single blank page PDF document with javascript built into it to print when the page is opened.  "

What I need is to create the PDF, Add the Javascript to the existing PDF, and then open a new window with that pdf.

Has anybody done this before? It looks like it might be possible with iTextSharp, but i still cant figure out the code.
JavaScriptAdobe AcrobatC#

Avatar of undefined
Last Comment
Karl Heinz Kremer

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Michel Plungjan

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
patricktcooke

ASKER
Hey thanks for responding. I know I have to be missing something obvious, but what i dont see in either article is how to open the pdf to begin using the javacript code. It just starts outs as

var objDoc = this;
var objPrintParams = doc.getPrintParams();

Do you know how to open the pdf to start adding the javacript?
Michel Plungjan

You do not normally open the pdf, you WRITE the pdf with the command in it

Possibly you can add the command using Acrobat PRO
Karl Heinz Kremer

Patrick, the JavaScript is added to the PDF file - just as mplungjan explained. In the JavaScript code, you refer to the current document as "this". So, once the document is open (which happens either by the user double-clicking on it, or opening it via the File menu, or by downloading it from a web page), that "this" variable is available.

Do you have Adobe Acrobat Pro?
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Tom Knowlton

I've requested that this question be deleted for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
Michel Plungjan

Please accept mplungjan http:#a34092670
Karl Heinz Kremer

After reading the question again, I don't think that either mplungjan or myself provided useful information to the asker: The tags selected for this question imply that the desired solution is for a web server based application, hence the information about creating the documet on the fly, adding JavaScript and opening a new window (in the browser) with that PDF. Acrobat cannot be used on a server, so all our suggestions were useless. The asker even suggested iTextSharp - which would be the right tool to do this, but we never considered that.

My suggestion: Appologize to the asker and deleting the question - because the asker never replied to the question in the last comment, delete without a refund.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Michel Plungjan

I do not agree.

The solution I suggestion was to include the print javascript in the PDF from the server when WRITING the PDF.

It by the way IS possible, but not convenient to run Acrobat on a server.

We use iText from Java and it works perfectly.

Karl Heinz Kremer

Not if the documents are created on the fly for variable data printing or database publishing. And no, it's not possible to run Acrobat on a server - for legal reasons: Adobe does not allow Acrobat to be run on a server. Check the EULA you accepted when you installed Acrobat. There are also technical reasons why it's less than desireable to have Acrobat on a server, but that's a moot point because you are not allowed to do so.

I still stand by my recommendation to close this question without a refund.
Michel Plungjan

"Not if the documents are created on the fly for variable data printing or database publishing"

what is that an answer to?

And actually I meant Distiller http://www.adobe.com/products/acrdis/
Your help has saved me hundreds of hours of internet surfing.
fblack61
Karl Heinz Kremer

That was an answer to your suggestion to add the JavaScript with Acrobat - which is possible for static PDFs that get uploaded to a server, but not for dynamic PDFs created on the fly.

All Distiller does is convert PostScript files to PDF. If you dont' have a PS file, Distiller wil not do much for you. The mentioning of iTextSharp suggests that the PDFs are generated from an application, which is also suggested by the C# and VB.net.

I've provided my input, and I'll just wait until a moderator makes a decision.
Michel Plungjan

Did you click my link? On the fly printing pdf fron a tiff file on the server
Karl Heinz Kremer

I clicked on the link you provded as part of your answer in https://www.experts-exchange.com/questions/26600950/Add-Javascript-to-Open-Print-Dialog-to-PDF.html?cid=1573&anchorAnswerId=34092670#a34092670 - and it does NOT talk about that.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Michel Plungjan

You are determined not to agree with me it seems.

I am talking about the link to here posted in http:#a36108089 which uses the kind of javascript mentioned in my first post
Badotz

Of all of the posts, why did you accept that one, as opposed to just closing the question?
Michel Plungjan

Yeah, that is what I was wondering too
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Karl Heinz Kremer

Deleted without a refund. See my explanation above.