Created
March 19, 2013 06:02
-
-
Save thara/5194013 to your computer and use it in GitHub Desktop.
iTextを使用した、既存PDFに対する編集
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// PdfStamperのコンストラクタに渡したOutputStreamは、PdfStamper#close内でcloseメソッドが呼ばれてしまうため、 | |
// 一時領域としてByteArrayOutputStreamを渡し、編集結果のバイト文字列を引数のOutputStreamに書き込む。 | |
ByteArrayOutputStream tempOut = new ByteArrayOutputStream(); | |
PdfStamper stamp; | |
try { | |
stamp = new PdfStamper(original, tempOut); | |
} catch (IOException e) { | |
throw new DocumentException(e); | |
} | |
int pageSize = original.getNumberOfPages(); | |
for (int importPageNo = 1; importPageNo <= pageSize; importPageNo++) { | |
PdfContentByte underContent = stamp.getUnderContent(importPageNo); | |
edit(underContent); | |
} | |
try { | |
stamp.close(); | |
out.write(tempOut.toByteArray()); | |
} catch (IOException e) { | |
throw new DocumentException(e); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment