It works great,

Thanks a lot,
NArcis

On Mon, Jan 11, 2010 at 12:47 PM, 1T3XT info <i...@1t3xt.info> wrote:

> Traian Decebal wrote:
>
>> the biggest problem that I face is using dicritics. I use dicritics just
>> fine using a font that has them, but I can't get HTMLWorker to use the same
>> font.
>>
>
> This is a typical example where it's better to use a FontProvider.
> See the attached code and the resulting PDF (based on your HTML).
>
> import java.io.FileOutputStream;
> import java.io.FileReader;
> import java.io.IOException;
> import java.sql.SQLException;
> import java.util.HashMap;
> import java.util.List;
>
> import com.itextpdf.text.BaseColor;
> import com.itextpdf.text.DocListener;
> import com.itextpdf.text.Document;
> import com.itextpdf.text.DocumentException;
> import com.itextpdf.text.Element;
> import com.itextpdf.text.Font;
> import com.itextpdf.text.FontProvider;
> import com.itextpdf.text.Image;
> import com.itextpdf.text.html.simpleparser.ChainedProperties;
> import com.itextpdf.text.html.simpleparser.HTMLWorker;
> import com.itextpdf.text.html.simpleparser.ImageProvider;
> import com.itextpdf.text.html.simpleparser.StyleSheet;
> import com.itextpdf.text.pdf.BaseFont;
> import com.itextpdf.text.pdf.PdfWriter;
>
> public class Roumanian {
>
>    /**
>     * Inner class implementing the FontProvider class.
>     * This is needed if you want to select the correct fonts.
>     */
>    public static class MyFontFactory implements FontProvider {
>        public Font getFont(String fontname,
>                String encoding, boolean embedded, float size,
>                int style, BaseColor color) {
>                BaseFont bf;
>                try {
>                                bf =
> BaseFont.createFont("c:/windows/fonts/arialuni.ttf",
>                                                "Identity-H",
> BaseFont.EMBEDDED);
>                        } catch (DocumentException e) {
>                                e.printStackTrace();
>                                return new Font();
>                        } catch (IOException e) {
>                                e.printStackTrace();
>                                return new Font();
>                        }
>            return new Font(bf, size);
>        }
>
>        public boolean isRegistered(String fontname) {
>            return false;
>        }
>    }
>
>    /** The resulting HTML file. */
>    public static final String HTML = "roumanian.html";
>    /** The resulting PDF file. */
>    public static final String RESULT = "roumanian.pdf";
>
>    /**
>     * Main method.
>     *
>     * @param args no arguments needed
>     * @throws IOException
>     * @throws DocumentException
>     * @throws SQLException
>     */
>    public static void main(String[] args)
>        throws IOException, DocumentException, SQLException {
>        HashMap<String,Object> map = new HashMap<String, Object>();
>        map.put("font_factory", new MyFontFactory());
>        // step 1
>        Document document = new Document();
>        // step 2
>        PdfWriter.getInstance(document, new FileOutputStream(RESULT));
>        // step 3
>        document.open();
>        // step 4
>        List<Element> objects
>            = HTMLWorker.parseToList(new FileReader(HTML), null, map);
>        for (Element element : objects) {
>            document.add(element);
>        }
>        // step 5
>        document.close();
>    }
>
> }
>
>
> ------------------------------------------------------------------------------
> This SF.Net email is sponsored by the Verizon Developer Community
> Take advantage of Verizon's best-in-class app development support
> A streamlined, 14 day to market process makes app distribution fast and
> easy
> Join now and get one step closer to millions of Verizon customers
> http://p.sf.net/sfu/verizon-dev2dev
> _______________________________________________
> iText-questions mailing list
> iText-questions@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/itext-questions
>
> Buy the iText book: http://www.1t3xt.com/docs/book.php
> Check the site with examples before you ask questions:
> http://www.1t3xt.info/examples/
> You can also search the keywords list:
> http://1t3xt.info/tutorials/keywords/
>
------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.1t3xt.com/docs/book.php
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to