jcing
1
一个9M多一点的PDF文件,等了3个小时都没有处理结束?
Document pdfDocument = new Document(outPath + PDF_FILENAME);
PageCollection pageCollection = pdfDocument.getPages();
if (pageCollection == null) {
System.out.println(“is null!”);
return;
}
System.out.printf(“run2.1… \n”);
PrintWriter out = new PrintWriter(outFile);
try {
System.out.printf("run2.2... \n");
TextAbsorber textAbsorber = new TextAbsorber(new TextExtractionOptions(TextExtractionOptions.TextFormattingMode.Raw));
pageCollection.accept(textAbsorber);
System.out.printf("run2.3... \n");
String extractedText = textAbsorber.getText();
System.out.printf("run2.4... \n");
out.println(extractedText);
mResult.put(TEXT_STATUS_KEY, SUCCESS);
mResult.put(TEXT_MESSAGE_KEY, TEXT_FILENAME);
} finally {
pdfDocument.close();
out.flush();
out.close();
}
输出了run2.3… ,textAbsorber.getText() 就下不去了!
@jcing
感谢您与支持人员联系。
您能否将源PDF文件上传到Google Drive,Dropbox等,以便我们可以尝试在我们的环境中重现和调查它。 在共享请求的数据之前,请确保使用 Aspose.PDF for Java 18.9.1。
还分享您的环境详细信息,包括JDK / JRE版本,操作系统详细信息等。
jcing
3
jcing
4
JDK: openjdk version “1.8.0_171”
操作系统:Linux version 4.15.0-29deepin-generic
jcing
5
我昨天晚上开了7台服务器,都是32G内存的+24核CUP处理PDF,12个小时左右只处理了800个左右!
我现在手头上需要批量转的pdf有5万多个,这种速度基本整个项目基本要泡汤的感觉呀?
jcing
6
image.png (319.3 KB)
cup都100%了,就是不出结果呀?急死人了!
@jcing
感谢您与支持人员联系。
我们已经注意到TextFragmentAbsorber
的问题,并且在我们的问题管理系统中记录了带有ID PDFJAVA-38063的故障单,以便进一步调查和解决。 故障单ID已与此线程链接,以便您在解决故障单后立即收到通知。
此外,请您详细说明如何传输PDF文件并面对速度问题,以便我们调查它以帮助您。
jcing
9
image.png (47.0 KB)
cup占用1000多,处理了101个小时!
@jcing
请在共享示例应用程序时详细说明问题,以便我们可以尝试在我们的环境中重现和调查它。
@jcing
关于PDFJAVA-38063,在文本提取算法的堆内存使用中发现了一个问题。 我们正在进一步调查。
但是,下面是逐页提取文本的变通方法。 我们的电脑需要1分20秒。
String PDF_FILENAME = "dbc83203bb9b4eb1e637867f9f272d4f";
Document pdfDocument = new Document(myDir + PDF_FILENAME+".pdf");
PageCollection pageCollection = pdfDocument.getPages();
if (pageCollection == null) {
System.out.println("is null!");
return;
}
System.out.printf( "run2.1... \n");
int pagesCount = pageCollection.size();
PrintWriter out = new PrintWriter(myDir + PDF_FILENAME+"_text.txt");
try {
System.out.printf("run2.2... \n");
StringBuilder extractedText = new StringBuilder();
for (int i = 1; i <=pagesCount ; i++) {
Page p = pdfDocument.getPages().get_Item(i);
TextAbsorber textAbsorber = new TextAbsorber(new TextExtractionOptions(TextExtractionOptions.TextFormattingMode.Raw));
p.accept(textAbsorber);
System.out.printf("run2.3... \n for page: "+ p.getNumber());
extractedText.append(textAbsorber.getText());
pdfDocument.dispose();
pdfDocument = new Document(myDir + PDF_FILENAME+".pdf");
}
System.out.printf("run2.4... \n");
out.println(extractedText.toString());
} finally {
pdfDocument.close();
out.flush();
out.close();
}
jcing
13
Document pdfDocument = new Document("/data/1.pdf");
pdfDocument.setEmbedStandardFonts(true);
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
saveOptions.setFixedLayout(true);
saveOptions.setSplitIntoPages(true);
saveOptions.FontSavingMode = HtmlSaveOptions.FontSavingModes.AlwaysSaveAsWOFF;
saveOptions.LettersPositioningMethod = LettersPositioningMethods.UseEmUnitsAndCompensationOfRoundingErrorsInCss;
saveOptions.RasterImagesSavingMode = HtmlSaveOptions.RasterImagesSavingModes.AsEmbeddedPartsOfPngPageBackground;
pdfDocument.save(mHtmlPath.getAbsolutePath() + "/out.html", saveOptions);
这段代码也是很慢的,有办法向上面一样一页导出后重建document的方法改善速度问题呢?
jcing
14
Document pdfDocument = new Document(outPath + PDF_FILENAME);
PageCollection pageCollection = pdfDocument.getPages();
if (pageCollection == null) {
System.out.println("is null!");
return;
}
int pagesCount = pageCollection.size();
for (int i = 1; i <= pagesCount; i++) {
Page p = pdfDocument.getPages().get_Item(i);
Document tmpDoc = new Document();
tmpDoc.setEmbedStandardFonts(true);
tmpDoc.getPages().add(p);
HtmlSaveOptions saveOptions = new HtmlSaveOptions();
saveOptions.setFixedLayout(true);
saveOptions.setSplitIntoPages(true);
saveOptions.FontSavingMode = HtmlSaveOptions.FontSavingModes.AlwaysSaveAsWOFF;
saveOptions.LettersPositioningMethod = LettersPositioningMethods.UseEmUnitsAndCompensationOfRoundingErrorsInCss;
saveOptions.RasterImagesSavingMode = HtmlSaveOptions.RasterImagesSavingModes.AsEmbeddedPartsOfPngPageBackground;
tmpDoc.save(mHtmlPath.getAbsolutePath() + "/" + Integer.toString(i) + ".html", saveOptions);
pdfDocument.close();
pdfDocument.dispose();
tmpDoc.dispose();
pdfDocument = new Document(outPath + PDF_FILENAME);
}
The issues you have found earlier (filed as PDFJAVA-38063) have been fixed in Aspose.PDF for Java 18.11.