Print a pdf from a webpage with javascript

Hi, I am not having any luck with this, been trying for a bit. I want to be able to have a basic html page with a pdf embedded in it, have a print button which when you press it, it prints the pdf. My attempts so far are the attached file. When I press print nothing happens. There are examples on the web using Javascript, but each one I try, when I press Print nothing happens.

Can you help? To cut down on my syntax errors, let's assume I have some webspace called www.somewebspace.com and on there I have a folder called Test1 and in that folder is my html file called OutdoorActivityInstructor.html and the pdf is Outdoor_Activity_Instructor.pdf. I want to be able to show Outdoor_Activity_Instructor.pdf embedded in my OutdoorActivityInstructor.html file and when I press my bespoke "Print" button, it prints the pdf.

I am testing on google chrome.

Incidentally, when you look at my code, the <a href="OutdoorActivityInstructor.php"><IMG SRC="download_image.gif" BORDER="1")</a>    is just to download the pdf file and that works fine. What doesn't work is having a print button, which prints the pdf.

Thanks.
RupertAAsked:
Who is Participating?
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.

RupertAAuthor Commented:
Just looking at my entry here, it does not seem to show my html file I have been working on. Whether that is hidden from me and viewable to others I do not know. I will attach it here again in case it has not successfully uploaded.
0
RobOwner (Aidellio)Commented:
I'm sorry to say It's just NOT possible.  JavaScript doesn't have access to your embedded PDF, it's sandboxed against it for security reasons.

Embedding a PDF involves a plugin and is essentially a program outside the realms of what JavaScript is allowed to interact with.

JavaScript CAN print the webpage but it would only print the visible section of the embedded PDF
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
David Johnson, CD, MVPOwnerCommented:
Cannot be done you cannot control something outside of your webpage. Which I am viewing not executing .. If it could be done you'd already know if it was possible since millions of users would be screaming blue murder about browsing to a website clicking on something and their printer wants to print a million pages of solid black.
0
Steve BinkCommented:
You might also want to consider that modern browsers have internal mechanics for displaying PDFs, and include print functionality.  Why not rely on that.  Perhaps loading the PDF in an iframe somewhere on the page would be acceptable?
0
RupertAAuthor Commented:
Hey guys thanks a lot for pointing that out. Like you said, it makes sense that you cannot do what I wanted to achieve. The solution I actually came up with was to not have a pdf on my webpage. I just created what was on the pdf (simple stuff) as html on the webpage and printed the whole page. Thanks a lot.
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.