Fonts not displaying correctly when converting DOCX to PDF

I am doing a word merge, and after that I convert the document to PDF.

The word document is using "Lucida Handwriting" font, and it is displayed correctly when I output to DOCX:



After this, I convert to PDF using code:

                // Save doc as DOCX to a memory stream

                MemoryStream inter_ret_file = new MemoryStream();

                document.Save(inter_ret_file, FormatType.Docx);


                // Read the word document

                WordDocument intermediateDocument = new WordDocument(inter_ret_file, Syncfusion.DocIO.FormatType.Docx);

                document.Close();

                inter_ret_file.Close();


                //Converts Word document into PDF document

                DocToPDFConverter converter = new DocToPDFConverter();

                PdfDocument pdfDocument = converter.ConvertToPDF(intermediateDocument);


                MemoryStream ret_file = new MemoryStream();

                pdfDocument.Save(ret_file);


                pdfDocument.Close();

                pqp_template_stream.Close();


                byte[] bin_file = ret_file.ToArray();

                ret_file.Close();

                // save the binary data


The PDF displays the text in a different font, but if I edit the PDF, and click on the text, it says it's  "Lucida Handwriting" even though the text that is displayed is not that font!



Please help me fix this!


1 Reply

LB Lokesh Baskar Syncfusion Team June 29, 2021 05:23 PM UTC

Hi Michael,  

Thank you for contacting Syncfusion support. 

On further analysis on the given code snippet, to overcome this rendering issue we have to enable the EmbedFonts property in converter settings. Please refer the highlighted code given below.


 
//Open the file as Stream 
FileStream docStream = new FileStream("Test handwriting font.docx", FileMode.Open, FileAccess.Read); 
//Loads an existing Word document 
WordDocument intermediateDocument = new WordDocument(docStream ,FormatType.Docx); 
docStream.Close(); 
//Creates an instance of the DocToPDFConverter 
DocToPDFConverter converter = new DocToPDFConverter(); 
converter.Settings.EmbedFonts = true; 
//Converts Word document into PDF document 
PdfDocument pdfDocument = converter.ConvertToPDF(intermediateDocument); 
//Saves the PDF file  
MemoryStream outputStream = new MemoryStream(); 
pdfDocument.Save(outputStream); 
 //Closes the instance of document objects 
pdfDocument.Close(true); 
wordDocument.Close(); 
outputStream.Close(); 

Please refer the below link to know more details about embed font.
https://help.syncfusion.com/file-formats/docio/word-to-pdf#embedding-fonts

Please let us know if you have any other questions. 

Regards,  
Lokesh B 


Loader.
Up arrow icon