私は PDF 署名用に Itext ライブラリを使用しています。しかし、ファイルサイズが150MBの場合のように、サイズが大きいファイルはクラッシュしています
Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
at com.itextpdf.text.pdf.ByteBuffer.append(ByteBuffer.java:210)
at com.itextpdf.text.pdf.ByteBuffer.write(ByteBuffer.java:622)
at java.io.BufferedOutputStream.write(BufferedOutputStream.java:105)
at java.io.FilterOutputStream.write(FilterOutputStream.java:80)
at com.itextpdf.text.pdf.OutputStreamCounter.write(OutputStreamCounter.java:104)
at com.itextpdf.text.pdf.PRStream.toPdf(PRStream.java:230)
at com.itextpdf.text.pdf.PdfIndirectObject.writeTo(PdfIndirectObject.java:157)
at com.itextpdf.text.pdf.PdfWriter$PdfBody.write(PdfWriter.java:397)
at com.itextpdf.text.pdf.PdfWriter$PdfBody.add(PdfWriter.java:386)
at com.itextpdf.text.pdf.PdfWriter.addToBody(PdfWriter.java:848)
at com.itextpdf.text.pdf.PdfStamperImp.close(PdfStamperImp.java:353)
at com.itextpdf.text.pdf.PdfStamperImp.close(PdfStamperImp.java:327)
at com.itextpdf.text.pdf.PdfSignatureAppearance.preClose(PdfSignatureAppearance.java:1244)
at com.itextpdf.text.pdf.security.MakeSignature.signDetached(MakeSignature.java:134)
これは、50 MB未満のpdfファイルで正常に機能する私の署名コードです
private void PdfSigningProcess(String src, String dest,
Certificate[] chain,
PrivateKey pk, String digestAlgorithm, String provider,
MakeSignature.CryptoStandard subfilter, String reason, String location)
throws
GeneralSecurityException, IOException, DocumentException
{
// Creating the reader and the stamper
PdfReader reader =
new PdfReader(src);
FileOutputStream os =
new FileOutputStream(dest);
PdfStamper stamper = PdfStamper.
createSignature(reader, os, '\0');
//Creating the appearance PdfSignature Appearance
PdfSignatureAppearance appearance = stamper.getSignatureAppearance();
appearance.setReason(reason);
appearance.setLocation(location);
appearance.setVisibleSignature(new Rectangle(36, 7, 48, 144, 780), 1, "DQCA Signature");
// Creating the signature
ExternalDigest digest = new BouncyCastleDigest();
ExternalSignature signature =
new PrivateKeySignature(pk, digestAlgorithm, provider);
MakeSignature.signDetached(appearance, digest, signature, chain, null, null, null, 0, subfilter); //HERE IT IS CRASHING
}
「MakeSignature.signDetached」これは例外が発生する関数です...書き込みと追加のプロセスはこの関数内にあり、行ごとにデータを変更してフラッシュすることはできないため、この問題を修正する方法を教えてください...