save a pdf and close it programatically - javascript

I am automataing a webbased application using Selenium Webdriver.
A report is generated in PDF format is opened Acrobat reader. I have to save that PDF to a specific location and then close the pdf. So how can it be done thru automation. I tried searching on net and found this can be done using VB script but then need Adobe professional version for the same. Also the report that is generated doesnot have a specific title. That keeps changing.
Can this be done using javascript ?
Thanks

It's possible to generate some PDF in JS, try http://snapshotmedia.co.uk/blog/jspdf
It will return you an base64 string or an URI. Then you can redirect your visitor to the PDF (with this URI) or write down the base64 in a file.

Related

Prevent PDF Download in PHP

Is there any way to prevent PDF download and printing option from browser ?
I am using PHP codeigniter for uploading the PDF file from admin side. I want to restrict the download access, inspect access, page source access from user side. Users only need to read the PDF.
So is there any way to do this using PHP or Javascript?
Users can take screenshots, which is not a problem. I only wan't to prevent the pdf url and download access in all aspects.
Do we have to convert PDF to any other format for this?

Possible to add javascript to a PDF to communicate with a parent window?

I am currently trying to find a way so that whenever a Link is selected in a specific PDF file to be able to know which URL it points to and do something based on the selection. I've looked online for pdf libraries such as Adobe Acrobat SDK and the Docotic.Pdf Library by bitmiracle, but haven't been able to find a solution to this. Can a PDF document opened in lets say, an Iframe inside an HTML window, communicate with functions defined in the HTML window? In my case I am not constructing the initial PDF using any pdf creator. My pdf is being converted from a word document and then would be opened using some pdf viewers or similar tools.

How to print outputstream PDF using Javascript

I'm getting PDF file as output stream and want to print it using Javascript. There're some tips about printing PDF file or iframe. But I need to print PDF files that is generated by server after print request.
JavaScript can't access any local resources like the file system or attached printers, so this isn't possible directly.
What you need is to convert the PDF to, say, HTML5. Then display that in your browser and call document.print() to print it.
The project pdf.js already does a pretty good job to convert PDF to HTML.

Save HTML5 page as PDF

On click of a button, without doing a round trip to the server, can we save a HTML5 page on clients machine as PDF.
Check out PDF.js. This lib can create pdf in the browser (or serverside on node.js).
Using chrome you can print the page to a pdf file.
You need something like this, maybe server-side you can start a browser and print the content to a pdf file and send this to the client.
Disclaimer: i work for ByteScout
If you have simple HTML formatting and want to generate PDF on client side and if you have non-commercial project, check BytescoutPDF.js - it supports simple HTML formatting for text (font name, size, color) plus simple drawings and images, should be enough for simple reports

Automatically print a webpage to pdf

While using browsers like Chrome and Firefox, there is an option to print the page to PDF (that is saving the webpage as a PDF file).
Print this page
This code opens up the print page from where the user should manually choose print to PDF. Can this be done automatically? If so please help.
You can not print page to pdf with Javascript. You have to use server side script to print page to pdf. In PHP, you can use 3rd party PDF library like http://www.tcpdf.org .
There is not much available to print to PDF in Javascript.
The most supported option is indeed to generate it server-side using a library such as tcpdf (as shown by Thein Hla Maw).
I don't think Mark's solution is the correct one, since it requires the users to have some software installed.
For pure javascript PDF generation, there is this.
NB : thanks SO :-)
Yes... provided that your users have a few things installed.
They need a PDF print driver, such as PrimoPDF
If you want to automatically print to this driver, they need to have a plugin installed, such as JS Print Setup (for Firefox) or MeadCo ScriptX for IE
Then, using the API of said plugin, you can choose which driver to print to. You can even skip the print dialog.
A better option, however, would be the generate the PDF server-side, stream it to them, and then use JavaScript inside the PDF to automatically open the print dialog as soon as they view it. This way they don't need any plugins.

Categories