logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
lxman  
#1 Posted : Wednesday, May 26, 2021 3:05:22 PM(UTC)
lxman

Rank: Member

Groups: Registered
Joined: 10/19/2017(UTC)
Posts: 14
United States
Location: North Carolina

Was thanked: 1 time(s) in 1 post(s)
I realize that this probably is not a simple ask. But I need to determine what font a particular PdfControl uses to render its text. The best thing I seem to have come up with in searching the forums is this:

https://forum.patagames....Width-of-text-in-textbox

In post #6 you outline a procedure to obtain the font. I do note that was 2 years ago, so I would just like to ask - is there any more direct way to get the font that a PdfControl uses?

Thank you,

Michael
Paul Rayman  
#2 Posted : Thursday, May 27, 2021 7:29:36 PM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 1,138

Thanks: 10 times
Was thanked: 133 time(s) in 130 post(s)
well

Code:

//Get Default appearance for the control
string da = GetDefaultAppearance(doc.FormFill.InterForm, ctrl.Field.Dictionary);

//Parse DA
float[] strokeColor, fillColor;
float fs;
FS_MATRIX m;
string tagName;
Pdfium.FPDFTOOLS_ParseDefaultAppearance(da, out strokeColor, out fillColor, out tagName, out fs, out m);

//Check acroforms dictionary for the tagName
var font = doc.FormFill.InterForm.Fonts[tagName];


internal string GetDefaultAppearance(PdfInteractiveForms InterForms, PdfTypeDictionary dict = null, int level = 0, bool checkAcroFormsDictionary = true)
{
	if ((level > 128))
		return "";
	if (dict.ContainsKey("DA") && dict["DA"].Is<PdfTypeString>())
		return dict["DA"].As<PdfTypeString>().UnicodeString;
	if (dict.ContainsKey("Parent") && dict["Parent"].Is<PdfTypeDictionary>())
		return GetDefaultAppearance(InterForms, dict["Parent"].As<PdfTypeDictionary>(), level++);
	if (checkAcroFormsDictionary && InterForms.Dictionary != null && InterForms.Dictionary.ContainsKey("DA") && InterForms.Dictionary["DA"].Is<PdfTypeString>())
		return this.InterForms.Dictionary["DA"].As<PdfTypeString>().UnicodeString;
	return "";
}

lxman  
#3 Posted : Friday, May 28, 2021 5:37:46 AM(UTC)
lxman

Rank: Member

Groups: Registered
Joined: 10/19/2017(UTC)
Posts: 14
United States
Location: North Carolina

Was thanked: 1 time(s) in 1 post(s)
Thank you for that. I'll play with it a bit and see how it turns out.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.