How to display UTF-8 Characters in PDF via Html String

5,581 views
Skip to first unread message

shikha tyagi

unread,
Jun 25, 2011, 2:59:44 PM6/25/11
to Flying Saucer Users
Hi ,
I am creating PDF file from Xhtml String (It contains CSS).
Html String Contains Currency Symbols like лв, ₩, ₪ and so
on..
So when we create PDF file using
org.xhtmlrenderer.pdf.ITextRenderer class , it does not display any
Symbol in PDF.

after parsing an Html string from Builder, it shows All Currency
Symbols in Document , but when this document object sent to Renderer
method public void setDocument(Document, String,
NamespaceHandler),
public void
createPDF(OutputStream) throws DocumentException

after that , it doesnt dispaly any symbol


Please help me out, it so urgent task in my project



Thanks
shikha
shikha....@gmail.com

Peter Brant

unread,
Jun 26, 2011, 1:52:49 PM6/26/11
to flying-sa...@googlegroups.com

You need to use a font that contains glyphs for those characters. If you search the mailing list archives, you'll find lots of examples of this. The basic pattern is to register the font with ITextFontResolver or @font-face and then reference the font in your CSS with font-family.

Pete

shikha tyagi

unread,
Jun 26, 2011, 2:45:51 PM6/26/11
to flying-sa...@googlegroups.com
hi peter,
           Thanks for your Response but
         I am new to this  kind of issue, can u please send me some snapshot  of code ?
        Here is Steps  which is using  in my project:--
        (i) I am generating Html String from XSLT and it shows all Currency Symbols sucessfully,

        (ii) after parse an Html String using documentbuilder, again it shows all Currency Symbols in Document...

         But i think when we use Renderer class , it creates an problem with currency symbols..
         I think I need to set charset encoding as "UTF-8' in charset

         Please send me code to resolve this Issue....
          

I am using This Code:--

 DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(new StringBufferInputStream(buf.toString()));

ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(doc, null);

String outputFile = "100bottles.pdf";
OutputStream os = new FileOutputStream(outputFile);
renderer.layout();
renderer.createPDF(os);
os.close();

Peter Brant

unread,
Jun 27, 2011, 5:42:10 AM6/27/11
to flying-sa...@googlegroups.com
I don't have any self-contained sample code handy, but here is a
thread (among others) that discusses the same problem:

http://groups.google.com/group/flying-saucer-users/browse_thread/thread/63d5ec6be2f034c6

Pete

Reply all
Reply to author
Forward
0 new messages