使用 pdflib 和 pCos 获取表单字段位置
Get form field position with pdflib and pCos
对于一个项目,我必须以正确的顺序获取 pdf 的表单字段,我使用 pdflib,但提取的字段位置与它们在 PDF 中出现的位置不同。
我认为我们可以使用 pCos 提取表单字段位置,但我找不到解决方案。
谢谢!
您可以通过使用字段的“/Rect”字典,使用 pCos 检索表单字段的矩形。一个非常简单的(基于 java 的样本)看起来像这样:
String rect_path = "fields[" + f + "]/Rect";
if (p.pcos_get_string(doc, "type:" + rect_path).equals("array")
&& (int) p.pcos_get_number(doc, "length:" + rect_path) == 4) {
System.out.print("[");
for (int i = 0; i < 4; i += 1) {
if (i > 0) {
System.out.print(" ");
}
System.out.print(p.pcos_get_number(doc, rect_path + "[" + i + "]"));
}
System.out.print("], ");
}
"Rect" 字典包含四个值,具有表单字段的左下角和右上角坐标。所以你可以遍历字典并检索值。
您可能会在 pCOS cookbook
中找到更多示例
对于一个项目,我必须以正确的顺序获取 pdf 的表单字段,我使用 pdflib,但提取的字段位置与它们在 PDF 中出现的位置不同。 我认为我们可以使用 pCos 提取表单字段位置,但我找不到解决方案。
谢谢!
您可以通过使用字段的“/Rect”字典,使用 pCos 检索表单字段的矩形。一个非常简单的(基于 java 的样本)看起来像这样:
String rect_path = "fields[" + f + "]/Rect";
if (p.pcos_get_string(doc, "type:" + rect_path).equals("array")
&& (int) p.pcos_get_number(doc, "length:" + rect_path) == 4) {
System.out.print("[");
for (int i = 0; i < 4; i += 1) {
if (i > 0) {
System.out.print(" ");
}
System.out.print(p.pcos_get_number(doc, rect_path + "[" + i + "]"));
}
System.out.print("], ");
}
"Rect" 字典包含四个值,具有表单字段的左下角和右上角坐标。所以你可以遍历字典并检索值。
您可能会在 pCOS cookbook
中找到更多示例