PDF export issue

32 views
Skip to first unread message

acimasiz

unread,
May 15, 2008, 1:33:13 PM5/15/08
to JMesa
I have downloaded and successfully configured most recent version of
Jmesa. I am trying to get the PDF export working but the generated
files for some reason can not be read by pdf viewers. I was able to
get the other export types correctly working. There does not seem to
be any exceptions in the log files. the file just can not be read.

I searched the forums and found out this type of an errors was
previously reported. I however could not find a post if it has been
fixed or not.

Do we have a solution to get this working?

thanks

Jeff Johnston

unread,
May 15, 2008, 3:04:10 PM5/15/08
to jm...@googlegroups.com
Were your exports working on a previous release and only now failing to work? If so, what release were you using before?

There have been problems reported for the PDF exports just lately so I'm not sure if we just started having problems, or if more developers with similar environments are having the same problem.

-Jeff Johnston

acimasiz

unread,
May 15, 2008, 3:52:55 PM5/15/08
to JMesa
Thanks for your reply.

I have the version 2.3.1. I was not on a previous release. I was able
to get some of the pdf's working with this version but it is not
consistent. It just seems to fail for some reason for some cases. The
data I have on the tables at the moment for testing purposes does
consist of very basic text. As I mentioned earlier, there does not
seem to be any error messages in the logs. I compared the xhtmls of
working examples to non-working examples and came up empty. I ran the
generated xhtml results through tidy and found out that it was missing
few attributes and tags here and there like the the title tag. I ended
up changing/adding those for test purposes to get a valid xhml
document. Once I had the valid xhtml, I tried generating PDFs again
but It did not work. There were still no exceptions logged.

Thanks again!

On May 15, 3:04 pm, "Jeff Johnston" <extremecompone...@gmail.com>
wrote:
> Were your exports working on a previous release and only now failing to
> work? If so, what release were you using before?
>
> There have been problems reported for the PDF exports just lately so I'm not
> sure if we just started having problems, or if more developers with similar
> environments are having the same problem.
>
> -Jeff Johnston
>

Jeff Johnston

unread,
May 15, 2008, 4:06:12 PM5/15/08
to jm...@googlegroups.com
What a great detailed post!

I have a feeling it is the process of converting html to pdf (using flying saucer) than the actual iText library that is causing problems.

I do not have the time right now to create a view using straight iText, but I bet someone that knows iText could write that fairly quickly. The views are plugable in JMesa and developers that helped me create the current export views thought it was a simple process. I'm not neccessarily directing this at you, but just including that in this thread in case a JMesa developer would be willing to create that view.

-Jeff Johnston

acimasiz

unread,
May 22, 2008, 11:58:34 AM5/22/08
to JMesa
Thanks again for your reply.

I see that views are plug-gable in Jmesa through TableFacade object. I
mean I guess I can use it to set a view or overwrite a view. However,
I see that the render method is always getting PdfViewExporter object
and calling the export method on it. This is the object that seems to
be using the ItextRenderer which seems to be causing the problem as
described on the above posts. Is it possible for me to supply my on
Exporter so that I can use Itext instead of ItextRenderer. I was able
to do this without using the TableFacade object but I just wanted to
confirm.

Thanks for your time!

On May 15, 4:06 pm, "Jeff Johnston" <extremecompone...@gmail.com>
wrote:
> What a great detailed post!
>
> I have a feeling it is the process of converting html to pdf (using flying
> saucer) than the actual iText library that is causing problems.
>
> I do not have the time right now to create a view using straight iText, but
> I bet someone that knows iText could write that fairly quickly. The views
> are plugable in JMesa and developers that helped me create the current
> export views thought it was a simple process. I'm not neccessarily directing
> this at you, but just including that in this thread in case a JMesa
> developer would be willing to create that view.
>
> -Jeff Johnston
>

Jeff Johnston

unread,
May 22, 2008, 12:46:45 PM5/22/08
to jm...@googlegroups.com

Being able to plug in custom exporters is an improvement that I need to make to the TableFacade. For now I think you could just extend the TableFacadeImpl class and override the render() and getView() methods. There is not much to those methods so you could even just copy the code in there for now.

Are you thinking of writing a new PDF view and Exporter? Is that something you would be willing to donate to the project? If so I could start working on the improment to the TableFacade. I have been putting off doing it just because so far the developers have been using just the stock views and exporters.

-Jeff Johnston

acimasiz

