我正在尝试将多个大型PDF文件(〜10MB)与书签合并在一起。 它适用于较小的PDF文件,但如果有一些非常大的文件需要合并,则无法使用。
下面是我在Groovy中编写的代码
public class MergePDFBookmarks
{
public static void mergePDFFiles(Map jsonobj, String pathname, String
pdfoutfullpath)
{
def mergePdf = new PDFMergerUtility();
jsonobj.each{k,v->
if (v instanceof List){
v.each{it ->
mergePdf.addSource(pathname + "/" + it["TLF_ID"] + ".pdf")
}
}
}
println "Merging to PDF File: " + pdfoutfullpath + ".pdf"
mergePdf.setDestinationFileName(pdfoutfullpath)
mergePdf.mergeDocuments()
}
错误消息: 我收到错误消息,说
org.codehaus.groovy.runtime.callsite.StaticMetaMethodSite.call(StaticMetaMethodSite.java:88)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:133)
at MergePDFBookmarks.main(Script1.groovy:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:88)
... 6 more
Caused by: java.lang.OutOfMemoryError: GC overhead limit exceeded
at java.util.Arrays.copyOf(Arrays.java:2219)
at java.util.ArrayList.grow(ArrayList.java:242)
at java.util.ArrayList.ensureExplicitCapacity(ArrayList.java:216)
at java.util.ArrayList.ensureCapacityInternal(ArrayList.java:208)
at java.util.ArrayList.add(ArrayList.java:440)
at org.apache.pdfbox.cos.COSArray.add(COSArray.java:52)
at org.apache.pdfbox.pdfparser.BaseParser.parseCOSArray(BaseParser.java:1092)
at org.apache.pdfbox.pdfparser.BaseParser.parseDirObject(BaseParser.java:1275)
at org.apache.pdfbox.pdfparser.BaseParser.parseCOSDictionaryValue(BaseParser.java:249)
at org.apache.pdfbox.pdfparser.BaseParser.parseCOSDictionary(BaseParser.java:356)
at org.apache.pdfbox.pdfparser.BaseParser.parseDirObject(BaseParser.java:1264)
at org.apache.pdfbox.pdfparser.PDFObjectStreamParser.parse(PDFObjectStreamParser.java:106)
at org.apache.pdfbox.cos.COSDocument.dereferenceObjectStreams(COSDocument.java:683)
at org.apache.pdfbox.pdfparser.PDFParser.parse(PDFParser.java:255)
at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:1227)
at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:1194)
at org.apache.pdfbox.util.PDFMergerUtility.mergeDocuments(PDFMergerUtility.java:238)
at org.apache.pdfbox.util.PDFMergerUtility.mergeDocuments(PDFMergerUtility.java:195)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)