Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Add Javascript to Open Print Dialog to PDF

Posted on 2010-11-08
20
Medium Priority
?
2,610 Views
Last Modified: 2012-06-21
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.

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/ASP/Q_21683457.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.
0
Comment
Question by:patricktcooke
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
20 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 2000 total points
ID: 34092670
0
 

Author Comment

by:patricktcooke
ID: 34095343
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?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 34095619
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
0
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 34111982
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?
0
 
LVL 5

Expert Comment

by:Tom Knowlton
ID: 36107664
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.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 36107665
Please accept mplungjan http:#a34092670
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 36107998
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.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 36108089
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.

0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 36111495
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.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 36111587
"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/
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 36111877
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.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 36112485
Did you click my link? On the fly printing pdf fron a tiff file on the server
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 36112539
I clicked on the link you provded as part of your answer in http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_26600950.html?cid=1573#a34092670 - and it does NOT talk about that.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 36112626
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
0
 
LVL 29

Expert Comment

by:Badotz
ID: 36118095
Of all of the posts, why did you accept that one, as opposed to just closing the question?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 36118617
Yeah, that is what I was wondering too
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 36126078
Deleted without a refund. See my explanation above.
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this first video of the three-part Xpdf series, we introduce and describe Xpdf, a library containing nine command line utilities that perform various functions on PDF files. We show where the library is located and how to download it, discuss its…
We often encounter PDF files that are pure images, that is, they do not have text characters, but instead contain only raster graphics. The most common causes of this are document scanning software and faxing software/services that create image-only…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question