这是iText5函数的一部分,首先获取页面高度和宽度,然后与输入参数进行比较。
Rectangle rectangle = page.getPageSize();
float pageHeight = com.itextpdf.text.Utilities.pointsToInches(rectangle.getHeight());
float pageWidth = com.itextpdf.text.Utilities.pointsToInches(rectangle.getWidth());我浏览了iText7接口,但找不到pointsToInches或类似的函数。看起来很简单,我不确定是我错过了它,还是它掉在iText7里了。任何人都知道它的功能或如何将点转换为英寸。任何帮助都是非常感谢的。
发布于 2018-03-13 09:24:28
我知道这很古老,但是除了@mkl对这个问题的评论之外,它没有其他的答案。默认UserUnit为每英寸72,但可以在页面字典的/UserUnit条目中更改。
看起来他们确实抛弃了inchesToPoints方法,但是一个直接的实现是微不足道的:float points = inches * 72f;。使用页面的UserUnit值的实现是addressed by Bruno in iText 5 here。让它适应iText 7很简单,因为PdfDictionary在这两个方面都有相似的语法。
public static float inchesToPoints(float inches, PdfPage page) {
PdfNumber userUnit = page.getPdfObject().getAsNumber(PdfName.USERUNIT);
float userUnitValue = userUnits == null ? 72f : userUnits.floatValue();
return inches * userUnitValue;
}编辑:它确实写了inches / userUnitValue,但它应该是inches * userUnitValue。
https://stackoverflow.com/questions/40184877
复制相似问题