Solved: html2pdf / jsPDF elements are cut off in the PDF

So I am using some JavaScript libraries in my Apache Cordova app to save some HTML to a PDF file, which can then be shared via email and social.
The problem was that the rendered content of the HTML element is only as wide as the parent element, which caused me some headaches as the content of the PDF (like the tables and text) were cut off at the width of the parent element.

The parent element was – in my case – simpy as wide as the browser’s viewport, which is kind of bad on a mobile device. So I tried several things – without much success. At last, I have had to use a dirtly little hack to make the canvas/render area wider.

I simply inserted a div with a fixed width of – in this case – 1500px. That fixed it for me.

Surely it is not nice code, and there may must be a way to do it within the JavaScript, but until I find out how, I will resort to this solution.

Veröffentlicht von

Christian Hänsel

Web-Entwickler, Experte für technisches SEO. ich liebe meinen Job, meine Familie und den Libanon. Fragen? Mail: chris@haensel.pro.

Ein Gedanke zu „Solved: html2pdf / jsPDF elements are cut off in the PDF“

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.