Reputation: 1484
I need to get font information (font family, color e.t.c) from FreeText
annotation using PDFTron in .Net. And I see only FreeText.GetFontSize
method. How can I get font information of FreeText
annotation?
Upvotes: 2
Views: 1311
Reputation: 2570
If an appearance stream is present, then parsing the appearance stream with the ElementReader interface returns the fonts actually used for the appearance. So in one sense this is the most accurate check.
To check for appearance call Annot.GetAppearance() != null
If there is no appearance present, then either you could generate the appearance and check then, though this modifies the PDF which is not always desired.
If no appearance stream is present, then you first check the DS
entry, which is a CSS string. For example:
font: 'Comic Sans MS',sans-serif 12.0pt; text-align:left; color:#E52237
If DS
is not present, than the DA
is required.
0 G 0.898 0.1333 0.2157 rg 0 Tc 0 Tw 100 Tz 0 TL 0 Ts 0 Tr /ComicSansMS 12 Tf
These are PDF graphics operators, essentially you parse the string and look for Tf
and the previous two operands are font and font size.
For example
SDF.Obj ds = Annot.GetSDFOjb().FindObj("DS");
if(ds != null) string ds_str = ds.GetAsPDFText();
Upvotes: 1