Setting textFragment.TextState.Font results in error when PDF is opened

Hi,
We are modifying an existing PDF almost along the lines of the code given in the github repo:

The one extra thing we have done is to set the font to Bold and Italic:
textFragment.TextState.FontStyle = FontStyles.Bold | FontStyles.Italic;

The above line of code follows textFragment.TextState.Font = …

When we open the PDF, the appended text is not displaying and when we click on it, we are getting an error “Cannot find or create the font ‘LMWFPU+ArialBoldItalic’. Some characters may not display or print correctly.” The “LMWFPU” string will change every time I generate the pdf and replace the text.

This error however seems to go away when we comment the below line of code:
textFragment.TextState.Font = FontRepository.FindFont(“Arial”);

I can confirm that I have Arial installed in my machine in C:\Windows\Fonts. Please advise if there is any way out of this error.

@mukaofenact,

Can you please share source file along withe error details to further investigate this issue.

// Open document
Document pdfDocument = new Document(filePath); // filepath is that of a PDF
int pageCount = pdfDocument.Pages.Count;

Page pdfPage;
pdfPage = pdfDocument.Pages[1]; // Page to be altered


// Create text fragment
TextFragment textFragment = new TextFragment(stampText);
textFragment.Position = new Position(28, 28);                

// Set text properties
textFragment.TextState.FontSize = fontSize;
textFragment.TextState.Font = FontRepository.FindFont("Arial");
textFragment.TextState.FontStyle = FontStyles.Bold | FontStyles.Italic;
textFragment.TextState.BackgroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray);
textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Black);

// Create TextBuilder object
TextBuilder textBuilder = new TextBuilder(pdfPage);

// Append the text fragment to the PDF page
textBuilder.AppendText(textFragment);

// Save resulting PDF document.
pdfDocument.Save(filePath);

@mukaofenact,

Can you please share source file so that we may help you out.

Hi,

I will see if I can whip up a sample app and upload it.

Hi,
FYI We are using Aspose.PDF 19.2.

We tried to replicate this issue in a standalone app and realise it was a PDF specific issue. The issue seems to happen only in a PDF version 1.1 (Acrobat 2.x) document. PDFs created/generated from a later version seemed to work okay. I had created the standalone app but struggled to get a PDF of version 1.1 (even Aspose.PDF allows only as old as till 1.3!)

Don’t think we will be pursuing this issue anymore as we are going to ask the customer to reprint the PDF to a later version. Thanks.

@mukaofenact,

Thank you for informing us.