html2pdf.js produces a blank document on iOS
See original GitHub issueI’m using html2pdf.js library to produce a dynamically generated report.
It works well on desktop but when I try to output the PDF on iOS the document is blank except for the headers and footers that I added separately.
Below is the code.
`var opt = { margin: [15, 6, 12, 6], filename: ‘${options.FileName}’, image: { type: ‘jpeg’, quality: 0.98 }, html2canvas: { scale: 2 }, jsPDF: { unit: ‘mm’, format: ‘a4’, orientation: ‘portrait’ }, pagebreak: { mode: [‘avoid-all’, [‘p’,‘li’,‘h1’,‘h3’], ‘legacy’] } };
var parentPDF = function(){ var textElem = document.getElementById(‘printFooter’); textElem.style.display = “none”;
var worker = html2pdf().set(opt).from(document.body).toContainer().toCanvas().toImg().toPdf().then(function () {
var pdfObject = worker.prop.pdf;
var number_of_pages = pdfObject.internal.getNumberOfPages();
var pdf_pages = pdfObject.internal.pages;
var myFooter = "";
for (var i = 1; i < pdf_pages.length; i += 1) {
pdfObject.setPage(i);
pdfObject.setFontSize(8);
myFooter = "Page " + i.toString() + "/" + (pdf_pages.length-1);
pdfObject.text(myFooter, 180, 289);
var textElem = document.getElementById('printFooter');
if(textElem){
var text = textElem.textContent;//TODO: get text from HTML
pdfObject.setFontSize(7);
pdfObject.text(text, pdfObject.internal.pageSize.getWidth() - 190, 289);
}
}
pdfObject.output('blob');
window.parent.PDF_CALLBACK(pdfObject.output('blob'));
});
};`
Issue Analytics
- State:
- Created 3 years ago
- Comments:14
Top Results From Across the Web
html2pdf.js produces a blank document on iOS - Stack Overflow
I have resolved this issue by splitting the whole document into pages and then passing pages one by one to the html2pdf library...
Read more >[Solved]-html2pdf.js produces a blank document on iOS
I have resolved this issue by splitting the whole document into pages and then passing pages one by one to the html2pdf library...
Read more >html2pdf.js | Client-side HTML-to-PDF rendering using pure JS.
html2pdf.js converts any webpage or element into a printable PDF entirely ... To capture a default PDF of the entire page, use html2pdf(document.body)...
Read more >All pdf's imported are blank on the Ipad - Apple Community
However, no matter what I try, the Ipad displays them as blank pages. ... I put the new PDF/A document on my iPad...
Read more >[Reactive Print PDF Button] Does not work in IOS, Safari or ...
This component is very perfect. But I have one issue, I think it is not compatible with a mobile browser. When the print...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I will put below the way I did it. Still, I had to ask the user not to create a PDF with more then 10 pages and to pray he/she won’t 😃
I hope this will help you. P.S: play with the options to fit your needs.
@syrykh-anastasiia what is your pagebreak mode? if you are using
avoid-allinpagebreak: { mode: ['avoid-all'] }, removeavoid-alland check.