gpt4 book ai didi

java - 我如何比较 pdf 的 2 个版本并忽略页脚?

转载 作者:行者123 更新时间:2023-12-01 23:46:19 25 4
gpt4 key购买 nike

我完全比较了具有相同页码的 pdf 的 2 个版本并忽略了页脚,实际上我正在使用 pdfbox,它与叠加图像进行比较并获得差异
所以我每次计算宽度和高度并创建包含页脚示例排除列表的文本文件

exclusions: [
{
page: 1
},
{
page:2
x1:0
y1:2310
x2:7433.827087402344
y2:2440.627600097656
},
{
page:3
x1:0
y1:2310
x2:7433.827087402344
y2:2440.627600097656
},
{
page:4
x1:0
y1:2310
x2:7075.852087402343
y2:2440.627600097656
}
]

一个输入流,它将文件作为输入,以便我可以将其作为 pdfComparator 的参数传递直到第 19 页都工作正常有人可以帮助我吗?

  private static void generateFileForIgnoreFooterInCompare(final File pdf) throws IOException {
final PDDocument doc = PDDocument.load(new File(String.valueOf(pdf)));
File PagesArea = new File("PagesArea.txt");
FileWriter fw = new FileWriter(PagesArea);
StringBuilder stb = new StringBuilder("exclusions: [").append(System.lineSeparator());
stb.append("{").append(System.lineSeparator()).append("page: 1").append(System.lineSeparator()).append("},").append(System.lineSeparator());


int footerHeight = 130;
for (int i = 2; i < doc.getNumberOfPages(); i++) {
double temp = doc.getPage(i).getMediaBox().getLowerLeftY();



double pageWidth = (doc.getPage(i).getMediaBox().getWidth()) * 4.3;
double pageHeight = (doc.getPage(i).getMediaBox().getHeight()) * 4.1;
int startIgnorePoint = (int) pageHeight - footerHeight;

stb.append("{").append(System.lineSeparator()).append("page:" + i).append(System.lineSeparator());
stb.append("x1:" + Integer.parseInt("0")).append(System.lineSeparator());
stb.append("y1:" + startIgnorePoint).append(System.lineSeparator());
stb.append("x2:" + pageWidth).append(System.lineSeparator());
stb.append("y2:" + pageHeight).append(System.lineSeparator());
stb.append(" },").append(System.lineSeparator());
}
stb.deleteCharAt(stb.lastIndexOf(","));
stb.append("]");
fw.write(stb.toString());
fw.close();
}
//------------------------------------------------------------


InputStream inputStreamForIgnoredArea = new FileInputStream("PagesArea.txt");

PdfComparator pdfComparator =
new PdfComparator(pdf1.getCanonicalPath(), pdf2.getCanonicalPath(), new CompareResultWithPageOverflow(5)).withIgnore(inputStreamForIgnoredArea);

1[![][1] ] 2

最佳答案

你可以尝试https://github.com/lumpchen/xdiff.ncc ,它也是基于pdfbox的。您可以将 footer 区域设置为接受区域,以忽略 footer 的差异。

关于java - 我如何比较 pdf 的 2 个版本并忽略页脚?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58239498/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com