Troubleshooting
Troubleshooting
ドキュメントが閉じられない — メモリリーク
Document は AutoCloseable を実装します。常に try-with-resources ブロックを使用してください:
try (Document doc = new Document("input.pdf")) {
// operations
} // doc.close() called automaticallyOutOfMemoryError(大きなファイル)
大きなドキュメントの場合、PdfFileEditor でディスクバッファリングを有効にしてください:
PdfFileEditor editor = new PdfFileEditor();
editor.setUseDiskBuffer(true);
editor.concatenate(inputFiles, "output.pdf");PdfFileSecurity: パスワードが正しくありません
decryptFile(password) は、提供されたパスワードが正しくない場合に false を返します。常に戻り値を確認し、失敗ケースを処理してください:
try (PdfFileSecurity security = new PdfFileSecurity()) {
security.setInputFile("encrypted.pdf");
security.setOutputFile("decrypted.pdf");
boolean ok = security.decryptFile("ownerPassword");
if (!ok) {
System.err.println("Decryption failed — verify the owner password.");
}
}PdfFileEditor: ヌル引数
PdfFileEditor.resizeContents() は例外を投げる代わりに null 引数を黙って無視します。resizeContents() 後に出力ドキュメントが変更されていないように見える場合は、ContentsResizeParameters 引数が null でなく、パーセンテージの合計が正確に 100 になることを確認してください。
AESCipher: キー長が間違っています
AES は正確に 16、24、または 32 バイト(128、192、または 256 ビット)のキーが必要です。長さが正しくないキーを渡すと、基盤となる Java 暗号プロバイダーから例外がスローされます。
注釈が表示されません
注釈を追加したのにビューアに表示されない場合は、次を確認してください:
- 注釈矩形がページの
MediaBox内にあることを確認してください page.getAnnotations().add(annotation)はすべてのプロパティを設定した後に呼び出されました- 注釈を追加した後にドキュメントが保存されました