The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

majiang (1) [Avatar] Offline
#1
Hi all ,
I changed the HelloWorldStampCopy.java code in chapter2 to insert 3 pages into file. but I found from the third page , the filed value become empty . I don't know the reason. anyone know reason? in the book section 2.3.1 ,it says "You can repeat this process as many times as you want:" , but looks like not.

the code like this

RandomAccessFileOrArray letter = new RandomAccessFileOrArray(
"results/in_action/chapter02/HelloLetter.pdf");
reader = new PdfReader(letter, null);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
stamper = new PdfStamper(reader, baos);
form = stamper.getAcroFields();
stamper.setFormFlattening(true);
stamper.close();

reader = new PdfReader(baos.toByteArray());
Document document = new Document(reader.getPageSizeWithRotation(1));
PdfCopy writer = new PdfCopy(document, new FileOutputStream(
"results/in_action/chapter02/tempateCopy.pdf"));
document.open();
//add first page
writer.addPage(writer.getImportedPage(reader, 1));
reader = new PdfReader(letter, null);
baos = new ByteArrayOutputStream();
stamper = new PdfStamper(reader, baos);
form = stamper.getAcroFields();
stamper.close();

reader = new PdfReader(baos.toByteArray());
//add third page
writer.addPage(writer.getImportedPage(reader, 1));
reader = new PdfReader(letter, null);
baos = new ByteArrayOutputStream();
stamper = new PdfStamper(reader, baos);
form = stamper.getAcroFields();
stamper.close();

reader = new PdfReader(baos.toByteArray());
// add third page
writer.addPage(writer.getImportedPage(reader, 1));