We have a docx file in which Arial MT, Times New Roman fonts are used but upon conversion to pdf we see the following issues :
- everything is coming in Arial font and not Arial MT
- The header has correct font but it has additional “Itallic” style applied to it.
All the used fonts are provided during conversion.
We are using Groupdocs.Conversion for java 25.3 version on a linux machine.
Attaching the docx and pdf files for your reference.
testSEFE03.docx (1.2 MB)
testSEFE03.pdf (1.6 MB)
@kswati2206
To address the font issues you’re experiencing during the conversion of your DOCX file to PDF using GroupDocs.Conversion for Java, you can utilize font substitution options to ensure that the correct fonts are applied. Here’s how you can specify font substitutions in your conversion process:
-
Disable Auto Font Substitution: Set the AutoFontSubstitution
property to false
to prevent the library from automatically substituting fonts.
-
Specify Default Font and Font Substitutes: You can define a default font and create a list of font substitutes to map the fonts used in your DOCX file to the desired fonts in the PDF output.
Here’s a sample code snippet demonstrating how to implement these options:
import com.groupdocs.conversion.Converter;
import com.groupdocs.conversion.contracts.FontSubstitute;
import com.groupdocs.conversion.options.convert.PdfConvertOptions;
import com.groupdocs.conversion.options.load.WordProcessingLoadOptions;
import java.util.ArrayList;
import java.util.List;
public class ConvertDocxToPdf {
public static void main(String[] args) {
String sourceFilePath = "path/to/your/testSEFE03.docx";
String outputFilePath = "path/to/output/testSEFE03.pdf";
// Create load options with font substitution
WordProcessingLoadOptions loadOptions = new WordProcessingLoadOptions();
loadOptions.setAutoFontSubstitution(false);
loadOptions.setDefaultFont("Arial"); // Set a default font if needed
List<FontSubstitute> fontSubstitutes = new ArrayList<>();
fontSubstitutes.add(FontSubstitute.create("Arial MT", "Arial")); // Map Arial MT to Arial
fontSubstitutes.add(FontSubstitute.create("Times New Roman", "Times New Roman")); // Ensure Times New Roman is used
loadOptions.setFontSubstitutes(fontSubstitutes);
// Initialize the converter
try (Converter converter = new Converter(sourceFilePath, () -> loadOptions)) {
PdfConvertOptions options = new PdfConvertOptions();
converter.convert(outputFilePath, options);
System.out.println("Conversion completed successfully.");
} catch (Exception e) {
e.printStackTrace();
}
}
}
Key Points:
- Font Substitution: This code maps “Arial MT” to “Arial” to ensure that the correct font is used in the PDF. You can adjust the mappings based on your specific needs.
- Italics Issue: If the header is still appearing in italics, ensure that the styles in your DOCX file are correctly set and that the conversion options are not altering them.
Make sure to replace the file paths with the actual paths of your DOCX and desired output PDF files. This approach should help resolve the font issues you are encountering during the conversion process.
If you continue to experience problems, consider checking the documentation for any additional settings that may affect font rendering in your specific environment.
Sources:
[1]: Convert WordProcessing Document to PDF with Font Substitution
Attaching the screenshot of the issue
image.jpg (91.2 KB)
I checked in the docx file and the fonts are correct.
Hello @kswati2206 ,
Thank you for contacting us.
We have investigated your scenario and would like to clarify a few points on your side.
Could you please let us know how you are using Windows fonts during the conversion process?
Have you installed them locally, or are you simply trying to add the required fonts using the ConverterSettings.setFontDirectories()
method?
To avoid font-related issues during conversion, we strongly recommend installing Windows fonts locally.
As a reference, you can check this documentation for more details.
This step is important because when you attempt to add fonts individually via the setFontDirectories()
property and then view the converted document locally, your viewer (e.g., Adobe Reader) may not correctly render the font names.
In most cases, the viewer relies on locally installed fonts, and if (as in your case) the font Arial is installed locally while you try to add ArialMT via setFontDirectories()
, the viewer will display the font name simply as Arial.
We have also tested the scenario on our side using GroupDocs.Conversion 25.5, and the converted document appears identical to the original.
We’ve attached the output and a screenshot — please try downloading it and verify it on your end.
output_docker_withFonts.pdf (1.7 MB)
Screenshot_1.png (103.4 KB)
We are providing the fonts using the SetFontDirectory option and have the following set of fonts for this Org, could you please try reproducing this issue by providing all of these?
Arial_fonts.zip (2.2 MB)
Fonts_others.zip (2.0 MB)
@kswati2206 ,
Indeed, there is an issue with the style of the Times New Roman font you are attempting to pass via the setFontDirectories()
parameter (Screenshot_2.png (106.7 KB)).
However, we added the required fonts on our side, and the result matches the original document.
Please try adding those fonts as well (TNR.zip (2.2 MB)).
Regarding the Arial MT font — as you can see in the Screenshot_2.png, it is present in the document and its name is displayed correctly.
As far as we understand, you are viewing the result on macOS, while the conversion itself is performed on Linux.
In this case, we recommend that you always check two things when viewing the document in Adobe Reader on macOS:
- Use the Ctrl + D shortcut in Adobe Reader to inspect the fonts embedded in the document. (Screenshot_3.png (90.9 KB))
- If Adobe Reader displays a different font name or style (which often happens with Windows fonts), double-check whether the font is available in the dropdown list, as shown in the attached screenshot (Screenshot_4.png (100.2 KB)).
It’s possible that the font is correctly embedded in the document, but Adobe Reader renders it incorrectly due to how it handles font substitution or style mapping on macOS.
After using the Times New Roman font provided by you the Itallic issue is resolved but the two column layout is breaking now. It could be related to font files.
I will check other font files too if there could be any issues with them.
@kswati2206 ,
If you have any further questions, please don’t hesitate to contact us.