将表单字段添加到 pdfBox 中的旋转页面
Add form fields to a rotated page in pdfBox
我需要将 adobe 表单字段添加到现有 pdf。
我遇到的问题是在向旋转页面添加字段时,生成的表单字段文本方向不正确。
例如顺时针旋转 90 度的页面会生成文本为 "vertical" 的表单域。
是否有解决方法可以使创建的表单域方向正确?
widget的外观特征字典(/MK条目)有一个/R条目可以设置旋转。参见例如this file.
PDAppearanceCharacteristicsDictionary fieldAppearance
= new PDAppearanceCharacteristicsDictionary(new COSDictionary());
fieldAppearance.setRotation(90);
widget.setAppearanceCharacteristics(fieldAppearance);
您可能需要调整坐标。要找到最佳坐标,请使用 PDFDebugger 并将鼠标悬停在您希望字段所在的位置。
更新:
对于外观流由用户而不是 PDFBox 创建的复选标记(和单选按钮)(如 here or in the PDFBox example 所示),您需要像这样自己设置矩阵(90°):
yesAP.setMatrix(AffineTransform.getQuadrantRotateInstance(1, rect.getWidth(), 0));
这里的“1”表示90°。翻译需要针对其他旋转进行调整。
我需要将 adobe 表单字段添加到现有 pdf。
我遇到的问题是在向旋转页面添加字段时,生成的表单字段文本方向不正确。
例如顺时针旋转 90 度的页面会生成文本为 "vertical" 的表单域。
是否有解决方法可以使创建的表单域方向正确?
widget的外观特征字典(/MK条目)有一个/R条目可以设置旋转。参见例如this file.
PDAppearanceCharacteristicsDictionary fieldAppearance
= new PDAppearanceCharacteristicsDictionary(new COSDictionary());
fieldAppearance.setRotation(90);
widget.setAppearanceCharacteristics(fieldAppearance);
您可能需要调整坐标。要找到最佳坐标,请使用 PDFDebugger 并将鼠标悬停在您希望字段所在的位置。
更新: 对于外观流由用户而不是 PDFBox 创建的复选标记(和单选按钮)(如 here or in the PDFBox example 所示),您需要像这样自己设置矩阵(90°):
yesAP.setMatrix(AffineTransform.getQuadrantRotateInstance(1, rect.getWidth(), 0));
这里的“1”表示90°。翻译需要针对其他旋转进行调整。