Hi, 

I've successfully filled AcroForm fields in a template I created with a 
stand-alone application and now I'm trying to do the same via a web application 
(using Spring). 
According to the output messages I get, the template is successfully accessed, 
the code can check the presence of AcroForm fields in the PDF but using the 
same code as in the stand-alone application, I get as output the template (same 
size and all) but the fields are not filled, and I have no idea why it is not 
working?

I'm due to give this part of the project back in a couple of hours and I'm 
struggling since quite some time now. Can someone know what's wrong?

In the book (iText in Action), the examples with servlet do not contain the use 
of templates to generate the PDF.

Here is the code I'm using:

    private static void fillForm(String filename, CustomerData data, 
OutputStream out) throws IOException, DocumentException, ParseException {
        PdfReader reader = new PdfReader(filename);
        PdfStamper stamper = new PdfStamper(reader, out);
        Date date = new Date();
        
        AcroFields form = stamper.getAcroFields();
        form.setField("date", FORMATTER.format(date));
        form.setField("companyAddress", data.getCustomerName());
        form.setField("customer", data.getCustomer());
        stamper.setFormFlattening(data.isFlatten());
        stamper.close();
    }

I even tried this

    public static String test(String templateSource, String pdfView, 
ITextRaupeDealer raupeDealer) throws IOException, DocumentException, 
ParseException {
        String outputPDFTemp = tempFolder + File.pathSeparator + pdfView + "_" 
+ raupeDealer.getCustomer().getId() + ".pdf";
        PdfReader reader = new PdfReader(templateSource);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfStamper stamper = new PdfStamper(reader, baos);
        AcroFields form = stamper.getAcroFields();
        Date date = new Date();
        
        Set<String> keys = form.getFields().keySet();
        
        for (String string : keys) {
            System.out.println("Key found: " + string);
        }
                
        form.setField("date", FORMATTER.format(date));
        form.setField("companyAddress", "Test");
        stamper.setFormFlattening(true);
        stamper.close();
        return outputPDFTemp;
    }

But to no avail.

Thanks.

Daniel W.

_________________________________________________________________
News, entertainment and everything you care about at Live.com. Get it now!
http://www.live.com/getstarted.aspx
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php

Reply via email to