Convert HTML to PDF with links - javascript

Is there a node.js module or a javascript library that can convert HTML/Page into PDF with selectable texts and working links? I've tried Phantomjs. But since its the only screenshot the page and convert it to pdf, texts are not selectable and links are not working. Also tried jsPDF but links are not working either. Hope you guys can share some of your experience in dealing the same problem.
Your response is greatly appreciated.

You can parse the HTML body with htmlparser. The complete html will be properly converted to JSON.
Depending upon the keys, you can then write it to a PDF using pdfkit.
This is very general solution. If you give us an insight as to what type of HTML you want to get into a PDF, maybe then we would be able to help with some specific code or logic.

Try http://www.cloudformatter.com/css2pdf.
Their links demo at http://www.cloudformatter.com/CSS2Pdf.Demos.Hyperlinks shows external links and internal links within the generated PDF.

Related

jQuery/Javascript Create PDF from HTML/CSS with selectable text

I'm trying to convert a web page content into a PDF and I've successfully done it with jsPDF + html2canvas and with html2pdf but the problem with both approaches are that they convert the content into an image and then generate the PDF off the image and I need the PDF content to be "selectable" because I need to pass certain tags that will be read by another application.
so far I haven't found anything that would allow me to do this with jquery/javascript.
Any ideas how to accomplish this?
Thanks in advance,

pdfkit library is not embedding images in the pdf file generated

I am using PDFkit with node.js to convert an html page to pdf. HTML page has several image tags in body tag.
However When I convert html to pdf I get the black page generated. Can someone help me with the issue? thanks in advance!
#simran I hope this answer solves your issue. Try this logic it works for me:
I just posted it on another thread for pdf related issue: https://stackoverflow.com/a/64114358/3202440

"buttonImportIcon" syntax for Javascript PDF code

I am attempting to import an icon into a button form field, using a page from a separate PDF file. I need to use other pages rather than just the first page of the document and I have tried to accomplish this by specifying "nPage" in the syntax. Regardless of this input, the icon only imports the first page of the document. Below is the syntax that I currently have:
this.getField("test").buttonImportIcon({
cPath: "Z:/tempDWGs.pdf",
nPage: 4
});
Does anyone know why the code above is using page '0' from the source document and not page '4'? Any help is greatly appreciated!
This was a bug in the software specific coding engine that was not processing the command correctly. The above code is correct and should work as intended.

Convert a long HTML page to PDF persisting CSS

I have tried JSPDF and HTML2Canvas for this. While the HTML is rendered successfully, its CSS is entirely messed up. I also read somewhere that html2canvas doesn't work with long pages.
Can anyone provide me a simple Javascript code that takes DOM element and generates its PDF and also maintains its CSS? I would really appreciate it. Thanks.

Generate PDF of a section of a php page once rendered into HTML and CSS and account for pdf page-breaks

The system I am working on has a questionnaire in it and then shows the responses to the admin in a nice report on screen. I need to create functionality that turns the on screen report into a pdf, similar to how the browser generates a pdf of the page when you select print. Although I need to only turn a section of the page into pdf. And it would be ideal to be able to alter the HTML so that the pdf page breaks don't interfere with the presentation of the report.
You can download a pdf of how the report looks, generated by the browser functionality. This is just an example, I need the pdf to be generated by a link or button and not include the whole page (the top part in this case).
I have tried some php HTML to pdf generators, but it's difficult because the HTML is dynamically generated so I'm not sure how to send all the HTML, once rendered, to the page that creates the pdf.
To overcome the page breaks, I've considered using javascript or jquery to read the height of the div of each question within the report and then write a simple script to calculate if the next div will fit on the page and if not add a margin on top of that div so that it starts on a new page.
What software can I use to generate the pdf, given these requirements? Either php or javascript. Appreciate the help.
Have you considered Snappy for PHP? It makes use of wkhtmltopdf behind the curtains to convert any HTML document into PDF.
We are using it and it works great.
https://github.com/KnpLabs/snappy
You could try mpdf and use the page-break-inside: avoid property which is actually a CSS property. I have not used this, but it might be what you're looking for.
Looks like you can add this property to the <div> and <table> tags (mPDF Supported CSS).

Categories