Reputation: 1174
I've a requirement where user are going to fill lots of fields ( text field, check box, radio button ) on pdf form and they will mail us. I need to read each fields on pdf form and insert into oracle table.
Edit1: I'm trying following code, It generates pdf but when I double click it says "invalid format". What's wrong ?
import java.io.FileOutputStream;
import java.io.IOException;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.PdfWriter;
public class pdfGentest{
public static void main(String[] args) {
Document document = new Document();
try {
PdfWriter.getInstance(document, new FileOutputStream("c:\\HelloWorld.pdf"));
document.open();
document.add(new Paragraph("Hello World"));
}
catch (DocumentException de) {
System.err.println(de.getMessage());
} catch (IOException ioe) {
System.err.println(ioe.getMessage());
}
}
}
Fixed: Due to I've not closed the document..Adding document.close(); fixed the problem
Upvotes: 4
Views: 10397
Reputation: 119
You can use PDF Box api, which will support to extract the fields information more clearly.
Upvotes: 3
Reputation: 1134
You can use IText library to do that. Link =>http://itextpdf.com/
Sadly I don't have java code example for that as I am using iTextSharp library for C#.NET buts pretty straightforward.
You might want to check itextpdf.com/book/examples.php for examples. Also check the following link for some example on reading field values, http://itext-general.2136553.n4.nabble.com/Problem-Reading-Interactive-Form-Values-Acro-Fields-from-PDF-using-iText-td2171900.html
Upvotes: 3