We are using Aspose PDF JAVA version 24.12
We are trying to use pdfContentEditor to replace text inside an existing PDF file.
When we use the replaceText-code for a piece of text in a font with state: “Embedded Sub” we get the next error when executing in a Docker environment.
Format of font “Symbol” is not supported for new composite font
We have configured:
replaceTextStrategy.setNoCharacterBehavior(ReplaceTextStrategy.NoCharacterAction.UseStandardFont);
But we still get the exception as listed above.
We can think of a few options:
Fully embed the fonts (not always possible)
Specify a standard font? The option: ReplaceTextStrategy.NoCharacterAction.UseStandardFont suggests that something like that is possible.
Can you tell us how to indicated a “StandardFont” in Java?. What are the standard fonts?
Standard Fonts are usually Microsoft Core Fonts that are already present in Windows environment and in Linux like environment, they can be installed by installing the msttcorefonts package. However, can you please share some more details like sample file and the code snippet with complete error details so that we can log an investigation ticket and share the ID with you.
try (var pdfContentEditor = new PdfContentEditor())
{
// Use fallback to standard font if character information is not present in PDF-file
ReplaceTextStrategy replaceTextStrategy = new ReplaceTextStrategy();
replaceTextStrategy.setNoCharacterBehavior(ReplaceTextStrategy.NoCharacterAction.UseStandardFont);
pdfContentEditor.setReplaceTextStrategy(replaceTextStrategy);
String tempFilename = tempFile.toString();
pdfContentEditor.bindPdf(tempFilename);
// Replace the placeholders in the PDF file
var substitutionCount = substitutePlaceholders(pdfContentEditor, substitutions);
Stacktrace
2025-01-23 08:52:23 Caused by: com.aspose.pdf.internal.ms.System.l7k: Format of font “Symbol” is not supported for new composite fonts
2025-01-23 08:52:23 at com.aspose.pdf.internal.l7v.lj.lf(Unknown Source) ~[aspose-pdf-24.12.jar:24.12]
2025-01-23 08:52:23 at com.aspose.pdf.internal.l7v.lj.(Unknown Source) ~[aspose-pdf-24.12.jar:24.12]
2025-01-23 08:52:23 at com.aspose.pdf.internal.l8y.lf.lI(Unknown Source) ~[aspose-pdf-24.12.jar:24.12]
2025-01-23 08:52:23 at com.aspose.pdf.internal.l7v.l1p.lI(Unknown Source) ~[aspose-pdf-24.12.jar:24.12]
2025-01-23 08:52:23 at com.aspose.pdf.internal.l7p.le.lI(Unknown Source) ~[aspose-pdf-24.12.jar:24.12]
2025-01-23 08:52:23 at com.aspose.pdf.internal.l7u.lI.lI(Unknown Source) ~[aspose-pdf-24.12.jar:24.12]
2025-01-23 08:52:23 at com.aspose.pdf.internal.l7h.lI.lI(Unknown Source) ~[aspose-pdf-24.12.jar:24.12]
2025-01-23 08:52:23 at com.aspose.pdf.TextSegment.setText(Unknown Source) ~[aspose-pdf-24.12.jar:24.12]
2025-01-23 08:52:23 at com.aspose.pdf.TextFragment.setText(Unknown Source) ~[aspose-pdf-24.12.jar:24.12]
2025-01-23 08:52:23 at com.aspose.pdf.facades.PdfContentEditor.replaceText(Unknown Source) ~[aspose-pdf-24.12.jar:24.12]
2025-01-23 08:52:23 at com.aspose.pdf.facades.PdfContentEditor.replaceText(Unknown Source) ~[aspose-pdf-24.12.jar:24.12]
2025-01-23 08:52:23 at com.aspose.pdf.facades.PdfContentEditor.replaceText(Unknown Source) ~[aspose-pdf-24.12.jar:24.12]
See below for a code example. See also attached pdf
Tried replaceText with and without TextState-argument (which is created with an existing font name).
All attempts result in: “Format of font “Symbol” is not supported for new composite fonts” KarolisTestDoc.pdf (84.4 KB)
private void test()
{
try (var pdfContentEditor = new PdfContentEditor())
{
// Use fallback to standard font if character information is not present in PDF-file
ReplaceTextStrategy replaceTextStrategy = new ReplaceTextStrategy();
replaceTextStrategy.setNoCharacterBehavior(ReplaceTextStrategy.NoCharacterAction.UseStandardFont);
pdfContentEditor.setReplaceTextStrategy(replaceTextStrategy);
String tempFilename = "test.pdf";
pdfContentEditor.bindPdf(tempFilename);
int substitutionCount = 0;
while (pdfContentEditor.replaceText("{toReplace}", "Approved by Author "))
{
substitutionCount++;
}
TextState textState = new TextState("DejaVu Sans");
while (pdfContentEditor.replaceText("{toReplace}", "Approved by Author ", textState))
{
substitutionCount++;
}
if (substitutionCount > 0)
{
// Save the updated PDF document
pdfContentEditor.save(tempFilename);
}
}
}
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): PDFJAVA-44681
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
Issue seems related to Linux. Which does not pickup the setting: ReplaceTextStrategy.NoCharacterAction.UseStandardFont
When I use a PDF with a font not installed on my Windows system, it does an automatic fallback, to a default font.
Also generating a new TextState with correct font the behaviour does not changed when running under Linux.
Thanks for sharing this information. We will investigate from this perspective and let you know as soon as the ticket is resolved. Please be patient and spare us some time.
This does not resolve the issue, but it changes the stacktrace. It would be really nice if you are able to define some work-around.
Is there a different function that allows modifying text (without these font issues) in an existing PDF.
Next to that is there documentation on how next classes work together when using PdfContentEditor (they all seem related but there dependencies are unclear to me):
Caused by: java.lang.NullPointerException: Cannot invoke "com.aspose.pdf.internal.l7v.l0n.lf()" because "<parameter3>" is null
at com.aspose.pdf.internal.l7v.lj.lI(Unknown Source) ~[aspose-pdf-24.12.jar:24.12]
at com.aspose.pdf.internal.l7v.lj.<init>(Unknown Source) ~[aspose-pdf-24.12.jar:24.12]
at com.aspose.pdf.internal.l8y.lf.lI(Unknown Source) ~[aspose-pdf-24.12.jar:24.12]
at com.aspose.pdf.internal.l7v.l1p.lI(Unknown Source) ~[aspose-pdf-24.12.jar:24.12]
at com.aspose.pdf.internal.l7p.le.lI(Unknown Source) ~[aspose-pdf-24.12.jar:24.12]
at com.aspose.pdf.internal.l7u.lI.lI(Unknown Source) ~[aspose-pdf-24.12.jar:24.12]
at com.aspose.pdf.internal.l7h.lI.lI(Unknown Source) ~[aspose-pdf-24.12.jar:24.12]
at com.aspose.pdf.TextSegment.setText(Unknown Source) ~[aspose-pdf-24.12.jar:24.12]
at com.aspose.pdf.TextFragment.setText(Unknown Source) ~[aspose-pdf-24.12.jar:24.12]
at com.aspose.pdf.facades.PdfContentEditor.replaceText(Unknown Source) ~[aspose-pdf-24.12.jar:24.12]
at com.aspose.pdf.facades.PdfContentEditor.replaceText(Unknown Source) ~[aspose-pdf-24.12.jar:24.12]
at com.bwise.logic.integrations.documentconverter.PdfTextReplacer.replaceText(PdfTextReplacer.java:311) ~[storage-integrations-5.8-SNAPSHOT.jar:5.8-SNAPSHOT]
at com.bwise.logic.integrations.documentconverter.PdfTextReplacer.substitutePlaceholders(PdfTextReplacer.java:298) ~[storage-integrations-5.8-SNAPSHOT.jar:5.8-SNAPSHOT]
More feedback.
In essence I can get the application to work.
Only requirement seems to be that the font times.ttf is available.
But, only the times.ttf from Microsoft seems to work. If that file is not found or it is not the expected TTF. I get the error: “Format of font “Symbol” is not supported for new composite font”
Putting the symbol.ttf in Linux does not solve the issue, adding times.ttf does solve the problem.
Sure, we have noted and taken this feedback into our account. We will consider it while investigating the ticket and let you know as soon as it is resolved. Please be patient and spare us some time.
We are sorry for the inconvenience.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.