Free Support Forum - aspose.com

Embeded Fonts not recognized in code

Hi Team,

We have a PDF with a embeded custom font.

I tried to apply the font to all the textFields of PDF using the following code..

But the highlighted line throws a error "Font Airmole was not found" at runtime.

Is it necessary to install the font on the system ?? Becuase the font specified is allready in the PDF file.

   	    Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(outputPath);
            Aspose.Pdf.Facades.Form form = new Aspose.Pdf.Facades.Form(outputPath);
            String[] allfields = form.FieldNames;
            //the following line gives a error at runtime
   	    Aspose.Pdf.Text.Font font = FontRepository.FindFont("Airmole");
 
            foreach (var fieldName in allfields)
            {
                Aspose.Pdf.InteractiveFeatures.Forms.Field field = pdfDocument.Form[fieldName] as Aspose.Pdf.InteractiveFeatures.Forms.Field;
                field.DefaultAppearance = new Aspose.Pdf.InteractiveFeatures.DefaultAppearance(font, 10, System.Drawing.Color.Black);
            }           
            pdfDocument.Save(outputPath3);
   	    Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(outputPath);
            Aspose.Pdf.Facades.Form form = new Aspose.Pdf.Facades.Form(outputPath);
            String[] allfields = form.FieldNames;
            Aspose.Pdf.Text.Font font = FontRepository.FindFont("Airmole");
        <span style="color: blue;">foreach</span> (<span style="color: blue;">var</span> fieldName <span style="color: blue;">in</span> allfields)
        {
            Aspose.Pdf.InteractiveFeatures.Forms.<span style="color: rgb(43, 145, 175);">Field</span> field = pdfDocument.Form[fieldName] <span style="color: blue;">as</span> Aspose.Pdf.InteractiveFeatures.Forms.<span style="color: rgb(43, 145, 175);">Field</span>;
            field.DefaultAppearance = <span style="color: blue;">new</span> Aspose.Pdf.InteractiveFeatures.<span style="color: rgb(43, 145, 175);">DefaultAppearance</span>(font, 10, System.Drawing.Color.Black);
        }           
        pdfDocument.Save(outputPath3);</pre><p> </p><p>regards,</p><p>Rohan W</p>

Hi Rohan,


Thanks for using our products.

The method FontRepository.FindFont(…) finds system installed fonts and standard Pdf fonts. It also provides the functionality to open custom fonts so that they can be used when creating PDF files. So in order to set the font for form field, you need to first install the font over system. We are sorry for this inconvenience.