Save HTML5 page as PDF - javascript

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

Related

Converted PDF should be saved on server side, not downloaded

The issue is that a converted PDF is downloaded by the client. I need the PDF to be saved on server side and sent by mail.
I am using jsPDF and html2canvas for converting HTML to PDF.
I guess that jsPDF is not the proper tool for your task. First line at Github is "Client-side JavaScript PDF generation for everyone" which says it all.
To let the server create a PDF, you need a tool which renders the HTML result and creates a PDF from it. Maybe a MS Word or OpenDocument template used in headless mode will suit your needs, as suggested here among other solutions.

Universal document viewer in browser - without server side conversion

I want to embed a document viewer in my webpage, which should support all microsoft office formats, pdf, images, etc.
I don't want file conversion to happen on server side and then send it back to html viewer.
Is there a way to instantly view the file with original format directly in browser? Or is there a way to convert files to browser supported formats on fly in frontend (using Javascript) and show it instantly? Is there any product that does it now?
A quick google search shows there are a few javascript libraries out there that can deal with MS Office docs, e.g. DOCX.js, although they may not cover all your use cases.

ways to open large-sized pdf without downloading (using open on javascript)

Good day,
I have a system that renders large amount of data through pdf ( 30mb + ). Now I want the user to view pdf first so he can either download it or just print it right away. as of the moment I am forcing the user to download the file since open( 'datauri here' ) wont work with larger files.. the problem with downloading is that files are multiplying and consumes space over time and also its not necessary for me to download all files that that they want to print right away.
I need a functionality that is similar to chrome's preview when using windows.print
can you please suggest any ideas or other things to do this?
I am currently using javascript library to create pdf (pdfmake). I am also using chrome as my main browser
You would have to make sure that the PDF is optimized for fast web view, and that your server is using the byteserving protocol for serving the file.
If that is the case, a useful PDF viewer (such as the web browser component provided by Acrobat/Reader) understands this protocol and requests (after the first page plus overhead of the PDF) only the data for the pages which are to be displayed.
A quick search did, however, not reveal whether the Chrome PDF viewing component is smart enough to understand the byteserving protocol.

How to create a jpg image with Javascript?

i'm creating a web application to generate images according to user's input, more precisely a barcode generator. i'm using javascript to process the data input by user. In the end, i want to have my output barcode as an jpg or png. What other tools do i need? I know that javascript cannot create the .jpg or .png file for me. What other tools can help me generate an image file?
Its possible using Canvas element in HTML5
http://blog.nihilogic.dk/2008/04/saving-canvas-data-to-image-file.html
I dont know i there any free script is out there but you can try this one:
http://www.java4less.com/barcodesjavascript/barcodesjavascript.php?info=intro
Hope its help,
Karls
I have created previews of user driveways after pavement using PHP GD with a picture submitted by the user.
It's done with PHP so you would POST the data to a PHP script on the server side and create the image from there.
I went as far as having the user click and make a path of the section to remove (the old driveway) and use that to cut out the driveway and replace it with a background layer.
You can set up PHP locally with Apache or IIS. PHP is pretty much standard on all hosting services.
You could build an image editor with it.
https://www.php.net/manual/en/book.image.php

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