unread,
May 23, 2008, 10:14:36 AM5/23/08
to JMesa
I actually ended up writing something very basic to get this going. I
looked into using HTMLWorker class in iText to parse the xhtml
returned by the original PdfView object. Even though HTMLWorker was
able to parse the generated xhtml successfully, iText libraries
provided StyleSheet object is not sophisticated enough to parse and
apply some of the css defined in the pdf style sheet. The StyleSheet
object seems to be a very basic representation of CSS and requires you
to supply things by tags or by names and with map properties. Since I
was running out of time Instead of using HTMLWroker, and the
StyleSheet object, I ended up using PdfPTable object. I basically
ended up creating a new PdfView object and overwrote the render method
to build the PdfPTable object and have it return it to the
PdfViewExporter class. Since there is no style sheets or CSS parsing
capablitiy, I ended up decorating the table while it was being built
with PdfPTable object. I ended up using Color object to set RGB colors
on cells and other iText objects. The fonts are also set in there. As
you can see this is not pretty at all. However, since the table
decoration was/is very simple, it worked out for me. I'd be happy to
share it to you if you think it is worth it.

I was able to get the same look and feel. I also realized this works a
lot faster than iTextRenderer.

On May 22, 12:46 pm, "Jeff Johnston" <extremecompone...@gmail.com>
wrote:
> Being able to plug in custom exporters is an improvement that I need to make
> to the TableFacade. For now I think you could just extend the
> TableFacadeImpl class and override the render() and getView() methods. There
> is not much to those methods so you could even just copy the code in there
> for now.
>
> Are you thinking of writing a new PDF view and Exporter? Is that something
> you would be willing to donate to the project? If so I could start working
> on the improment to the TableFacade. I have been putting off doing it just
> because so far the developers have been using just the stock views and
> exporters.
>
> -Jeff Johnston
>

Jeff Johnston

unread,
May 23, 2008, 3:11:07 PM5/23/08
to jm...@googlegroups.com

I would be interested in seeing what you did. If nothing else I could put it on the wiki as an example of how to customize various things in JMesa. If you want you can either post your code here, or send it to me at extremec...@gmail.com.

I also would be interested in hearing about how difficult it was to figure out how to modify what you did. You know, things that could be documented better, etc...

-Jeff Johnston

acimasiz

unread,
May 23, 2008, 6:15:05 PM5/23/08
to JMesa
Sure no problem . I will go ahead and try to explain with examples
what I did and how I did it.

I basically ended up writing two objects namely ItextPdfView and
ItextPdfViewExporter. In ItextPdfView object I ended up creating two
methods namely getTableCaption that returns a Paragraph object and
render method that returns a PdfPTable object. Here is how they look.

public Paragraph getTableCaption() throws Exception {
Paragraph p = new Paragraph(this.table.getCaption(),
FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLDITALIC,
this.captionFontColor));
p.setAlignment(this.captionAlignment);
return p;
}

public PdfPTable render() {

PdfPTable table = new
PdfPTable(this.table.getRow().getColumns().size());

HtmlRow row = this.table.getRow();
List<Column> columns = row.getColumns();

// build table headers
for (Iterator<Column> iter = columns.iterator();
iter.hasNext();) {
HtmlColumn column = (HtmlColumn) iter.next();
PdfPCell cell = new PdfPCell(new
Paragraph(column.getTitle(),
FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL,
this.headerFontColor)));
cell.setPadding(3.0f);
cell.setBackgroundColor(this.headerBackgroundColor);
table.addCell(cell);
}

// build table body
Collection<?> items = coreContext.getPageItems();
int rowcount = 0;
for (Object item : items) {
rowcount++;

row = this.table.getRow();
columns = row.getColumns();

for (Iterator<Column> iter = columns.iterator();
iter.hasNext();) {
HtmlColumn column = (HtmlColumn) iter.next();

String property = column.getProperty();
Object value =
column.getCellRenderer().getCellEditor().getValue(item, property,
rowcount);
PdfPCell cell = new PdfPCell(new
Paragraph(value.toString(), FontFactory.getFont(FontFactory.HELVETICA,
12, Font.NORMAL)));
cell.setPadding(3.0f);
if ((rowcount % 2) == 0) {
// even color

cell.setBackgroundColor(this.evenCellBackgroundColor);
}
else {
// odd color

cell.setBackgroundColor(this.oddCellBackgroundColor);
}
table.addCell(cell);
}
}

// add results to the table
PdfPCell cell = new PdfPCell(new
Paragraph(snippets.statusBarText(),
FontFactory.getFont(FontFactory.HELVETICA, 12, Font.ITALIC)));
table.addCell(cell);
table.setSpacingBefore(5.0f);

return table;
}

In the getTableCaption function I just use the Jmesa table object to
get the caption, decorate it with some fonts and stick it into the
Paragraph object.

In the render method, I basically ended up using Jmesa objects to get
headers, body and the status bar information. Once I had the
information, I created PdfPCell objects and added the cell objects to
the PdfPTable object. During this process, as you can see above, the
cells were decorated with color, font, etc.

Once I had the PdfPTable object build, the ItextPdfViewExporter
basically did the following in the export method.

