wmhfitz wrote:
> Here's my class...
>
> public class FillEnabledForm {
>
> public static final String ENABLED_FORM = "CAI_0708.pdf";
> public static final String RESULT = "ENABLED_CAI.07.10.08.pdf";
> static String readPdf =
> "C:\\TRMWorkspace\\ClearView\\WebContent\\WEB-INF\\resources\\forms\\CAI0708.pdf";
>
> public static void main(String[] args) {
>
> Document document = new Document();
> ByteArrayOutputStream bos = new ByteArrayOutputStream();
>
> try {
This is step A in the document stamping process:
> PdfReader reader = new PdfReader(readPdf);
> System.out.println("Pdf Version:
> "+reader.getPdfVersion());
> System.out.println("Num of Pages: "+
> reader.getNumberOfPages());
> System.out.println("File Length:
> "+reader.getFileLength());
> System.out.println("Encrypted: "+reader.isEncrypted());
Why do you need the following line? Are you going to create a new
document from scratch? This is step 1 in the document creation process.
> document = new Document();
No, you are going to stamp an existing document. This is step B in the
document stamping process:
> PdfStamper stamper = new PdfStamper(reader, bos);
This is step 2 in the document creation process. It is commented out.
> // PdfWriter writer = PdfWriter.getInstance(document, bos);
This is step 3 in the document creation process. It's absurd.
> document.open();
You are manipulating a form. This is step C in the document stamping
process:
> AcroFields form = stamper.getAcroFields();
> form.setField("fullName", "Blackie Lawless");
> form.setField("representativeName", "Rob Halford");
This is step 5 in the document creation process.
> document.close();
It throws an error because you omitted step 4!!
This is step D in the document stamping process.
> stamper.close();
>
> } catch (IOException e) {
> e.printStackTrace();
> } catch (DocumentException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> }
> }
The answer to your question is clear.
Either you create a document from scratch using steps 1, 2, 3, 4 and 5.
Or you manipulate an existing document using steps A, B, C and D.
You mixed both. That doesn't make sense.
--
This answer is provided by 1T3XT BVBA
http://www.1t3xt.com/ - http://www.1t3xt.info
------------------------------------------------------------------------------
_______________________________________________
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