Note that there are some explanatory texts on larger screens.

plurals
  1. POjava save pdf from string with accents
    primarykey
    data
    text
    <p>I have a simple string with french accents. I am trying to save it to the pdf using ITextRenderer. Problem is that all the accents are deleted from the resulting pdf.</p> <p>Input string to be saved is coming from my velocity template. There, i am doinf StringEscapeUtils.escape(StringEscapeUtils.unescape(stringWithAccents)) and this process is giving me my input string, like Suppl&eacute;ment : Visa&amp;Pourboires".</p> <p>My code:</p> <pre><code> String documentHtml = "Suppl&amp;eacute;ment : &amp;agrave;&amp;egrave" DocumentBuilder builder; try { DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance(); fac.setFeature("http://xml.org/sax/features/namespaces", false); fac.setFeature("http://xml.org/sax/features/validation", false); fac.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); fac.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); builder = fac.newDocumentBuilder(); byte[] docByte = documentHtml.getBytes("UTF-8"); ByteArrayInputStream is = new ByteArrayInputStream(docByte); Document doc = builder.parse(is); is.close(); File file = new File(this.getFolder(), this.getFileName()); if (file.exists()) { file.delete(); } // save pdf OutputStream os = new FileOutputStream(file); ITextRenderer renderer = new ITextRenderer(); renderer.setDocument(doc, file.getParentFile().getAbsolutePath()); renderer.layout(); renderer.createPDF(os, true); os.close(); return this.getFolder().getAbsolutePath() + "/" + this.getFileName(); } catch (ParserConfigurationException e) { LOGGER.error("Error while parsing the configuration " + e.getMessage(), e); throw new BOServiceException("Error while parsing the configuration : " + e.getMessage(), e); } catch (UnsupportedEncodingException e) { LOGGER.error("Encoding error : " + e.getMessage(), e); throw new BOServiceException("Encoding error : " + e.getMessage(), e); } catch (SAXException e) { LOGGER.error("Error in the document because of SAX : " + e.getMessage(), e); throw new BOServiceException("Error in the document because of SAX : " + e.getMessage(), e); } catch (IOException e) { LOGGER.error("Error due to io problem : " + e.getMessage(), e); throw new BOServiceException("Error due to io problem :" + e.getMessage(), e); } </code></pre> <p>So u have idea why my encoding is not working? Why in the result pdf I cannot see characters like &agrave;&amp;egrave</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload