Exception while using com.aspose.pdf.TextFragement.setText method :: Format of font "Symbol" is not supported for new composite fonts

Hello,
I am trying Aspose PDF api for java to replace a text portion in PDF document. Below is sample code snippet of what i am using. The code is working fine for few documents but throwing exception for few document. Can you please check if there are any bug around this and suggest further?

Sample code snippet :
String coveragePeriodMatch = “Coverage Period: .*”;
String coveragePeriodToReplace = “Coverage Period: 09/01/2024 - 08/30/2025”;

TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(coveragePeriodMatch,new TextSearchOptions(true) );

pdfDocument.getPages().accept(textFragmentAbsorber);

TextFragmentCollection textFragmentCollection = textFragmentAbsorber.getTextFragments();

for (TextFragment textFragment : textFragmentCollection) {
textFragment.setText(coveragePeriodToReplace);
textFragment.getTextState().setFont(font);
textFragment.getTextState().setFontSize(12);
textFragment.getTextState().setFontStyle(FontStyles.Bold);
}

Exception :
Exception occured while validating pdf’s with csv Format of font “Symbol” is not supported for new composite fonts
Exception occured while validating pdf’s with csv: com.aspose.pdf.internal.ms.System.l7k: Format of font “Symbol” is not supported for new composite fonts

Observations :

  • textFragment.setText() is throwing exception when coveragePeriodToReplace variable contains “09”. But not for all documents.
  • Issue is observed only in Linux OS, not on Windows machine.
  • Issue occurs only for some set of documents not for all.
  • while using same source document for replication, the exception occurs only when the coverage period replacement text contains “09”.

Please suggest on below things :

  1. Is there any open bug around this issue already ? if not can we create one and try to fix it quickly
  2. Is there any way to enable additional debug logs which will help us to understand the issue better
  3. Are there any work around available ?

@veeramanim22

It seems you are encountering an issue with the setText method of the TextFragment class in the Aspose PDF API for Java, specifically related to the “Symbol” font format not being supported for new composite fonts. Here are some suggestions to address your concerns:

  1. Open Bug Reports: As of now, I do not have information on any existing bug reports related to this specific issue. However, if you believe this is a bug, I recommend reaching out to Aspose support directly to report it. They can provide you with the latest updates and possibly create a ticket for you.

  2. Debug Logging: To enable additional debug logs, you can configure the logging settings in your Java application. This typically involves setting the logging level to DEBUG for the Aspose library. You can use a logging framework like Log4j or SLF4J to capture detailed logs, which may help you understand the issue better.

  3. Workarounds:

    • Font Replacement: If the issue arises specifically with the “Symbol” font, consider replacing it with a different font that is supported. You can check the fonts available in your PDF document and choose one that does not cause the exception.
    • Text Segments: Instead of modifying the TextFragment directly, you can access and modify the individual TextSegment objects within the TextFragment. This allows you to handle font settings on a more granular level, which might help avoid the exception.

Here is a sample code snippet that demonstrates how to access and modify text segments:

TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(coveragePeriodMatch, new TextSearchOptions(true));
pdfDocument.getPages().accept(textFragmentAbsorber);

TextFragmentCollection textFragmentCollection = textFragmentAbsorber.getTextFragments();

for (TextFragment textFragment : textFragmentCollection) {
    textFragment.setText(coveragePeriodToReplace);
    for (TextSegment segment : textFragment.getSegments()) {
        segment.getTextState().setFont(font); // Set a different font if needed
        segment.getTextState().setFontSize(12);
        segment.getTextState().setFontStyle(FontStyles.Bold);
    }
}

This approach allows you to handle each segment individually, which may help in avoiding the exception you are facing.

If you continue to experience issues, please provide more details about the specific documents that cause the exception, as this may help in diagnosing the problem further.

Sources:
[1]: TextFragment | Aspose.PDF for Java API Reference

We have used in the similar way. But the moment when we reach setText() itself we have got the exception.

@veeramanim22

Are you using the latest version of the API? Can you please share your sample PDF document with us as well so that we can test the scenario in our environment and address it accordingly?

Hi @asad.ali ,
Thanks for the response. I have tried with aspose-pdf versions 22.10 and 22.11.
on both versions I am facing the same issue.

Reg the sample PDF, I cannot share the actual PDFs which I am facing issue. Let me try to create a sample PDF and share here if possible.

@veeramanim22

Sure, please take your time to share a sample PDF so that we can test the scenario in our environment and address it accordingly.