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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Enable custom font on PDF document

Thread ID:

Created:

Updated:

Platform:

Replies:

143817 Apr 5,2019 05:53 PM UTC Oct 23,2019 12:59 PM UTC ASP.NET Core - EJ 2 6
loading
Tags: DocIO
Szymon Kozlowski
Asked On April 5, 2019 05:53 PM UTC

Hi!
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:

            Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense(_appSettings.SyncfusionLicenseKey);

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

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

            MemoryStream memoryStream2 = new MemoryStream();
            pdfDocument.Save(memoryStream2);
            pdfDocument.Close();


Abirami Varadharajan [Syncfusion]
Replied On 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. 

Regards, 
Abirami 



Szymon Kozlowski
Replied On 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.Close();

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

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

            renderer.Dispose();

            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);

Abirami Varadharajan [Syncfusion]
Replied On 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 (16.4.0.42).  
  
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.  

Regards, 
Abirami 


Abirami Varadharajan [Syncfusion]
Replied On 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

Regards, 
Abirami 


Matt Symes
Replied On 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.


Vijayasurya Anandhan [Syncfusion]
Replied On 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.
https://www.syncfusion.com/downloads/support/forum/143817/ze/WordToPDF_CustomFont1771439118.zip

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.

Regards,
Vijayasurya A


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon