Javascript - print pdf

I am trying to print a pdf that is embedded in its own frame.

You can see a demo app at: http://npat.space2u.com/pdf/pdfprintdll.dll/

Let the PDF load and then you can see my attempts to print it attached to the onclick events of the various buttons.

Can anyone come up with some code to print the PDF?

Also when i have a working solution i want to enable the print button after the pdf has loaded.  I guess i can do this on some onLoad event.  A suggestion here would also be appreciated.

/richard
soozhCEOAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GaryCommented:
You already have a print button embedded in the iframe in the tools menu, why add another?
0
COBOLdinosaurCommented:
It throws an error on an uncaught error because I won't accept your cookie.  If you resolve that, then I will take a look.  I don't accept cookies except from a very select group of sites.  The way you handle the error is totally unacceptable.  There is no way a user should ever see a message like that.

Cd&
0
soozhCEOAuthor Commented:
i want a print button to make it easier for users to print the pdf...

and sorry about the cookie but thats just the way it is....

maybe someone else can help?
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

GaryCommented:
Is the PDF coming from the exact same domain?
0
soozhCEOAuthor Commented:
yes.  npat.space2.com

you can see the url if you look in the js.
0
GaryCommented:
All that should be needed is
window.frames["framename"].focus();
window.frames["framename"].print();


But I cannot get it work locally, I may be hitting SOP
0
soozhCEOAuthor Commented:
what is SOP
0
GaryCommented:
Same Origin Policy
0
soozhCEOAuthor Commented:
I had that at first but then the error was "Access denied".
0
GaryCommented:
Don't know what server you are on
If php you can use
Header always append X-Frame-Options SAMEORIGIN
in the iframed page, may (should) solve the access denied.
0
soozhCEOAuthor Commented:
i fixed the access denied by using the same domain for the main window and the frame.

The problem now is most likely a syntax or similar error.
0
GaryCommented:
I thought you said they were the same domain already...?
0
soozhCEOAuthor Commented:
They are in the same domain and if you run the app and look at the code you will see that.

What i was trying to say was that i originally had a SOP problem but i fixed it by moving everything to the same domain.

No the errors are different... which you will see if you click on the buttons and execute the code i am trying.


/thanks
0
GaryCommented:
Have you tried setting the headers like I said above
There is still a permission problem
0
soozhCEOAuthor Commented:
i dont think that there is a permission problem here.  The iframe window uses the same domain as the main window.  You can check - maybe i am wrong.

If you try the 4 buttons and associated code you will see different types of error.  I dont Think any of them are permission errors.

Dont Think xframe options are the solution here.
0
David Johnson, CD, MVPOwnerCommented:
you want to force or add a button for me to click on your website that will print to my printer?
It's not happening.. I can print or save the document quite well thank you.

Browser Security will stop you from accessing my devices!!!!
0
Dave BaldwinFixer of ProblemsCommented:
@ve3ofa is right.  In addition, you need a PDF reader program to open the file ON My computer to print it on my computer.  The browser isn't going to do that.  This must be the 'day' for asking this question and the answer is the same:  Browsers don't print PDFs, PDF readers print PDFs.
0
soozhCEOAuthor Commented:
ok maybe i must make myself a bit clearer...

I have the pdf displayed in whatever the browser is using - i guess its Acrobat Reader - and what i want is a button that can pop up the print dialogue for the pdf document.

The PDF document is in its own iframe.

I have seen plently of examples that use focus on the iframe and then print... but i can not get it to work.

The example i have published has 4 buttons and different code examples.  I dont think the problem is a cross domain issue.

I was hoping someone could run the app and look at the code and runtime errors.

here is the link again http://npat.space2u.com/pdf/pdfprintdll.dll/.

Let the pdf be generated (2-3 seconds) and then see if you can find a way to get one of the print buttons to open the print dialogue.
0
David Johnson, CD, MVPOwnerCommented:
I have seen plently of examples that use focus on the iframe and then print... but i can not get it to work.  Show me 1 that works.
 
Most i-frames are rendered by the browser, pdf's are not. The user will in previous browsers get an open/save dialog box, or the browser will use its pdf reader, or an installed 3rd party pdf reader i.e. adobe reader will be called to render the pdf.
0
Dave BaldwinFixer of ProblemsCommented:
No, you are perfectly clear but I'll say it again:  Browsers don't print PDFs, PDF readers print PDFs.
0
soozhCEOAuthor Commented:
ok...

ve3ofa - no i cant find one that works... thats why i am asking.  

DaveBaldwin - good to know i am perfectly clear... so it must be that i dont understand what you mean.

Really i dont care how it is done - i just need to open the file print dialogue for the pdf document..

but maybe what you are saying is it cant be done?
0
Dave BaldwinFixer of ProblemsCommented:
The print dialog is opened thru the PDF reader, not the browser.  Your buttons in the browser aren't going to work because they can't talk to the PDF reader program.
0
David Johnson, CD, MVPOwnerCommented:
you say this:
I have seen plently of examples that use focus on the iframe and then print... but i can not get it to work.
now you say this:
no i cant find one that works... thats why i am asking.

but maybe what you are saying is it cant be done?

No Maybe at all.. It can't be done PERIOD
0
soozhCEOAuthor Commented:
looks like someone not having a good day...

but just to correct you... i have found plenty of examples but i never said any worked  - hence the question.
0
David Johnson, CD, MVPOwnerCommented:
I'm having a fine day..
i have found plenty of examples but i never said any worked    You mean did not work in your particular implementation.. I'm guessing here.. Yes there are many web pages that will make a print-friendly page BUT one of them will actually print anything. The user will select the option to print the webpage.  The browser does not have access to the system's hardware without explicit action by the user outside of the webpage. The webpage itself is sandboxed.
0
RobOwner (Aidellio)Commented:
You're going to have to try a different approach and use a desktop application written in whatever flavour of language you like.

For instance create a vb.net forms based application and load the pdf and give the ability to print it
Not much to go on but I'm not even sure you'll go down this path
http://social.msdn.microsoft.com/Forums/vstudio/en-US/68f16e1b-0982-4869-8708-ff9e2d560278/printing-pdf-file-from-vbnet
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.