> Yes i found it here, but don't store the data. I write here what I've
The code you posted does not even compile:
> dpi.addPieceInfo(os, reader, appName, dataName, new PdfString("prova"));
That method does not accept an OutputStream.
The major conceptional error is, though, that you
a) use the same OutputStream for the PdfStamper as you used for the
PdfWriter without any re-initialization of that variable:
> writer = PdfWriter.getInstance(document, os);
> PdfStamper stamper = new PdfStamper(reader, os);
b) don't close the PdfStamper before checking the result.
Here a simple junit test case for the DocumentPieceInfo helper class:
public class TestDocumentPieceInfo
PdfName appName = new PdfName("MYAPP");
PdfName dataName = new PdfName("Hash");
String data = "Some test data.";
public void test() throws IOException, DocumentException
DocumentPieceInfo dpi = new DocumentPieceInfo();
InputStream resourceStream =
PdfReader reader = new PdfReader(resourceStream);
dpi.addPieceInfo(reader, appName, dataName, new
PdfStamper stamper = new PdfStamper(reader, new
if (resourceStream != null)
PdfReader reader = new
PdfObject myData = dpi.getPieceInfo(reader, appName, dataName);
As you see I load an existing PDF file. (I use a PDF from the project
resources, it could also have been any PDF from the file system.)
Then I add information using the class under test and then store the result
in the file system as "target/test-outputs/test-with-piece-info.pdf".
Then I load that newly written file and check for the data in question, and
hey, they are there!
View this message in context: http://itext-general.2136553.n4.nabble.com/Insert-custom-dictionary-in-pdf-file-tp4659026p4659031.html
Sent from the iText - General mailing list archive at Nabble.com.