如何使用pdfbox获取字体大小 [英] how to get font size using pdfbox

查看:143
本文介绍了如何使用pdfbox获取字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道 TextPosition 中的 getFontSize 方法是否总是返回一个,我应该只使用 getFontSizeInPt 来获取字体的大小吗?我遇到的问题是 getFontSizeInPt 有时会为相同大小的文本返回不同的值(对于相同大小的同一段落中的文本,我得到了 12 和 11 返回值.

Does anyone know if the method getFontSize in TextPosition always returns one and should I only use getFontSizeInPt to get the size of the font? The problem I have is that getFontSizeInPt sometimes returns different values for the same sized text (I got 12 and 11 return for text in the same paragraph with the same size.

推荐答案

有谁知道TextPosition中的getFontSize方法是否总是返回一个

Does anyone know if the method getFontSize in TextPosition always returns one

它并不总是返回一个.

请注意,在 PDF 页面内容描述中,有几个设置都会影响最终文本大小:

Please be aware that in the PDF page content descriptions there are several settings which all influence the final text size:

  • 字体选择运算符Tf的字体大小参数:
  • 运算符设置的文本矩阵Tm;
  • 算子设置的当前变换矩阵cm;
  • PDF 页面的UserUnit设置.
  • the font size parameter of the font selecting operator Tf:
  • the text matrix set by the operator Tm;
  • the current transformation matrix set by the operator cm;
  • the UserUnit setting of the PDF page.

最终的文本大小是由文本矩阵缩放的第一个值,由变换矩阵再次缩放,并再次由用户单位值缩放.

The final text size is the first value scaled by the text matrix, scaled again by the transformation matrix, and scaled once more by the user unit value.

(实际上还有更多的因素.例如,如果使用渲染模式 2、填充和描边,对于人造粗体效果,这也会略微增加尺寸.)

(Actually there even are some more factors. E.g. if one uses rendering mode 2, fill & stroke, for a faux bold effect, this slightly increases the size, too.)

TextPosition.getFontSize 仅返回第一个值.

TextPosition.getFontSizeInPt 返回类似于矩阵缩放的第一个值.(类似,因为乍一看似乎还有另一种影响.)

TextPosition.getFontSizeInPt returns something like the first value scaled by the matrices. (something like because at first glance there seems to be another influence in it.)

不同的 PDF 创建者以不同的方式使用这些影响:

Different PDF creators use these influences in different ways:

  • 某些 PDF 创建者仅使用第一个值来设置字体大小,并且仅将矩阵用于不更改有效字体大小的操作,例如旋转.
  • 某些 PDF 创建者将第一个值设置为 1 并使用矩阵进行缩放.
  • 一些 PDF 创建者介于两者之间,它们同时使用第一个值和缩放操作.

因此,您的 PDF 似乎是由软件使用第二种方式创建的.

Thus, your PDFs seem to be created by software using the second way.

getFontSizeInPt 有时会为相同大小的文本返回不同的值(对于相同大小的同一段落中的文本,我得到了 12 和 11 的返回值.

getFontSizeInPt sometimes returns different values for the same sized text (I got 12 and 11 return for text in the same paragraph with the same size.

你能分享一个关于这个问题的示例 PDF 吗?如上所述,乍一看似乎还有其他可能不正确的影响.但您的 PDF 也可能有一些特别之处.

Could you share a sample PDF with that issue? As mentioned above, at first glance there seem to be additional influences which might be incorrect. But there also might be something special about your PDF.

这篇关于如何使用pdfbox获取字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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