com.lowagie.text.Document document = new
com.lowagie.text.Document();
ByteArrayOutputStream baos = new ByteArrayOutputStream();

PdfWriter.getInstance(document, baos);
document.open();
document.add(((PdfView) view).getTableCaption());
document.add(((PdfView) view).render());
document.close();

this.responseHeaders(baos.toByteArray(), response);
ServletOutputStream out = response.getOutputStream();
baos.writeTo(out);
out.flush();

I obviously ended up calling the export method myself instead of using
the render method in TableFacade object. I did not think I needed to
overwrite TableFacadeImp.

Hope this helps!

On May 23, 3:11 pm, "Jeff Johnston" <extremecompone...@gmail.com>
wrote:
> I would be interested in seeing what you did. If nothing else I could put it
> on the wiki as an example of how to customize various things in JMesa. If
> you want you can either post your code here, or send it to me at *
> extremecompone...@gmail.com.*
>
> I also would be interested in hearing about how difficult it was to figure
> out how to modify what you did. You know, things that could be documented
> better, etc...
>
> -Jeff Johnston
>

acimasiz

unread,
May 23, 2008, 6:22:56 PM5/23/08
to JMesa
I attached a generated pdf file incase you are wondering how it
looks.

http://jmesa.googlegroups.com/web/groups.pdf?gsc=mJySqRYAAACaX4KLEJVcQ7OxefbIzcaTb4sM5LxQecB2XX9dOcthjQ
> ...
>
> read more »

Jeff Johnston

unread,
May 27, 2008, 2:25:42 PM5/27/08
to JMesa
Thank you for the example!

On May 23, 5:22 pm, acimasiz <ismail.se...@gmail.com> wrote:
> I attached a generated pdf file incase you are wondering how it
> looks.
>
> http://jmesa.googlegroups.com/web/groups.pdf?gsc=mJySqRYAAACaX4KLEJVc...
> ...
>
> read more »

Vidhya

unread,
Jul 21, 2008, 8:40:23 AM7/21/08
to JMesa
Hi,
Can you provide the source code of what you have done above?
I would like to try it as I am having some pdf export issues too.

Vidhya


On May 27, 2:25 pm, Jeff Johnston <extremecompone...@gmail.com> wrote:
> Thank you for the example!
>
> On May 23, 5:22 pm, acimasiz <ismail.se...@gmail.com> wrote:
>
>
>
> > I attached a generatedpdffile incase you are wondering how it
> > > > > apply some of the css defined in thepdfstyle sheet. The StyleSheet
> > > > > > Are you thinking of writing a newPDFview and Exporter? Is that
> ...
>
> read more »- Hide quoted text -
>
> - Show quoted text -

Jeff Johnston

unread,
Jul 21, 2008, 9:37:16 AM7/21/08
to JMesa

I completely forgot about this post! I remember I was going to write
up an issue ticket for it and then it slipped my mind and I forgot
about it completely.

The file is located here:
http://jmesa.googlegroups.com/web/groups.pdf?gsc=mJySqRYAAACaX4KLEJVcQ7OxefbIzcaTb4sM5LxQecB2XX9dOcthjQ

This is something that needs to be looked into for sure. I wrote up
an issue ticket for this now too:

http://code.google.com/p/jmesa/issues/detail?id=120

-Jeff Johnston
> ...
>
> read more »

Jeff Johnston

unread,
Jul 21, 2008, 9:50:42 AM7/21/08
to JMesa
I see the code is actually just within this post itself. That link I sent is just the link to the screenshot.

Do you want to try and implement this? If so take a look at the existing CSV and Excel view to  see how to create a custom export view. I can jump in and help as well....just not at work as we have some timelines to make right now.

-Jeff Johnston

Jeff Johnston

unread,
Jul 21, 2008, 9:56:31 AM7/21/08
to JMesa

Here is a link to the iText documentation on creating tables:

http://itextdocs.lowagie.com/tutorial/objects/tables/pdfptable/index.php

There is also a chapter in their In Action book dedicated to tables.

-Jeff Johnston



On Jul 21, 8:37 am, Jeff Johnston <extremecompone...@gmail.com> wrote:
> I completely forgot about this post! I remember I was going to write
> up an issue ticket for it and then it slipped my mind and I forgot
> about it completely.
>
> The file is located here:http://jmesa.googlegroups.com/web/groups.pdf?gsc=mJySqRYAAACaX4KLEJVc...
> ...
>
> read more »

acimasiz

unread,
Jul 21, 2008, 11:10:49 AM7/21/08
to JMesa

acimasiz

unread,
Jul 21, 2008, 11:12:50 AM7/21/08
to JMesa

Jeff Johnston

unread,
Jul 21, 2008, 11:43:23 AM7/21/08
to jm...@googlegroups.com

