[ 
https://issues.apache.org/jira/browse/PDFBOX-5392?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17509388#comment-17509388
 ] 

黄文杰 commented on PDFBOX-5392:
-----------------------------

按照目前业务需要是先对pdf文件按每页进行了拆分,见附件问题文件,拆分是正常的,拆分后,又按上述代码重新进行合并,就产生上述问题,拆分代码如下:

private static List<byte[]> splitPdf(byte[] bytes) {
List<byte[]> result = new ArrayList<>();
PDDocument document = null;
try {
document = PDDocument.load(new ByteArrayInputStream(bytes));
Splitter splitter = new Splitter();
List<PDDocument> pdfPages = splitter.split(document);
for (PDDocument pdfPage : pdfPages) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
pdfPage.save(bos);
result.add(bos.toByteArray());
}
return result;
} catch (Exception e) {
throw new BizException(" 拆分 PDF 失败");
} finally {
IOUtils.closeQuietly(document);
}
}

> java.lang.OutOfMemoryError: Java heap space during ScratchFileBuffer#addPage
> ----------------------------------------------------------------------------
>
>                 Key: PDFBOX-5392
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-5392
>             Project: PDFBox
>          Issue Type: Bug
>            Reporter: 黄文杰
>            Priority: Major
>         Attachments: 问题文件.pdf
>
>
> 在对一个73页的pdf文件,进行拆分单页pdf文件,再重新进行合并时,内存溢出了
> java.lang.OutOfMemoryError: Java heap space
>     at 
> org.apache.pdfbox.io.ScratchFileBuffer.addPage(ScratchFileBuffer.java:132)
>     at 
> org.apache.pdfbox.io.ScratchFileBuffer.ensureAvailableBytesInPage(ScratchFileBuffer.java:184)
>     at 
> org.apache.pdfbox.io.ScratchFileBuffer.write(ScratchFileBuffer.java:236)
>     at org.apache.pdfbox.io.ScratchFile.createBuffer(ScratchFile.java:423)
>     at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:970)
>     at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:891)
>     at 
> org.apache.pdfbox.multipdf.PDFMergerUtility.mergeDocuments(PDFMergerUtility.java:259)



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: dev-h...@pdfbox.apache.org

Reply via email to