I tried these lines to import the original PDF file to the PdfWriter.
 

public static void main(String[] args) {

try {

PdfReader pdf_file = new PdfReader("Demo1.pdf");

Document document = new Document();

FileOutputStream file_result = new FileOutputStream("result.pdf");

PdfWriter writer = PdfWriter.getInstance(document, file_result);

document.open();

document.newPage();

writer.open();

PdfImportedPage import_page = writer.getImportedPage(pdf_file, 1);

//document.close();

//writer.close();

}

catch(Exception e) {

e.printStackTrace();

}

But seems that I cannot close both the 'writer' and the 'document'. It is always trapped to this exception if I do close the writer or document or both
 
ExceptionConverter: java.io.IOException: The document has no pages.
 at com.lowagie.text.pdf.PdfPages.writePageTree(Unknown Source)
 at com.lowagie.text.pdf.PdfWriter.close(Unknown Source)
 at com.lowagie.text.pdf.PdfDocument.close(Unknown Source)
 at com.lowagie.text.Document.close(Unknown Source)
 at InsertFields.main(InsertFields.java:61)
 

I'm sorry bout this, actually I'm really new in Java Programming.
Any suggestion will be good for me.
 
Thanks.
Nicholas Sutanto
 
----- Original Message -----
Sent: Friday, June 25, 2004 4:59 AM
Subject: RE: [iText-questions] Inserting Field in existing PDF file

You must use PdfWriter to import the original page and then place the fields.
There's no way to place the fields directly in an existing document in the same way as it is done in PdfStamper for annotations.
 
Best Regards,
Paulo Soares


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Nicholas Sutanto
Sent: Friday, June 25, 2004 9:15 PM
To: [EMAIL PROTECTED]
Subject: [iText-questions] Inserting Field in existing PDF file

 Hi,

I'm trying to make a new field.
What I'm doing right now is I make a new document and insert the field to the new document.
So let say I have input.pdf file which contains the original file and result.pdf which contain only the new fields. So how do I concantenate them? Is it the right way to insert the field?

Below are sample of my code.
     Document document = new Document();
      FileOutputStream file_result = new FileOutputStream("result.pdf");  
      PdfWriter writer = PdfWriter.getInstance(document, file_result);
      document.open();
      TextField field1 = new TextField(writer, new Rectangle(50, 760, 50 + 100, 760+50), "Value1");     
      PdfFormField fieldt1 = field1.getTextField();
      writer.addAnnotation(fieldt1);
      document.close();
      writer.close();
     

Then what should I do next? Is this the right step?

Thanks.
Nicholas.

Reply via email to