- Download the iText jar file from here.
- From 'Window' menu select 'Show Eclipse Views', 'Other', 'Package Explorer', to add the jar file to this folder of your database:
- Create a PDF file as a base template. I did this in Symphony as it saved the complication of adding lines and graphics programmatically. You then overlay text on this PDF to create each file.
- Call the following SSJS function to produce the PDF and attach it to a rich text field in a document:
//A. Load the java packages
importPackage(com.itextpdf);
importPackage(com.itextpdf.text);
importPackage(com.itextpdf.text.pdf);
importPackage(com.itextpdf.text.pdf.fonts);
importPackage(java.io);
//B. Initialize and get the PDF template (eg: from the Notes Data directory)
var theDirectory= session.getEnvironmentString("Directory",true);
var reader = new com.itextpdf.text.pdf.PdfReader (theDirectory + "/Template.pdf");
var fileOut = new java.io.FileOutputStream(filename);
var stamper = new com.itextpdf.text.pdf.PdfStamper(reader, fileOut);
var canvas = stamper.getOverContent(1);
//C. Embed the fonts you intend to use
var arial = new BaseFont.createFont("c:/windows/fonts/arial.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED);
var arialbd = new BaseFont.createFont("c:/windows/fonts/arialbd.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED);
var NORMAL = new Font(arial,10);
var BOLD = new Font(arialbd,10);
var BOLD11 = new Font(arialbd,11);
var BOLD12 = new Font(arialbd,12);
//D. Create and place your data eg:
var client = new Phrase(doc.getItemValueString("Client"),NORMAL);
ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, client, 65, 670, 0);
or
var lcost = new Phrase(@Text(doc.getItemValueDouble("Cost"),"C,"), BOLD11);
ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, lcost, 563, 533 - (i*44), 0);
Note that the coordinates are in points, starting from the bottom-left of the page. Zero rotation. 1" = 72 points = 25.4mm
//E. Close and Attach
stamper.close();
fileOut.close();
//attach the pdf
var rtitem:NotesRichTextItem= doc.createRichTextItem("Invoice");
rtitem.embedObject(NotesEmbeddedObject.EMBED_ATTACHMENT, "", filename, null);
For more detailed information this book can be purchased here:
I used your code and follow your instructions line by line. I am getting the following error :
ReplyDeleteUnexpected runtime error
The runtime has encountered an unexpected error.
Error source
Page Name:/myexport.xsp
Control Id: button2
Property: onclick
Exception
Error while executing JavaScript action expression
Script interpreter error, line=11, col=40: [ReferenceError] 'com' not found
11: var reader = new com.itextpdf.text.pdf.PdfReader(theDirectory + "/quote.pdf");
The following error information from Log :
ReplyDelete07/02/2012 11:49:55 PM HTTP JVM: com.ibm.xsp.webapp.FacesServlet$ExtendedServletException: javax.faces.FacesException: Error while executing JavaScript action expression
07/02/2012 11:49:55 PM HTTP JVM: CLFAD0134E: Exception processing XPage request. For more detailed information, please consult error-log-0.xml located in C:/Program Files/IBM/Lotus/Domino/data/domino/workspace/logs