I don't know where you heard that the writer must also be
opened.
The sequence is:
Document document = new Document(PageSize.A4, 20, 20, 20,
20);
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(_pdfFileName));
document.open();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(_pdfFileName));
document.open();
Best Regards,
Paulo Soares
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of NICOLAU Raffaele
Sent: Wednesday, March 31, 2004 12:45 PM
To: Sherlock Simon; [EMAIL PROTECTED]
Subject: RE: [iText-questions] setFontAndSize(...) supposed problem ..Actually the line concerned is the one with document.add(_header), and the PdfPtable is instanciated within the getHeader(..) method _returnValue = new PdfPTable(p_objHeader.size());Sorry if it was not clear enough,Thanks again,Regards,R.Nicolau-----Message d'origine-----
De : Sherlock Simon [mailto:[EMAIL PROTECTED]
Envoy� : mercredi 31 mars 2004 12:34
� : NICOLAU Raffaele; [EMAIL PROTECTED]
Objet : RE: [iText-questions] setFontAndSize(...) supposed problem ..I can't see where you instantiate myTable[Sherlock Simon] . If you debug your code I think you'll find that it's your null.-----Original Message-----
From: NICOLAU Raffaele [mailto:[EMAIL PROTECTED]
Sent: 31 March 2004 10:51
To: [EMAIL PROTECTED]
Subject: [iText-questions] setFontAndSize(...) supposed problem ..Hello iText users,I have some kind of problem concerning a Document, in which I try to add a PdfPTable. The PdfPTable is generated quite normally, but when I do thedocument.add(myTable), i have the following stack trace :DocumentException: java.lang.NullPointerException
at com.lowagie.text.pdf.PdfContentByte.setFontAndSize(Unknown Source)
at com.lowagie.text.pdf.PdfDocument.writeLineToContent(Unknown Source)
at com.lowagie.text.pdf.ColumnText.go(Unknown Source)
at com.lowagie.text.pdf.ColumnText.go(Unknown Source)
at com.lowagie.text.pdf.PdfPRow.writeCells(Unknown Source)
at com.lowagie.text.pdf.PdfPTable.writeSelectedRows(Unknown Source)
at com.lowagie.text.pdf.PdfPTable.writeSelectedRows(Unknown Source)
at com.lowagie.text.pdf.PdfPRow.writeCells(Unknown Source)
at com.lowagie.text.pdf.PdfPTable.writeSelectedRows(Unknown Source)
at com.lowagie.text.pdf.PdfPTable.writeSelectedRows(Unknown Source)
at com.lowagie.text.pdf.PdfDocument.addPTable(Unknown Source)
at com.lowagie.text.pdf.PdfDocument.add(Unknown Source)
at com.lowagie.text.Document.add(Unknown Source)
at com.influe.asp.render.RenderDocumentPdf.render(RenderDocumentPdf.java:148)
at com.influe.asp.render.Main.main(Main.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.intellij.rt.execution.application.AppMain.main(Unknown Source)Here is the portion of code involved .... :public String render(Locale p_locale,
String p_fileName) throws Exception
{
String _returnValue = null;// Classe pour la param�tres
RenderParameters _params = RenderParameters.getInstance();// Chemin du fichier pdf.
String _pdfFileName = null;// 1- Set d'objets Lowagie
PdfContentByte pcb;
PdfTemplate pt;
BaseFont bf = null;Document document = new Document(PageSize.A4, 20, 20, 20, 20);// 2- On ouvre le document
document.open();try
{
// 3- On r�cup�re l'objet ici.
// Faire les appels aux proxy pour chaque truc (sais pas trop comment faire encore) => non non non
// donn�es r�cup�r�es dans l'application utilisant ce module.if (p_fileName == null)
{
throw new RuntimeException("!!");
}_pdfFileName = File.createTempFile(p_fileName, ".pdf", new File(_params.getSharedDirectory())).getAbsolutePath();
}
catch(Exception _ex)
{
throw _ex;
}// 4- On set les propri�t� du document
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(_pdfFileName));try
{
// NOUVEAUTE � partir de la version 1.0, on dois ouvrir le writer !!!
writer.open();
pcb = writer.getDirectContent();
pt = pcb.createTemplate(25, 25);bf = BaseFont.createFont(_params.getArialUnicodeTTF(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);// On set la font et la taille
if (bf == null)
{
throw new RuntimeException("BaseFont problem, exiting.");
}PdfPTable _space = createSpace(new Font(bf, 9));// On cr�e la classe avec les evenements ???!!!
// RenderPdfEvent _events = new RenderPdfEvent(bf, pcb, pt);
// writer.setPageEvent(_events);// On forme le header ...
PdfPTable _header = getHeader(header, p_locale);
if (_header != null)
{
document.add(_header);
}...}and the getHeader() method ..private PdfPTable getHeader(
ArrayList p_objHeader,
Locale p_locale) throws Exception
{
// On cr�e un nouveau tableau avec autant de colonnes que d'�l�ments dans la liste des �l�ments de l'entete
PdfPTable _returnValue = null;try
{
if (p_objHeader.size() > 0)
{
_returnValue = new PdfPTable(p_objHeader.size());// largeur des diff�rentes colonnes ...
int _largeur = (100 / p_objHeader.size());
int[] _taille = new int[p_objHeader.size()];for (int _i = 0; _i < p_objHeader.size(); _i++)
{
_taille[_i] = _largeur;
}_returnValue.setWidths(_taille);
_returnValue.setWidthPercentage(100);for (Iterator _it = p_objHeader.iterator(); _it.hasNext(); )
{
RenderObjectI _element = (RenderObjectI)_it.next();
/* The PdfPTable here seems to be really wlel formed, in debugging i saw that it contained only one row with the data a specified before, so for me, the PDfPTable is really what I wanted it to be */Object _obj = _element.render(RenderDocumentI.RENDER_MODE_PDF, p_locale);if (_obj instanceof PdfPCell)
{
_returnValue.addCell((PdfPCell)_obj);
}if (_obj instanceof PdfPTable)
{
_returnValue.addCell((PdfPTable)_obj);
}
}
}
}
catch (Exception _ex)
{
log.error(_ex, _ex);
}return _returnValue;
}Thanks again !Regards,R.Nicolau
************************************************************************************
Internet email is not to be treated as a secure means of communication.
PITO monitors all internet email activity and content.
This communication is intended for the addressee(s) only.
Please notify the sender if received in error. Unauthorised use or
disclosure of the content may be unlawful. Opinions expressed in this
document may not be official policy.
Thank you for your co-operation.
************************************************************************************
