Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Tue Feb 02, 2021 4:22 pm

Hello, how are you?
How do I replace a font in a PDF file using a custom font installed on the operating system?
Thank you in advance!

gafforelli
 
Posts: 37
Joined: Sat Sep 15, 2018 6:38 pm

Wed Feb 03, 2021 6:16 am

Hello,

Thanks for your inquiry!

Please refer to the following code to replace a font in a PDF file using the custom font installed on the operating system.
Code: Select all
            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile("sample.pdf");

            //get the fonts used in the PDF
            PdfUsedFont[] fonts =  doc.UsedFonts;

            //get the font installed in the system
            Font theFont = new Font("Jokerman", 12f);
            PdfTrueTypeFont pdfTrueTypeFont = new PdfTrueTypeFont(theFont, 12f);

            //replace the first kind of fonts in the PDF
            PdfUsedFont font = fonts[0];
            font.Replace(pdfTrueTypeFont);

            doc.SaveToFile("ReplaceFont.pdf", FileFormat.PDF);


If the code does not match your needs, please provide us with your input file for investigation. Thanks in advance.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Mon Feb 08, 2021 2:18 am

Hello,

Hope you are doing well!

Has the issue been solved now? Could you please give us some feedback at your convenience?

Thanks in advance.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Return to Spire.PDF