How to display a date field from an XPage in a pdf created with iText -
After watching iText - I tried to create a PDF of a form in one of my XPs. The form is basically a 2 column table with different data fields - name, address etc. All text fields are fully displayed but do not have date fields. This is an example where I am trying to display the date of person (Person_dob) in cell 7 of my table.
var cell 7 = new com.itextpdf.text.pdf.PdfPCell (new com.itextpdf.text.Paragraph (currdoc.getItemValueString ("Person_dob")));
This table displays blank in the cell, the date field does not have a value; I have tried to change the code and used getItemValueString instead of getItemValueDate and getItemValue but before that the PDF crashes, there is no doubt that I am making some clarity but I can not see it. Use GetItemValueDate () to get the object as the date and convert it to the string in the local level format:
var date = currdoc.getItemValueDate (" Person_dob "); If (date! = Null) {var cell 7 = new com. Type. PDFPCL new. Com.text.pdf.text.Paragraph (date.toLocaleDateString ())); }
If you want more control over the date format, you can use it instead:
Var date = Currdoc.getItemValueDate ("Person_dob"); If (date! = Null) {var datePattern = New Java. Text. Simple format ("yyyy-MM-dd"); Var cell 7 = new com.itextpdf.text.pdf.PdfPCell (new com.itextpdf.text.Paragraph (datePattern.format (date))); }
Comments
Post a Comment