itext 7 html至pdf并具有页面大小检测 [英] itext 7 html to pdf with page size detection

查看:240
本文介绍了itext 7 html至pdf并具有页面大小检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用itext 7将HTML模板(Velocity)呈现为PDF,然后呈现为PNG(Apache PdfBox),以进行热敏打印机打印.

I am using itext 7 to render HTML templates (Velocity) to PDF, then to PNG (Apache PdfBox), for thermal printer printing.

我的模板呈现为:

<html>
<head>
    <style>...</style>
</head>
<body>
    <div id="container">...</div>
</body>
</html>

我的容器的固定宽度为512像素.我想测量html的呈现高度,然后将其呈现为页面高度=测量高度的单页PDF.

My container has a fixed width to 512px. I would like to measure the rendered height of the html, and then render it as a single page PDF with page height = measured height.

但是渲染的尺寸不是预期的尺寸.我希望渲染的宽度为512px,但是layoutResult返回的宽度为385(而不是预期的512).

But the rendered size is not the expected size. I expect to have a rendered width of 512px, but the layoutResult returns a width of 385 (instead of the expected 512).

我错过了哪个参数? 谢谢.

Which parameter have I missed ? Thanks.

推荐答案

请查看FAQ条目

Please take a look at the FAQ entry How do the measurement systems in HTML relate to the measurement system in PDF? You'll discover that:

1英寸= 96像素

1 inch = 96 px

1英寸= 72个用户单位= 72磅

1 inch = 72 user units = 72 pt

看看您拥有的数字,就好像您在混淆像素和点.

Looking at the numbers you have, it looks as if you are confusing pixels and points.

96 px = 72 pt
512 px = 512 / 96 * 72 pt
512 px = 384 pt

我猜您期望512像素并获得384 pt,但这并不是一个错误,因为512 px等于384 pt.因此没有问题.问题的主要问题是您忘记提及测量系统.

I guess you expect 512 px and get 384 pt, but that's not an error, because 512 px equals 384 pt. Hence there is no problem. The main problem with your question is that you forget to mention the measurement system.

这篇关于itext 7 html至pdf并具有页面大小检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