English 中文(简体)
Embed font into PDF file by using iText
原标题:

I defined a tag map, and got a XML data file. I want to convert the XML data file to PDF by using iText. The question is how to embed fonts (e.g. Polish font, Chinese font) into the target PDF when converting XML to PDF?

问题回答

If you are doing more work with iText, you may want to invest into the iText book - it has examples for all the features of iText.

There is a parameter that you specify when you create your font that defines font embedding:

BaseFont helvetica = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);
Font font = new Font(helvetica, 12, Font.NORMAL);

You can find more iText font related examples here: http://1t3xt.info/examples/browse/?page=toc&id=14

However, you will have problem if you will not have single font matching any characters used by you and you need multiple fonts.

In this case the FontSelector class is for you.

I ve written a short article about that:
http://lechlukasz.wordpress.com/2010/01/06/using-dynamic-fonts-for-international-texts-in-itext/

Here s a really easy way of instructing iText to embed all fonts. Insert this before your code to load fonts:

FontFactory.defaultEmbedding = true;

You can try transforming it into PDF/A which has all the fonts embedded.

    PdfReader reader = new PdfReader(GetTemplateBytes());
    pst = new PdfStamper(reader, Response.OutputStream);

    pst.Writer.SetPdfVersion(PdfWriter.PDF_VERSION_1_4);
    pst.Writer.PDFXConformance = PdfWriter.PDFA1A;




相关问题
Java (AWT): fitting text in a box

I have an application that extends a Frame. Then, it ll display a few lines of text using: Font f = new Font("Arial", Font.PLAIN, 10); g.setFont(f); g.drawString("Test|great Yes ^.", x, y + 10); Now ...

Embed font into PDF file by using iText

I defined a tag map, and got a XML data file. I want to convert the XML data file to PDF by using iText. The question is how to embed fonts (e.g. Polish font, Chinese font) into the target PDF when ...

Font Rendering between Mozilla and webkit

I m not sure if this has anything to do with the recent Safari update, but I m beginning to notice this a lot. There is a drastic difference in the way each browser is rendering fonts. for instance, ...

Embedding Fonts in AS3 - Dynamic Text Field disappears

This is hopefully a new problem or just me missing something obvious. Please help! I m embedding a font into my AS3 application. I m doing everything by-the-book and it half-works. In my main class, ...

Dynamic GD image width text

I m trying to spice up my website by using custom fonts for headings. For me, the most appropriate way to do this is using PHP and GD. I have written a little script which will output the dynamic text ...

How do I combine @font-face and @media declarations?

I d like to build a common typography stylesheet with a very small number of selectors. As such, I d far prefer to use @media sections for the various versions rather than create different files, each ...

热门标签