Aspose words need type1 font, embedded mode and default font type

Hi, we have a requirement where we need an rtf file to be converted to pdf. The pdf needs to have Arial font, with Type-1 font type and the fonts need to be in embedded mode.
We tried the settings us options.setEmbedFullFonts(true) and options.setUseCoreFonts(true). We are unable to use both these settings as coreFonts settings is disabling embedded mode(embedded mode works without core fonts setting).
We are unable to set the default font name to Arial.

FontSettings fontSettings = FontSettings.getDefaultInstance();
          
fontSettings.setFontsSources(
        new FontSourceBase[] { new SystemFontSource(), new FolderFontSource("src/main/resources/Fonts/", true) });
fontSettings.getSubstitutionSettings().getFontConfigSubstitution().setEnabled(true);
fontSettings.getSubstitutionSettings().getDefaultFontSubstitution().setDefaultFontName("Arial");
LoadOptions lo = new LoadOptions();
lo.setFontSettings(fontSettings); 

Can you please provide some guidance here?

@ramachandra1988 Upon conversion to PDF Aspose.Words uses the fonts specified in the source document. If the specified fonts are not available the missed fonts are substituted. So if Arial font is no physically available in the specified fonts folder or is not specified in the source document, it will not be embedded into the output PDF document.
Could you please attach your source RTF document and the expected output (is possible)? We will check the issue and provide you more information.

test.docx (17.8 KB)
Hi this attachment is in docx but original file is rtf which is not allowed to upload here. We need the conversion of this file to pdf. We need

  1. File format needs to be Arial
  2. File needs to be in embedded mode.
  3. It needs to have type-1 core font type.

@ramachandra1988 In the attached document Times New Roman fonts is used. So you need to change the font before conversion it to PDF. You can use DocumentVisitor to achieve this. For example see the following code:

Document doc = new Document(@"C:\Temp\in.docx");
FontChanger changer = new FontChanger("Arial");
doc.Accept(changer);
doc.Save(@"C:\Temp\out.pdf");
class FontChanger : DocumentVisitor
{
    public FontChanger(string fontName)
    {
        mFontName = fontName;
    }

    /// <summary>
    /// Called when a FieldEnd node is encountered in the document.
    /// </summary>
    public override VisitorAction VisitFieldEnd(FieldEnd fieldEnd)
    {
        //Simply change font name
        ResetFont(fieldEnd.Font);
        return VisitorAction.Continue;
    }

    /// <summary>
    /// Called when a FieldSeparator node is encountered in the document.
    /// </summary>
    public override VisitorAction VisitFieldSeparator(FieldSeparator fieldSeparator)
    {
        ResetFont(fieldSeparator.Font);
        return VisitorAction.Continue;
    }

    /// <summary>
    /// Called when a FieldStart node is encountered in the document.
    /// </summary>
    public override VisitorAction VisitFieldStart(FieldStart fieldStart)
    {
        ResetFont(fieldStart.Font);
        return VisitorAction.Continue;
    }

    /// <summary>
    /// Called when a Footnote end is encountered in the document.
    /// </summary>
    public override VisitorAction VisitFootnoteEnd(Footnote footnote)
    {
        ResetFont(footnote.Font);
        return VisitorAction.Continue;
    }

    /// <summary>
    /// Called when a FormField node is encountered in the document.
    /// </summary>
    public override VisitorAction VisitFormField(FormField formField)
    {
        ResetFont(formField.Font);
        return VisitorAction.Continue;
    }

    /// <summary>
    /// Called when a Paragraph end is encountered in the document.
    /// </summary>
    public override VisitorAction VisitParagraphEnd(Paragraph paragraph)
    {
        ResetFont(paragraph.ParagraphBreakFont);
        return VisitorAction.Continue;
    }

    /// <summary>
    /// Called when a Run node is encountered in the document.
    /// </summary>
    public override VisitorAction VisitRun(Run run)
    {
        ResetFont(run.Font);
        return VisitorAction.Continue;
    }

    /// <summary>
    /// Called when a SpecialChar is encountered in the document.
    /// </summary>
    public override VisitorAction VisitSpecialChar(SpecialChar specialChar)
    {
        ResetFont(specialChar.Font);
        return VisitorAction.Continue;
    }

    private void ResetFont(Aspose.Words.Font font)
    {
        font.Name = mFontName;
    }

    private string mFontName = "Arial";
}

FontChanger is not available in Java. We need similar class in Java. Also we need to know if Type-1 font style and font embedding can be done?

@ramachandra1988 Here is Java implementation of the FontChanger class:

public class FontChanger extends DocumentVisitor {
    
    public FontChanger(String fontName)
    {
        mFontName = fontName;
    }

    /// <summary>
    /// Called when a FieldEnd node is encountered in the document.
    /// </summary>
    @Override
    public int visitFieldEnd(FieldEnd fieldEnd)
    {
        //Simply change font name
        resetFont(fieldEnd.getFont());
        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Called when a FieldSeparator node is encountered in the document.
    /// </summary>
    @Override
    public int visitFieldSeparator(FieldSeparator fieldSeparator)
    {
        resetFont(fieldSeparator.getFont());
        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Called when a FieldStart node is encountered in the document.
    /// </summary>
    @Override
    public int visitFieldStart(FieldStart fieldStart)
    {
        resetFont(fieldStart.getFont());
        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Called when a Footnote end is encountered in the document.
    /// </summary>
    @Override
    public int visitFootnoteEnd(Footnote footnote)
    {
        resetFont(footnote.getFont());
        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Called when a FormField node is encountered in the document.
    /// </summary>
    @Override
    public int visitFormField(FormField formField)
    {
        resetFont(formField.getFont());
        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Called when a Paragraph end is encountered in the document.
    /// </summary>
    @Override
    public int visitParagraphEnd(Paragraph paragraph)
    {
        resetFont(paragraph.getParagraphBreakFont());
        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Called when a Run node is encountered in the document.
    /// </summary>
    @Override
    public int visitRun(Run run)
    {
        resetFont(run.getFont());
        return VisitorAction.CONTINUE;
    }

    /// <summary>
    /// Called when a SpecialChar is encountered in the document.
    /// </summary>
    @Override
    public int visitSpecialChar(SpecialChar specialChar)
    {
        resetFont(specialChar.getFont());
        return VisitorAction.CONTINUE;
    }

    private void resetFont(Font font)
    {
        font.setName(mFontName);
    }

    private String mFontName = "Arial";
}

Aspose.Words does not support Type 1 fonts. Please see our documentation for more information:
https://docs.aspose.com/words/java/manipulate-and-substitute-truetype-fonts/#differences-in-processing-of-font-formats-in-asposewords-and-microsoft-word

Could you please clarify why you need type 1 fonts to be embedded into output PDF document

We have a use case where we send pdf fonts to print and mail out. The printer’s requirement is Type-1 font type with embedded subset. Is there a way to achieve this?

@ramachandra1988 Unfortunately, there is no way to embed type1 fonts into PDF documents using Aspose.Words. Type 1 fonts is a deprecated format within the font industry. Adobe will disable support for authoring with Type 1 fonts in January 2023. Microsoft has already dropped support of Type1 fonts in MS Office 2013 for Windows.
Considering the above as well as a serious resource costs for development and maintenance, work on this feature looks impractical.

In your case, you can try using Aspose.PDF or other PDF processing library for postprocessing PDF documents produced by Aspose.Words to embed type1 fonts.

A post was split to a new topic: Aspose.PDF need type1 font embedded mode