Getting an error when we try to replace fonts in a PDF using C#

Hi,

PDF Alignment is damaged when we try to replace fonts in a PDF using C#.

The pdf file has fonts like below.

we want to replace all these fonts with courier new font.



Below is the code snippet we are using. but its not working

PdfLoadedDocument loadedDocument = new PdfLoadedDocument(@"D:/TestPDF.pdf");

var lent = loadedDocument.UsedFonts.Length;
for (int j = 0; j < lent; j++)
{
loadedDocument.UsedFonts[j].Replace(new PdfStandardFont(PdfFontFamily.Courier, 10));
PdfFont newfont = new PdfTrueTypeFont(new Font("Courier", 14), true);
}
loadedDocument.Save("D:/Replacedfile.pdf");
loadedDocument.Close(true);

we are getting below error.

{"Can't replace font, the font is already embedded"}

Please help.





1 Reply

GK Gowthamraj Kumar Syncfusion Team July 8, 2021 11:27 AM UTC

Hi Vamsi, 
 
Thank you for contacting Syncfusion support. 
 
As per our specification, we could not replace the TrueTypeEmbedded font from the existing PDF document. We can only replace normally used fonts on our end. Kindly please refer to the below links for more information,       
 
Regards, 
Gowthamraj K 


Loader.
Up arrow icon