You should try something like this:

PathInJar="/fontResource/arialuni.ttf"; //This is a path in your java
project to the font.

String fontPath=getClass().getResource(PathInJar).toString();



2007/9/27, nsk clr <[EMAIL PROTECTED]>:
>
> Hi Paulo
>
> I bundled the ttf as a jar and use the following
>
> FontFactory.register("C:\\Itext\\arialuni.jar\\arialuni.ttf", "Arial
> Unicode MS");
>
> to access it. I get the below exception.
>
>  ExceptionConverter: java.io.IOException:
> C:\Itext\arialuni.jar\arialuni.ttf not found as file or resource.
>
> Can I access a ttf file from a jar? is the syntax right?
>
> Thanks
>
>
>
> *nsk clr <[EMAIL PROTECTED]>* wrote:
>
> Hi
>
> I need to use the same in Linux too. Is it possible to install
> ArialUnicode MS ttf in Linux or is there an equivalent font available?
>
> Thanks
>
> *nsk clr <[EMAIL PROTECTED]>* wrote:
>
> Thanks Paulo
>
> It's working fine. It was classpath setting clash that was giving the
> problem.
>
> *Paulo Soares <[EMAIL PROTECTED]>* wrote:
>
> It works with my code and my html.
>
> File file = new File("C:\\chinese.html");
> int fileLen = (int)file.length();
> FileInputStream fis = new 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:\\chinese.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();
>
>
> Paulo
>
> ----- Original Message -----
> From: "nsk clr"
> To: "Post all your questions about iText here"
>
> Sent: Wednesday, September 26, 2007 5:45 PM
> Subject: Re: [iText-questions] Issue in converting chinese content to pdf
>
>
> After removing the encoding="utf-8" in the html and using my code, I don't
>
> get the ouput like the one you have attached.
>
> It's all jumbled in a single line and with junk characters.
>
> Do I need to change any other basic settings in my system or in pdf?
>
> Thanks
>
> Paulo Soares wrote:
>
> Also remove the encoding in the html that is masking the real font
> encoding.
> I attach the modified html and the resulting pdf.
>
> Paulo
>
> ----- Original Message -----
> From: "nsk clr"
> To: "Post all your questions about iText here"
>
> Sent: Tuesday, September 25, 2007 11:27 PM
> Subject: Re: [iText-questions] Issue in converting chinese content to pdf
>
>
> When I use String userHTML = new String(bytes, "UTF-8");, I get nothing in
> the pdf.
>
> Otherwise, in the pdf- document properties, the encoding is shown as ANSI,
> inspite of me setting as Identity-H in
> st.loadTagStyle("body", "encoding", "Identity-H");
>
> How to set the Identity-H as encoding? Why is it not being set?
>
> Thanks
>
> Paulo Soares wrote:
> You must use the right charset. In this case:
>
> String userHTML = new String(bytes, "UTF-8");
>
> Paulo
>
> ----- Original Message -----
> From: "nsk clr"
> To:
> Sent: Tuesday, September 25, 2007 10:06 PM
> Subject: [iText-questions] Issue in converting chinese content to pdf
>
>
> Hi
>
> I use Itext to convert chinese html to pdf.
> The code is
> File file = new File("C:\\Itext\\chinese.html");
> int fileLen = (int)file.length();
> FileInputStream fis = new FileInputStream(file);
> byte[] bytes = new byte[fileLen];
> fis.read(bytes,0,fileLen);
> String userHTML = new String(bytes);
> 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:\\Swarna\\Itext\\chinese.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();
>
> I have attached the input and ouput files.
>
> Please let me know what to do to get the correct output
>
> Thanks
>
> å(r)sè°·æ­OEç½'页ï¼OEè(r)¯æ ¯ï¼OEå¹¶æOE?é'(r)æ ¥æ~¾ç¤ºä½
> æ?EURéEUR?语è¨EURéEURsè¿?æ^'们çs"å 好页ãEUR'
> è°·æ­OEç>(r)å? æ ä¾>ä¸<å^-语è¨EURç*OEé ¢ï¼s
> å(r)sè°·æ­OEç½'页ï¼OEè(r)¯æ ¯ï¼OEå¹¶æOE?é'(r)æ ¥æ~¾ç¤ºä½
> æ?EURéEUR?语è¨EURéEURsè¿?æ^'们çs"å 好页ãEUR'
> è°·æ­OEç>(r)å? æ ä¾>ä¸<å^-语è¨EURç*OEé ¢ï¼s
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2005.
>
> 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/
>
>
>
> ________________________________
>
> Tonight's top picks. What will you watch tonight? Preview the hottest
> shows
>
> on Yahoo! TV.
>  å(r)šè°·æ­Œç½'页,è(r)¯æ ¯ï¼Œå¹¶æŒ‰é'(r)æ
> ¥æ˜¾ç¤ºä½ 所选语言通过æˆ'们的å 好页。
> è°·æ­Œç›(r)å‰ æ ä¾›ä¸‹åˆ—è¯­è¨€ç•Œé ¢ï¼š
> å(r)šè°·æ­Œç½'页,è(r)¯æ ¯ï¼Œå¹¶æŒ‰é'(r)æ
> ¥æ˜¾ç¤ºä½ 所选语言通过æˆ'们的å 好页。
> è°·æ­Œç›(r)å‰ æ ä¾›ä¸‹åˆ—è¯­è¨€ç•Œé ¢ï¼š
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2005.
>
> 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/
>
>
>  ------------------------------
> Building a website is a piece of cake.
> Yahoo! Small Business gives you all the tools to get 
> online.<http://us.rd.yahoo.com/evt=48251/*http://smallbusiness.yahoo.com/webhosting/?p=PASSPORTPLUS>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2005.
>
> 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/
>
>
>  ------------------------------
> Be a better Heartthrob. Get better relationship answers
> <http://us.rd.yahoo.com/evt=48255/*http://answers.yahoo.com/dir/_ylc=X3oDMTI5MGx2aThyBF9TAzIxMTU1MDAzNTIEX3MDMzk2NTQ1MTAzBHNlYwNCQUJwaWxsYXJfTklfMzYwBHNsawNQcm9kdWN0X3F1ZXN0aW9uX3BhZ2U-?link=list&sid=396545433>from
> someone who knows.
> Yahoo! Answers - Check it out.
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2005.
>
> 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/
>
>
> ------------------------------
> Yahoo! oneSearch: Finally, mobile search that gives 
> answers<http://us.rd.yahoo.com/evt=48252/*http://mobile.yahoo.com/mobileweb/onesearch?refer=1ONXIC>,
> not web links.
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2005.
> 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/
>
>
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
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/

Reply via email to