2

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?

Stalso
  • 1,468
  • 2
  • 12
  • 21
  • Could you clarify why getting FreeText font information is important for you? Also are you trying to handle any FreeText annotation created by any software, or just certain sources? The reason I ask is that not only are there up to three places where font information for a FreeText is stored, but there could be multiple fonts used. – Ryan Feb 16 '18 at 17:17
  • My main source software is Bluebeam Revu. But in fact it will be ideal to serve any FreeText annotation – Stalso Feb 16 '18 at 18:07
  • For now I get annotation appearance, run element reader on it. Then I get gState of text element and call `getFont` method of the state object – Stalso Feb 16 '18 at 18:12

1 Answers1

1

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();
Ryan
  • 2,473
  • 1
  • 11
  • 14
  • How can I get font family from DA entry? I see there such string: `1 1 0 rg /Helv 12 Tf`. How can I get `Helvetica` family name? – Stalso Feb 19 '18 at 09:38
  • Let us say, that we have such doc. https://drive.google.com/file/d/1U-VL8OPEMO23HBNOUxqLzttnaGctn7WN/view?usp=sharing . I can get `1 1 0 rg /Helv 12 Tf`. And I have no idea how to get `Helvetica` family name. As far, as I understand I need to extarct object with number `499` , it is font resource. But I do not know, how to do it. `doc.GetAcroForm` returns null. – Stalso Feb 19 '18 at 12:19
  • `/Helv` is the only common one like this that I am aware of. I have also seen HeBo or HelvBo, both of which are "Helvetica Bold". This forum post shows the official 14 PDF fonts that every PDF library should support. https://groups.google.com/d/msg/pdfnet-sdk/fwy6KsiY7y8/I1f1Jy8R6x8J – Ryan Feb 19 '18 at 23:13