Hi,

I am facing an issue to append to a document. I have multiple pages that
hold both static and dynamic data at the end of the last page I need to
append filled W-4 form. The issue I am having is W-4 Form gets appended but
it does not retain the values basically a blank W-4 is appended. I even
tried to merge the document by reading filled W-4 document from the hard
drive but it never shows me the values. here is the code I have so:

ByteArrayOutputStream baosPDF1 = new ByteArrayOutputStream();
pdfwriter = PdfWriter.getInstance(document, new
FileOutputStream("C:/FinalFile.pdf"));
document.addCreationDate();
document.addProducer();
document.open();
document.newPage();
//the following method creates pages with static and dynamic data
getWelcomeNote(document);
                        
//here I am reading a W-4 template and populating the values
PdfReader reader1 = new PdfReader("C:\\fw4_2010.pdf"); 
ByteArrayOutputStream baosPDF = new ByteArrayOutputStream();
PdfStamper stamp = new PdfStamper(reader1, baosPDF,'\0',true); 
AcroFields form = stamp.getAcroFields();
form.setField("f1_09(0)", firstname);
form.setField("f1_10(0)", lastname);
form.setField("f1_14(0)", address);
stamp.setFormFlattening(false);
stamp.close();

//here I am trying to append W-4 to the document
PdfContentByte cb = docWriter.getDirectContent();
PdfReader reader = new PdfReader(baosPDF.toByteArray());
int pages = reader.getNumberOfPages();
int i = 0; 
PdfImportedPage page; 
while (i < pages) { 
                        i++; 
                       
document.setPageSize(reader.getPageSizeWithRotation(i)); 
                        document.newPage(); 

                        // get page from reader 
                        page = pdfwriter.getImportedPage(reader,i); 
                        int rotation = reader.getPageRotation(i); 

                        // think this for pages that aren't landscape 
                        // adds actual page to output 
                        if (rotation == 90 || rotation == 270) { 
                                cb.addTemplate( page,0,-1f,1f,
0,0,reader.getPageSizeWithRotation(i).height()); 
                        } else { 
                                cb.addTemplate(page, 1f, 0, 0,1f, 0, 0); 
                        } 
                        
                } 
                // creating a new reader automatically updates 
                reader = new PdfReader(baosPDF.toByteArray());

document.close();


but somehow it always append the blank W-4. For testing purpose I saved the
filled W-4 and then tried the following but it also does not show the filled
W-4 form rather a blank one is appended. 

mergePDF(document, pdfwriter, "C:/filled-w4.pdf");


As I am creating PDF's in which i have to merge the filled W-4 forms also
but no success so far. As I really don't want to create a W-4 from scratch
and would rather like to fill the W-4 template and generate a PDF and then
merge it with the document.

Any help is appreciated. 

Thanks



-- 
View this message in context: 
http://old.nabble.com/How-to-Append-a-PDF-to-a-document-Values-are-not-retained-tp27760209p27760209.html
Sent from the iText - General mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to