简体   繁体   English

html2pdf错误的页面大小和缺少的CSS

[英]html2pdf wrong page size and missing css

Im using html2pdf ( https://github.com/eKoopmans/html2pdf ) to convert a form to pdf onclick. 我使用html2pdf( https://github.com/eKoopmans/html2pdf )将表单转换为pdf onclick。 The form itself is very complex and includes 4 pages of css/js/html. 表单本身非常复杂,包含4页css / js / html。 Im just trying to capture one page of that now. 我只是想立即捕获其中的一页。

The plugin does what i want, but the page size is wrong and some css is missing. 该插件可以执行我想要的操作,但是页面大小错误并且缺少某些CSS。 Online the end of the form looks like: End of page 1 在线表单的结尾如下: 第1页结束

The end of the generated pdf looks like this: End of page 1 pdf 生成的pdf的结尾如下所示: 第1页pdf的结尾

The left and top margin is ok, right and bottom are not fitting and the whole text is a little too big on pdf. 左边和顶部的空白都可以,右边和底部的位置不合适,并且整个文本在pdf上太大了。 Maybe sth like a code to make the whole image size smaller would help to get all back on one page, since the original also has smaller text. 也许像是使整个图像尺寸更小的代码将有助于使所有图像重新回到一页上,因为原始文本的文字也较小。 Also as you can see, the blue frames around the text are missing. 另外,如您所见,文本周围的蓝框丢失了。 I guess thats css. 我猜多数民众赞成在CSS。

My code looks like this: 我的代码如下所示:

 <script type="text/javascript" src="https://rawgit.com/eKoopmans/html2pdf/master/dist/html2pdf.bundle.min.js"></script> <script> function printPDF() { var element = document.getElementById('element-to-print'); html2pdf(element, { hmargin: -0.60, vmargin: 20, filename: 'myfile.pdf', image: { type: 'jpeg', quality: 0.98 }, html2canvas: { dpi: 192, letterRendering: true }, jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait'} }); } </script> 

我认为您需要将此样式包括在某处, overflow: 'linebreak',如果您处理表格,我也建议使用jspdf autotable

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM