| Issue 59: | Two errors with PDF generation - and their fixes | |
| 1 person starred this issue and may be notified of changes. | Back to list |
I found two new errors when exporting a jmesa table to pdf:
1. When any of the exported data contains the ampersant ('&') character,
wich is common for german company names, the PDF generation is aborted with
an Exception: " org.xml.sax.SAXParseException: Der Entitätenname muss
unmittelbar nach dem '&' im Entitätenverweis folgen'.
2. When any of the exported data contains german umlauts (äöüÄÖÜß), the PDF
generation is aborted with an Exception: ' org.xml.sax.SAXParseException:
Ungültiges Byte 2 in 2-Byte-UTF-8-Folge'.
These errors were found in the version jmesa-2.2.4-pdf.
I found a fix for both errors that you should adopt into your next release.
I changed the method getBytes() of the class org.jmesa.view.pdf.PdfView to
this:
--- snip ---
public byte[] getBytes() {
String render = ((String) render()).replaceAll("\\&", "&");
byte[] bytes = null;
try {
bytes = render.getBytes("UTF8");
} catch (UnsupportedEncodingException e) {
// TODO do something wise here!
e.printStackTrace();
}
return bytes;
}
--- snip ---
Explanation:
1. the call of replaceAll replaces all '&' caracters with the html
enconding '&'.
2. the call of render.getBytes("UTF8") encodes the german umlauts to valid
utf-8 byte values.
Enjoy ;-)
Dirk Michaelsen
Nov 23, 2007
(No comment was entered for this change.)
Status:
Accepted
Nov 27, 2007
I implemented a fix for this. What I did was a custom body method and decorated the CellEditor with an editor that will escape xml syntax. I have not had the chance to really test it out yet, but I would be happy to do a build if you would like to test it! I was able to reproduce the error with the & symbol so I know it worked to fix that. http://jmesa.googlecode.com/svn/trunk/jmesa/src/org/jmesa/view/pdf/PdfView.java
Status:
Started
Nov 28, 2007
Good shot but no hit ;-)
I'm affraid to tell you that your code is still buggy. In case the column value is no
String (in my case it is an Integer) you get a ClassCastException. But if you change
the getValue method of the EscapeXmlCellEditor class like the following, everything
works like expected:
public Object getValue(Object item, String property, int rowcount) {
Object value = cellEditor.getValue(item, property, rowcount);
if (value != null) {
return StringEscapeUtils.escapeXml(value.toString());
}
return null;
}
So from my point of view you can close this issue.
Thanks a lot
Dirk Michaelsen
Nov 28, 2007
Got it! I checked in the changes. Let me know if you find anything else. The PDF view is getting better and better as we work with it more!
Status:
Fixed
|
Thank you for the information! For sure I will add the render.getBytes("UTF8") fix. The other one I am trying to think of something more generic. Really you would want all characters to be encoded as the ampersand is just one possibility. Maybe we need a generic wrapper CellEditor for PDF exports.... I will look into it!