This solution is based on the following, I just replaced the font with Adobe
Reader's Simplified Chinese fonts. When the pdf is opened, Adobe will prompt
the user to download and install the Asian pack:
http://www.mail-archive.com/[email protected]/msg20413.html
StringBuffer sBuff = new StringBuffer("<html>");
sBuff.append("<head></head>");
sBuff.append("<body>");
sBuff.append("<table border=1>");
sBuff.append("<tr><td>Test worker\u80CC\u666F背景</td></tr>");
sBuff.append("</table>");
sBuff.append("</body>");
sBuff.append("</html>");
Document document = new Document();
StyleSheet st = new StyleSheet();
st.loadTagStyle("body", "face", "STSong-Light");
st.loadTagStyle("body", "encoding", "UniGB-UCS2-H");
st.loadTagStyle("body", "leading", "12,0");
StringReader stringReader = new StringReader(sBuff.toString());
PdfWriter.getInstance(document, new
FileOutputStream("c:\\worker.pdf"));
document.open();
ArrayList p = HTMLWorker.parseToList(stringReader, st);
for (int k = 0; k < p.size(); ++k)
document.add((Element)p.get(k));
document.close();
Lil Lily wrote:
>
> Hi All,
>
> Our goal is to convert an html (with Chinese characters) to a pdf file.
> We patterned our code on the sample given on this forum but still can't
> make the chinese characters to appear.
>
> Attached here is a sample of the html file and below is the code snippet.
>
> File file = new File("C:\\html.htm");
> int fileLen = (int)file.length();
> java.io.FileInputStream fis = new java.io.FileInputStream(file);
>
> byte[] bytes = new byte[fileLen];
> fis.read(bytes,0,fileLen);
> String userHTML = new String(bytes, "UTF-8");
> Document document = new Document();
>
> FontFactory.register("c:\\windows\\fonts\\ARIALUNI.TTF");
>
> StyleSheet st = new StyleSheet();
> st.loadTagStyle("body", "face", "Arial Unicode MS");
> st.loadTagStyle("body", "encoding", "IDENTITY_H");
> st.loadTagStyle("body", "leading", "12,0");
> StringReader stringReader = new StringReader(userHTML);
> PdfWriter.getInstance(document, new FileOutputStream("C:\\sample.pdf"));
> document.open();
>
> ArrayList p = HTMLWorker.parseToList(stringReader, st);
>
> for (int k = 0; k < p.size(); ++k)
> document.add((Element)p.get(k));
>
>
> document.close();
>
>
> Thank you,
> Lily
>
>
> ---------------------------------
> Never miss a thing. Make Yahoo your homepage.
> <?xml version="1.0"?>
>
>
> To: Recipient Company: Sample Co Date: 13 Dec
> 2007 MESSAGE Dear æ¶äººæ¶
> Please note the following details:
>
> Line One Line Two
> -------------------------------------------------------------------------
> SF.Net email is sponsored by:
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services
> for just about anything Open Source.
> http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
> _______________________________________________
> iText-questions mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/itext-questions
> Buy the iText book: http://itext.ugent.be/itext-in-action/
>
>
--
View this message in context:
http://www.nabble.com/HTML-with-Chinese-characters-to-PDF-tp14332364p15146643.html
Sent from the iText - General mailing list archive at Nabble.com.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/