We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Enable custom font on PDF document

We have word template file which contains normal text with standard font and in header there is a barcode which is actually a font called Archon Code 39. Unfortunately after converting doc to pdf the barcode is not generated. How can we include this font to make pdf read this part of document correctly?

Code snippet below:


            byte[] buffer = Convert.FromBase64String(documentBody);
            MemoryStream memoryStream = new MemoryStream(buffer);
            WordDocument wordDocument = new WordDocument(memoryStream);
            memoryStream = new MemoryStream();
            wordDocument.Save(memoryStream, FormatType.Docx);

            DocToPDFConverter docToPDFConverter = new DocToPDFConverter();
            PdfDocument pdfDocument = docToPDFConverter.ConvertToPDF(wordDocument);

            MemoryStream memoryStream2 = new MemoryStream();

6 Replies

AV Abirami Varadharajan Syncfusion Team April 8, 2019 12:33 PM UTC

Hi Szymon, 

We suggest you to apply complete embed font to resolve issue at your end. We have a behaviour to embed font for the Unicode character and we will use ANSI Encoding for Non-Unicode character to reduce file size for normal character.  

So kindly apply below code before converting the document to resolve issue. 
Code example 
DocIORenderer docIoRenderer = new DocIORenderer(); 
docIoRenderer.Settings.EmbedCompleteFonts = true; 
For more details, please find the attached sample, in which we have created a word document with font “Archon Code 39” and converted the word document to PDF document. 

Please let us know if you have any concerns. 


SK Szymon Kozlowski April 9, 2019 08:30 AM UTC

Hi! Thank you for quick response and very nice sample. I want to use it in Azure Webjob and I use your code with small diffrence - I load the file from base64 string instead of FileStream and it is not working.. can you give me some more insights on this ? I include code below:

           byte[] buffer = Convert.FromBase64String(documentBody);
            MemoryStream memoryStream = new MemoryStream(buffer);

            WordDocument wordDocument = new WordDocument(memoryStream, FormatType.Automatic);
            DocIORenderer renderer = new DocIORenderer();
            renderer.Settings.EmbedCompleteFonts = true;
            MemoryStream wordStream = new MemoryStream();
            wordDocument.Save(wordStream, FormatType.Docx);
            wordStream.Position = 0;

            WordDocument newWordDocument = new WordDocument(wordStream, FormatType.Docx);

            PdfDocument pdfDocument = renderer.ConvertToPDF(newWordDocument);
            MemoryStream pdfStream = new MemoryStream();
            pdfStream.Position = 0;


            FileStreamResult fileStreamResult = new FileStreamResult(pdfStream, "application/pdf");

            byte[] bytes = new byte[fileStreamResult.FileStream.Length];
            fileStreamResult.FileStream.Read(bytes, 0, bytes.Length);
            return Convert.ToBase64String(bytes);

AV Abirami Varadharajan Syncfusion Team April 12, 2019 06:08 AM UTC

Hi Szymon, 

We are analyzing on the issue in azure environment. We will update you with further details on 15th April 2019. Alternatively, we suggest you the below approaches to achieve your requirement.  
Approach 1:  
Embed the fonts in Word document using Microsoft Word application and convert into PDF.

Please refer the below steps to meet your requirement:    
1. Open the Word document using Microsoft Word application and embedded the fonts in the document as per below screenshot:
In Microsoft Word application, go to File-> Options -> Save -> Check “Embed fonts in the file” option. 

Thus, the fonts used in the Word document are embedded into the file and moved along with the file to another machine. Essential DocIO provided support to preserve embedded fonts from the Word document into PDF while performing Word to PDF conversion from our 2018 Volume 4 release (  
Approach 2:     
If the font used in the Word document is missing in production machine, then DocIO uses “Microsoft Sans Serif” as default font for rendering the text in Word to PDF conversion.

From 2018 Volume 1 release (v16.1.0.24) onwards, DocIO provides support to customize font substitution using event while converting a Word document as PDF. Please find the linked sample, in which we have used font substitution feature which will helpful to achieve your requirement.  
Please let us know if you need further queries.  


AV Abirami Varadharajan Syncfusion Team April 15, 2019 11:23 AM UTC

Hi Szymon, 

On our further analysis, we have confirmed that the issue occurs when the specified font is not available in Azure environment. We have also ensured the same in windows environment. As mentioned in the previous update, we kindly request you to make use of the below approaches to achieve your requirement. 

  1. Embed font in the input document
  2. Font Substitution


MS Matt Symes October 22, 2019 07:10 PM UTC

We have the same issue. Is there any way we can deploy the fonts to a folder and have the Word->PDF Converter know to look in that folder for additional fonts for embedding? If this isn't available as a feature now, can it be considered for your roadmap please.

VA Vijayasurya Anandhan Syncfusion Team October 23, 2019 12:59 PM UTC

Hi Szymon,

Thank you for your update.

Yes, it is possible to achieve your requirement with "Deploying fonts to specific folder and use the folder for Word to PDF conversion" using our Font substitution feature. We have prepared a sample to meet your requirement which can be downloaded from the below link.

In this sample, we have done the following things:
1. Set the customer folder path to load the font stream.
2. Loaded the existing Word document.
3. Initializes the SubstituteFont event to perform font substitution during Word to PDF conversion.
4. Convert the Word document to PDF.  

Please let us know if you have any questions.

Vijayasurya A

Live Chat Icon For mobile
Up arrow icon