Thank you...again :). Sorry about forgetting about this post. It just completely slipped my mind....

I am going to take these two files and make them closer to a JMesa type view with their own renderers and editors. It will be roughly the same code though, but just organized into different classes.

Vidhya, you should be able to use this as is right now though. I still do need to make the TableFacadeImpl more flexible for putting in custom export renderers but if you look at the TableFacadeImpl.render() method you should be able to see how you can just call these java classes directly for now (instead of calling tableFacade.render()).

Acimasiz, would you have time to post an example of how you use this view?

-Jeff Johnston

Ismail Seyfi

unread,
Jul 21, 2008, 1:46:53 PM7/21/08
to jm...@googlegroups.com
Sure no problem. 

Once you have these classes all you have to do is figure out when the export is happening. I used TableFacade object and its Limit object. Here is how it looks 

TableFacade tableFacade = TableFacadeFactory.createTableFacade(this.getTableId(), this.getHttpServletRequest());

tableFacade.setItems((Collection) data);


if (tableFacade.getLimit().isExported() && tableFacade.getLimit().getExportType().compareTo(ExportType.PDF) == 0) {

                PdfView pdfView = new PdfView((HtmlTable) tableFacade.getTable(), tableFacade.getToolbar(), tableFacade.getWebContext(), tableFacade.getCoreContext());

                PdfViewExporter exporter = new PdfViewExporter(pdfView, this.getHttpServletRequest(), this.getHttpServletResponse());

                exporter.export();

            }


Good luck!

Jeff Johnston

unread,
Jul 23, 2008, 9:20:49 PM7/23/08
to JMesa

I have this new pdf view implemented now! It will go out with the next
release. It is really, really fast compared to the existing pdf view.

I think the next release will go out next month....

Acimasiz, I hope you don't mind but I put your name on the files as
you did all the work :)

http://code.google.com/p/jmesa/source/browse/trunk/jmesa/src/org/jmesa/view/pdfp/PdfPView.java

-Jeff Johnston


On Jul 21, 12:46 pm, "Ismail Seyfi" <ismail.se...@gmail.com> wrote:
> Sure no problem.
> Once you have these classes all you have to do is figure out when the export
> is happening. I used TableFacade object and its Limit object. Here is how it
> looks
>
> TableFacade tableFacade =
> TableFacadeFactory.createTableFacade(this.getTableId(),
> this.getHttpServletRequest());
>
> tableFacade.setItems((Collection) data);
>
> if (tableFacade.getLimit().isExported() &&
> tableFacade.getLimit().getExportType().compareTo(ExportType.PDF) == 0) {
>
>                 PdfView pdfView = new PdfView((HtmlTable)
> tableFacade.getTable(), tableFacade.getToolbar(),
> tableFacade.getWebContext(), tableFacade.getCoreContext());
>
>                 PdfViewExporter exporter = new
> PdfViewExporter(pdfView, this.getHttpServletRequest(),
> this.getHttpServletResponse());
>
>                 exporter.export();
>
>             }
>
> Good luck!
>
> On Mon, Jul 21, 2008 at 11:43 AM, Jeff Johnston <extremecompone...@gmail.com>
> wrote:
>
>
>
> > Thank you...again :). Sorry about forgetting about this post. It just
> > completely slipped my mind....
>
> > I am going to take these two files and make them closer to a JMesa type
> > view with their own renderers and editors. It will be roughly the same code
> > though, but just organized into different classes.
>
> > Vidhya, you should be able to use this as is right now though. I still do
> > need to make the TableFacadeImpl more flexible for putting in custom export
> > renderers but if you look at the TableFacadeImpl.render() method you should
> > be able to see how you can just call these java classes directly for now
> > (instead of calling tableFacade.render()).
>
> > Acimasiz, would you have time to post an example of how you use this view?
>
> > -Jeff Johnston
>
> > On Mon, Jul 21, 2008 at 10:12 AM, acimasiz <ismail.se...@gmail.com> wrote:
>
> >> I just attached my PdfView.java and PdfViewExporter.java that I wrote
> >> to deal with PDF export issues. I hope it helps.
>
> >>http://jmesa.googlegroups.com/web/PdfView.java?gda=SflkrT0AAACGopixQs...
>
> >>http://jmesa.googlegroups.com/web/PdfViewExporter.java?gda=N-DXh0UAAA...
> ...
>
> read more »

Ismail Seyfi

unread,
Jul 23, 2008, 10:41:07 PM7/23/08
to jm...@googlegroups.com
Hi Jeff, 

It is no problem. Thank you for doing that.

By the way my real name is Ismail. I corrected my profile. 

Keep up the good work. Looking forward to future releases. 

Ismail
Reply all
Reply to author
Forward
0 new messages