Print/save full webpage as PDF - javascript

I need a method to be able to print/save the current full webpage as a PDF.
I know it can be done if I download a PDF printer and print to that; but I need it to be done without the user having to do anything other than click a button in a webpage.
I can't do it via PHP as the page is all client side content, so I'm guessing an ActiveX component?
Any ideas would be greatly appreciated!
Many thanks

Try www.freepdfconvert.com - they also have a javascript one click PDF download from any page.

Related

How to download manually the HTML of a dynamic page

I need to download manually the HTML of a dynamic page.
I can't use a scraper because the site recognize me.
I tried to inspect the page, but in the Dev Tools I found no way to download the full HTML.
What should I do?
Pardon I'm quite newbie in Computer Science.
if you want to download the page just click these buttons on your keyboard
CTRL + S
That means you will save the current HTML page to your computer.
I hope it's clear and helpful, Thanks!.

Is it possible to force download a file (like pdf) as soon as a page loads

Actually this is what I'm trying to do. I have a form and when a user fills that form it goes to a thank you page where thank you message is displayed. Now what I'm trying to do is as soon as the thank you page opens a pdf file should start downloading without the user clicking anywhere on the page. I tried to find a solution by searching but almost all of them have given a solution where one link is provided and user have to click that link to download her pdf. But that is not what I want. And I want to achieve that using Javascript or jQuery only, no server side language.
A clarification:- PDF download on clicking a link is already working. What I want is PDF to download as soon as thank you page opens. I know logically this should not happen because by doing this anyone can set any number of files to be downloaded as soon as their page opens and fill your local drive. But my client wants only this thing to happen.
Calling click() for the user on an other-wise working link should do the trick:
<html>
download pdf
<script>
var link = document.getElementById("link");
link.click()
</script>
</html>
You can do it, in the HEAD tag:
<meta http-equiv="refresh" content="0; url=yourfile.pdf">
This will work also with browsers without JavaScript, and as soon as the the head tags loaded.
a working example:
See an example on github
You can use ajax to hit the url when the page loads.
EDIT: You might want to check this out https://stackoverflow.com/a/29266135/4549494

Give an option to download pdf OR open in browser

I'm pretty sure this isn't possible but thought I'd check with you guys.
I've just had a bizarre query from a client who wants to know if it's possible to give the user the option to either download a pdf or open it in their browser.
They have a thumbnail for the PDF. Single click to open it in the browser or double click to download it. I know I can catch the single or double click with jQuery. I just want to know if it's possible to force the behaviour of the link.
Thanks
This is possible, if for example you are using PHP you can create 2 methods, once will be a simple direct link to the pdf file (if a customer has adobe reader then it will open the pdf in the browser otherwise it will force a download), the other method would always force a download.
You can find a PHP force file download example here: How to force download of a file?

Image button - print a document from my webpage

I have a website, but I need a button which I want to print a specific .pdf file from my webpage database.
As an example, this site
has a print button, which gives you option to print some pdf files
Any idea how can I do that?
I've tried this one, but it's not working:
<a href="../Documents/ScrittoGraffito/Scritto_Customers/Nicolaides_Optical/Nicolaides_webpage/Shop1_Banner.pdf"
onclick="window.print()"/><p class="test">link</p></a>
That code will tell the browser to open the print dialog for the current page.
If you want to force the browser to print the linked pdf then that is not possible, as it will be completely controlled by the application or plugin that handles pdf documents.
EDIT;
Apparently it is possible, but you have to make use of a pdf toolkit.

print a pdf via javascript

I have a HTML page that has a link to a PDF. This PDF opens in a new window.
The parent HTML page has a File->Print menu item. When the user clicks Print I want to be able to automatically open the PDF and print it. The printing part is where I am stuck.
Any help would be much appreciated.
Thanks.
If you open that window with a specific name (e.g. target="nameofwin") in the link pointing at the PDF, you might get away with nameofwin.print(). However, I'm not sure if that'd work since the PDF will be shown using a plugin, and not be a native part of the page. There may be some API that allows you to interface with the PDF display plugin, but then you're stuck wondering if you've got Acrobat or FoxIt or WhateverElse running in there.
You can probably use PDF.js to render the PDF in a hidden div. Then, on your "print" button, register a click in which you add a new print stylesheet to the document, show that div, print the window and then remove the print stylesheet.

Categories

Resources