From past couple of days I'm working on a prototype project in which pdf form fields should be accessed using Domino Java.
There are couple of tasks involved in this project ,
* Designing user interface in pdf and
* Reading fields data using Java
I have struggle a lot to accomplish these tasks so I thought to blog it for my other fellow LN developers.Designing user interface in pdf
To design user interface in pdf , You may choose any of these following options,1- Using iText Java API: IText for Java API provides handful of methods to design user interface in pdf.It's like a old Java AWT methods where you need to calculate coordinates to place your objects.It's not very precise and takes lots of time to design simple interface.Don't go with it if you want to design complex form.
2- Adobe LiveCycle Designer: I've tried with trial version of this tool and found it allows you to design user interface and save it.But,You can't edit it in Adobe reader. For that, You must "Distribute" the form after saving.Distribution option is disabled in trial version and this option remain disabled if you are using stand alone version of this tool ( which I got from net).Adobe LiveCycle designer is integrated with Adobe Acrobat Pro.
3- Adobe InDesign: This can be used to design acro pages but you must use Adobe Acrobat Pro to convert designed page into Acrobat form.You can refer following link to design form in InDesign,
InDesign CS3, In Good Form
4- Adobe Acrobat Pro: I'm using this and it fits perfectly to my need. Here is my sample form designed using Adobe Pro where information can be added and saved.,Reading fields data using Java
To accomplish this,I've used iText for Java API which seems only way to communicate easily with pdf objects.
Since I'm not using iText to design pdf interface so accessing existing pdf using iText is pretty straight forward.
As this project goes, I will write more about it.
September 13, 2010 at 2:18 AM
You also could have a look at Apache pdfbox for accessing all the PDF stuff in Java including the XML that represent the meta-data.
September 13, 2010 at 2:57 AM
Thanks Stephan , I will have a look.
September 13, 2010 at 2:58 AM
Just one small point: you have a nested try... catch block. You can lose that :-)
September 13, 2010 at 3:02 AM
Thanks Ben. One for NotesSession and other for iText.If I remove any of them they throw an error.
September 13, 2010 at 5:41 AM
Agree strongly on your itext choice.
I've allways designed my Lotus Agents that way that the agent itself was quite small and only for Domino related stuff.
I put IText-code, JDBC-code, Business logic, jakarta-commons-webclient code, etc in its own classes. So it is much easier to write junit integration tests for them.
Even case you don't like junit, a class like this:
class PdfService {
public static void main (String[] args ) {
PdfService pdfService = new PdfService();
pdfService.printFields("C:/My Documents/SampleForm.pdf");
}
void printFields (String filePath) {
PdfReader reader = new PdfReader(filePath);
AcroFields form = reader.getAcroFields();
HashMap fields = (HashMap) form.getFields();
String key;
for (Iterator i = fields.keySet().iterator(); i.hasNext(); ) {
key = (String) i.next();
System.out.println(form.getField(key));
}
}
catch (IOException ioe) {
System.err.println(ioe.getMessage());
}
} catch(Exception e) {
e.printStackTrace();
}
}
Can be run directly in Eclipse AND from a notes agent.
regards
Axel
September 13, 2010 at 7:08 PM
@Axel,
Useful indeed.However, Notes agent must use NotesMain() as a start up method ?
September 14, 2010 at 3:21 AM
@Rishi: Yes, you can use the PdfService class from the NotesClass.
NotesMain() {
PdfService pdfService = new PdfService();
pdfService.printFields(yourFilePath);
}
The idea is just separate the "subsystems" like the one that does PDF-stuff from the notes agent. I've found that such separation allways brought gains in better testability and maintainability.
September 14, 2010 at 3:51 AM
@Axel,
Correct..Putting business logic in separate classes and using them in main class is really neat way to code.I'm following this methodology.
October 18, 2010 at 5:51 AM
Hi All,
I'm new to Lotus notes. I have to pull data from Lotus Notes documents and also some data from Oracle and need to create PDF file by combining the data. Please suggest me some best appraoch to do that...
Thank you
October 18, 2010 at 6:58 AM
Suneela,
You should look at iText for Java API. It provides plenty of methods to read and write pdf document.
Rishi