How to convert the word document with non-standard font to PDF

With the help of Spire.Doc, we can use the method doc.SaveToFile () to convert the word document files to PDF format easily. When the word documents contains non-standard font, we will find that we can't pick up the non-standard font in the result PDF page. In fact, Spire.Doc also supports to convert the word document with non-standard font to PDF successfully. This article will show you how to remain the non-standard font on the result PDF file no matter I install the font or not in my server.

Here comes to the code snippets. Firstly, please the word document with the non-standard font Bar-Code 39:

How to convert the word document with non-standard font to PDF

Without the special setting when convert it to PDF, the barcode font will be replaced by text in the result PDF file. View the results as below:

How to convert the word document with non-standard font to PDF

Now I will show you the code of how to render word document to PDF, where the font won't be changed.

Step 1: Create a word document and load from file:

Document doc = new Document();
doc.LoadFromFile("sample.docx");

Step 2: When convert to PDF file, set the property IsEmbeddedAllFonts as true.

ToPdfParameterList parms = new ToPdfParameterList()
    {
        IsEmbeddedAllFonts = true
    };

Step 3: Save the document to file and apply the style in the step 2.

doc.SaveToFile("result.pdf", parms);

If we don't want to install the font on our server machine, we can use the following method to apply the fonts and save it to PDF successfully.

{
    Document doc = new Document();
    doc.LoadFromFile("sample.docx");

    ToPdfParameterList parms = new ToPdfParameterList()
    {
        PrivateFontPaths = new List()
       {
          new PrivateFontPath("Bar-Code 39","..\\..\\Code39.ttf")
       }
    };
    doc.SaveToFile("result.pdf", parms);
}

Effective screenshot:

How to convert the word document with non-standard font to PDF