开发者

GdiCharSet & iTextSharp

开发者 https://www.devze.com 2023-02-01 05:32 出处:网络
Is there the way to create iTextSharp font using additional info开发者_运维问答 (such as gdiCharSet etc) from System.Drawing.Font object?Short answer: Yes.

Is there the way to create iTextSharp font using additional info开发者_运维问答 (such as gdiCharSet etc) from System.Drawing.Font object?


Short answer: Yes.

Long answer: Each attribute is a bit different, but all that information can be expressed within PDF in general, and iText[Sharp] in specific.

You can specify a font's encoding when you create it, but you must do so in a way iText understands. Specifically, encoding values are strings within iText[Sharp]. BaseFont has a number of public static string members that list many of the available encodings, including several code pages that will map nicely to some of the GdiCharSet values. Others, not so much.

I generally suggest using "Identity-H" and subsetting your fonts (which happens automagically with Identity-H, you can't avoid it, which is a Good Thing) unless you need to keep the file size to a bare minimum. There are several single-byte encodings, the most common of which is "WinAnsiEncoding", BaseFont.WINANSI (the default IIRC). The string can also be the name of a "CMap" (such as Identity-H).

CMaps are generally language specific, and encoding specific. UTF & Japanese, or Big5 (a Chinese encoding as I recall), or what have you. Identity-H (and Identity-V) are font specific instead. They simply map values in the content stream to glyph indexes in the font (which can vary wildly from one font to the next, or between versions of a given font: that's why you're required to embed subsets of Identity-* fonts).

In PDF (and therefore iText[Sharp]), "bold" and "italic" are part of the font's identity, not a property. "Arial-Bold", "Arial-Italic", etc.

Strikeout and underline are decorations added after the fact (though I believe iText will let you set a flag at the font level for such things in com.itextpdf.text.Font's constructor).

iText won't give you direct access to the height, though a font's "descriptor" will let you define it.

The point size isn't a property either, you set it and the font (and color, default black) before you draw some text.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号