Convert URL to PDF from the client-end - javascript

I want to save a web URL as a PDF. For example we can File->Save As-> PDF on the browser to save a webpage as a PDF.
But, in my case when the User provides a URL, I want to convert that URL to a PDF pragmatically.
There are many libraries and SO post on extracting the URL from the backend. According to my requirement I want the PDF to be generated on the Client-Side itself. So the user downloads exactly what he sees.
These are some of the links I visited:
Export HTML page to PDF on user click using JavaScript
Generate pdf from HTML in div using Javascript
Can someone help me to convert a webpage (given as a URL) to PDF format ?

Related

JS: How to download PDF (via download url) automatically and attach it to an email?

I have a next.js project, where I want to attach a PDF to an email. The PDF is generated automatically with PDF Monkey. After the generation is successful, I get a JSON response with a download url.
Now, I'd like to attach this document as a PDF in an email (nodemailer). I don't want to send an email with a download link to the PDF.
Can someone tell me what's the process to do so (download PDF automatically, save it somewhere)? Is it possible?

Attach pdf to mail with js

I am using jspdf to generate pdf. I am using that library to generate pdf in my ionic app which generates somekind of report and the file plugin, mail plugin are used to create file and attach to email app and this is pretty cool and easy there.
But i am migrating this to web user. I can also generate the pdf in the browser and can be saved to user pc.Is there handy method that i can attach generated pdf instantly to the form ?(I think mailto: cannot be used to attach the file so i want to use form to send the pdf file to server).
And last question, i can send the base64 data to php server.Is there any method that base64 can be converted to pdf in php? (i am not much familiar with the php)

PDF JS Functionality

I have created a HTML project. But my main aim is to display the pdf's on my site so that users can't save or download them is this possible using (https://mozilla.github.io/pdf.js/) viewer? If so how can i do it because i'm trying to output a lot of pdfs and this just seems impossible to do looking at the code.
No, it's not possible to display native pdfs to the user without allowing them to download them. By the nature of http, they will have had to download the pdf data in order for them to be displayed.
However, you could take snapshots of the pdf on the server, and display these to the user as pngs.
There are a number of libraries that will allow you to convert the first page of a pdf to an image, I suggest you start by trying to implement one of those.

How using javascript can i save a PDF from inside a frame with a html5 <embed> tag

I have a website which dynamically creates a PDF after some user selection in one of its frames. It uses the HTML5 tag to display the PDF file.
Can someone help me with a script which:
detect when a pdf is loaded (do we need to determine the frame first?)
save the pdf to a local storage location (iOS)
To scrape a PDF for data, may I suggest you look into this lib from Mozilla:
https://github.com/mozilla/pdf.js/
With this, you should be able to load the PDF from a URL and then scrape the necessary data from that PDF without it ever needing to touch "local storage." Here is a link to a Hello World example to get you started:
http://jsbin.com/pdfjs-helloworld-v2/1/edit
Note:
In web parlance, local storage refers to the browser's LocalStorage API which is not related to saving to the device's HDD.

How to use data URI to deliver MSWord document (.docx) to Chrome?

I have a JavaScript app that does client-side encryption & decryption of files, storing the encrypted data at Google Cloud Storage. All the encryption & data transfer stuff works correctly, but I'm having trouble getting all document types to open in Chrome. PDF works fine because of Chrome's built-in PDF viewer, but I would like to have it auto-open other file types as well. For example:
JavaScript app retrieves encrypted data, then decrypts it to produce a String or ByteArray containing a Word document.
I create a data URI and call window.open() on it. In the PDF case, a new tab opens with the PDF document. When the data URI is a Word document (MIME type application/vnd.openxmlformats-officedocument.wordprocessingml.document) I get a blank window with (apparently) no content.
I have been able to create an <A> tag with the data URI, and it downloads the correct data if the user right-clicks the link, but although I've set that MIME type to auto-open upon download, Chrome doesn't open it. (It does auto-open Word docs sent from a regular HTTP request with that MIME type.)
I would like to do several things with my decrypted data, starting with it in a client-side JavaScript string:
Open in a new tab/window (for things that the browser can do, or has a plugin for)
Open in external application
Save as file
Any help on these?
Thanks!
It will need that Google Chrome also have a MS Word viewer as well. Something that is not included by default like the PDF viewer...

Categories

Resources