Want to apply Script fonts to particular field value in PDF using aspose pdf .net

47 Views Asked by At

I want to apply Script fonts to particular field value in PDF.

I am using aspose PDF. But that font is not applying.

Here is steps I have followed :

I have downloaded ttf file. Created new folder in project and added font in that folder.

Then I am fetching PDF form fields and loop through it foreach and then trying to applying that font to only one value which I needed.

foreach (Field formField in pdfDocument.Form.Fields)
            {
                switch (formField.PartialName.ToString())
                {
                    case "f1_32[0]":
                        formField.Value = request.Signature;
                        formField.DefaultAppearance.FontName = "E:\\Projects\\Testprojectname\\Fonts\\Photograph_Signature.ttf";
                        break;
                }
            }
1

There are 1 best solutions below

2
Murat Ishenbaev On

the DefaultAppearance.FontName property is used to set the default font for form fields in the PDF, but it won't affect the font of an individual field value. To change the font of a specific field value, you need to use the TextState.Font property.

foreach (Field formField in pdfDocument.Form.Fields)
{
    switch (formField.PartialName.ToString())
    {
        case "f1_32[0]":
            formField.Value = request.Signature;
            TextState textState = formField.DefaultAppearance.TextState;
            textState.Font = FontRepository.OpenFont("E:/Projects/Testprojectname/Fonts/Photograph_Signature.ttf");
            break;
    }
}