PDF Generating Tool Support Forum

HOME   Login   Register    Search




  Subject: Encoding problem (æøå)
   PostPosted: 14 Sep 2011, 17:51 
Hi.

I am rendering af URL and have problems with characters like æ, ø, å which is shown as '?'.

How do I solve the character problem?

My HTML page is declared with the meta tag:
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

The pd4ml debug looks like:
version: PD4ML 371b9 (eval)
using content encoding from HTTP header: iso-8859-1
new parse attempt with: UTF8
done in 240ms.

In the PD4ML code I use the code:
Code:
...
PD4ML html = new PD4ML();
html.overrideDocumentEncoding("iso-8859-1");
html.enableDebugInfo();

response.setContentType("application/pdf");
response.setHeader("Content-disposition","inline; filename="+fileName+".pdf");
            
InputStreamReader isr = new InputStreamReader(connection.getInputStream());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
html.render( url, baos );
   
byte[] result = baos.toByteArray();
response.setContentLength(result.length);
      
ServletOutputStream sos = response.getOutputStream();
sos.write( result );


  Subject: Re: Encoding problem (æøå)
   PostPosted: 14 Sep 2011, 17:56 
PD4ML supports by default ISO-8859-1 charset only. In order to output international characters you need to utilize TTF embedding feature of PD4ML Pro.

pd4ml-html-css-pdf-tips-tricks-f7/ttf-embedding-t42.html


  Subject: Re: Encoding problem (æøå)
   PostPosted: 14 Sep 2011, 18:08 
Thanks.

But the characters like æøå is supported by ISO-8859-1.

And why does the debug says that it parse with attempt: UTF8?:
using content encoding from HTTP header: iso-8859-1
new parse attempt with: UTF8

Please see:
http://en.wikipedia.org/wiki/ISO/IEC_8859-1


  Subject: Re: Encoding problem (æøå)
   PostPosted: 14 Sep 2011, 18:31 
new parse attempt with: UTF8
is caused by an encounter with <meta> encoding directive.

In your code overrideDocumentEncoding() takes no effect, as if works only for render(URL) methods.

/**
 * sets default encoding for URL-addressed HTML documents 
 * @param encoding name
 * @since v3.7.1
 */
public void overrideDocumentEncoding( String encoding ) {


As long as you pass the HTML source as an InputStreamReader, it uses a charset of the reader. You may try to use InputStreamReader constructor with Carset parameter. But a better approach would be to call
render(StringReader isr, OutputStream os, URL base, String encoding)

> But the characters like æøå is supported by ISO-8859-1.
Obviously the problem is caused by an attempt to interpret ISO-8859-1 document as UTF-8. First we need to make sure it is parsed as ISO-8859-1. Please try the above suggestions.


  Subject: Re: Encoding problem (æøå)
   PostPosted: 14 Sep 2011, 19:27 
Thanks, I will try your approach.

But how do we convert the website url to java.io.StringReader if we are not going to use java.net.URLConnection?

And what is the java.net.URL base for?

Can you please give some tips?


  Subject: Re: Encoding problem (æøå)
   PostPosted: 14 Sep 2011, 19:41 
> And what is the java.net.URL base for?

base is for relative path calculations. InputStreamReader or StringReader simply provide no info to resolve relative paths.

Well, in your sample code it is not quite clear where connection variable comes from. If your source document can be addressed by URL, it is good idea to use one of render(URL) methods. In the case html.overrideDocumentEncoding("iso-8859-1") should work for you as expected.


  Subject: Re: Encoding problem (æøå)
   PostPosted: 14 Sep 2011, 20:02 
Sorry my mistake.

We are not using java.net.URLConnection. We only use:
html.render( url, baos );

Here is how we get the URL:
java.net.URL url = new java.net.URL("http://www.cateringportal.dk/rekvisition/servlet/URLOrder?orderID=279&uid=uJ5FOxxyXCgMvU42ygSRqdBlmWLPGzVw7JiAqOsTPnhv8MirBa");


  Subject: Re: Encoding problem (æøå)
   PostPosted: 15 Sep 2011, 16:26 
Problem is solved.

The URL I pointed to, was a servlet which was redirecting to the jsp page (HTML page). This caused the problems with showing speciel characters like æøå as ???.

Now I just point the URL directly to the jsp page (HTML page) and it works now. The characters are shown perfectly.

Thanks for support.



[Reply]     [ 8 posts ] 

cron
Copyright ©2004-10 zefer|org. All rights reserved. Bookmark and Share