0

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;
                }
            }
Sami In
  • 246
  • 2
  • 11
  • This scenario need to be properly tested and addressed. Please create a post in our official Aspose.PDF support forum (https://forum.aspose.com/c/pdf) with your sample files. We will test the scenario in our environment and address it accordingly. Please note that official forums are recommended and right place to discuss such matters. This is Asad Ali and I work as Developer Evangelist at Aspose. – Asad Ali Jul 05 '23 at 15:55

1 Answers1

0

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;
    }
}
  • I am getting this error : `.DefaultAppearance does not contain a definition for.TextState` – Sami In Jul 04 '23 at 18:29
  • As requested in our first comment under the original post, can you please create a topic in our dedicated forum with all necessary information so that we can further proceed to assist you accordingly. – Asad Ali Jul 10 '23 at 20:25