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

.NET Core, DocIO and PDF Conversion - fonts completely messed up

Hello!
I'm trying to generate a PDF-File -> I use DocIO to execute a MailMerge operation and then convert it to PDF and send it to my client to view it.
The template I'm using has a custom font which is installed on my PC but the result is just a mess. I couldn't find anything about embedding fonts
when using MailMerge / a template file.
This is what the result looks like:

What seems to be the problem here?
This is my code:
[HttpPost] public async Task Arbeitsvertrag([FromBody]CreateArbeitsvertragModel model) { string basePath = _hostingEnvironment.WebRootPath; string template = basePath + @"/Vorlagen/Arbeitsvertrag/Vollzeit/Arbeitsvertrag_VZ.docx"; FileStream fileStream = new FileStream(template, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); WordDocument document = new WordDocument(fileStream, FormatType.Docx); List employeeData = await GetEmployeeDataVZ(model); MailMergeDataTable mailMergeDataTable = new MailMergeDataTable("Mitarbeiter", employeeData); document.MailMerge.ExecuteGroup(mailMergeDataTable); DocIORenderer render = new DocIORenderer(); PdfDocument pdfDocument = render.ConvertToPDF(document); render.Dispose(); document.Dispose(); MemoryStream stream = new MemoryStream(); pdfDocument.Save(stream); stream.Position = 0; pdfDocument.Close(true); string contentType = "application/pdf"; return new FileStreamResult(stream, contentType); }

13 Replies

PK Prakash Kumar D Syncfusion Team December 5, 2018 09:53 AM UTC

Hi Paul, 
 
Thank you for contacting Syncfusion support. Please find the details below 
 
Regarding the mess with resultant document: 
On analysis the given screenshot, we suspect that the issue might be with embed fonts. Kindly share us the input document to analyze further from our side and provide you the prompt solution at earliest. 
 
Note: The documents shared will not be disclosed and is only for the purpose to reproduce the issue. We assure you that the document will be deleted from our side once the issue is resolved. 
 
Regarding the query I couldn't find anything about embedding fonts 
We have already implemented the API to embed fonts in PDF document while converting Word document into Pdf using DocIORenderer. It will be available in our upcoming 2018 Volume 4 release at the mid of December 2018 tentatively.

We suggest you set the below API to embed the fonts in converted PDF which will be available in 2018 Volume 4 release. Please refer the below code snippet: 
 
//Instantiates DocIORenderer instance for Word to PDF conversion  
DocIORenderer renderer = new DocIORenderer();  
//Sets EmbedFonts property as true, to embed fonts in resultant PDF  
renderer.Settings.EmbedFonts = true;  
//Sets EmbedCompleteFonts property as true, to embed complete font information in converted PDF  
renderer.Settings.EmbedCompleteFonts = true;  
  
 
Regards, 
Prakash Kumar 



PK Paul Kocher December 5, 2018 10:44 AM UTC

Hello Prakash,

where can I send the document to? Do you need the font for it, too?


PK Prakash Kumar D Syncfusion Team December 6, 2018 10:14 AM UTC

Hi Paul, 
 
Regarding where can I send the document: 
You can send the document to support@syncfusion.com with the forum Id in subject line.  
 
Regarding Do you need the font for it, too: 
Yes, kindly share the fonts used in the input Word document. It will be more helpful to analyze at our end and provide you the solution at earliest. 
 
Regards, 
Prakash Kumar 



PV Pieter van Kampen replied to Prakash Kumar D December 6, 2018 04:05 PM UTC

Hi Paul, 
 
Thank you for contacting Syncfusion support. Please find the details below 
 
Regarding the mess with resultant document: 
On analysis the given screenshot, we suspect that the issue might be with embed fonts. Kindly share us the input document to analyze further from our side and provide you the prompt solution at earliest. 
 
Note: The documents shared will not be disclosed and is only for the purpose to reproduce the issue. We assure you that the document will be deleted from our side once the issue is resolved. 
 
Regarding the query I couldn't find anything about embedding fonts 
We have already implemented the API to embed fonts in PDF document while converting Word document into Pdf using DocIORenderer. It will be available in our upcoming 2018 Volume 4 release at the mid of December 2018 tentatively.

We suggest you set the below API to embed the fonts in converted PDF which will be available in 2018 Volume 4 release. Please refer the below code snippet: 
 
//Instantiates DocIORenderer instance for Word to PDF conversion  
DocIORenderer renderer = new DocIORenderer();  
//Sets EmbedFonts property as true, to embed fonts in resultant PDF  
renderer.Settings.EmbedFonts = true;  
//Sets EmbedCompleteFonts property as true, to embed complete font information in converted PDF  
renderer.Settings.EmbedCompleteFonts = true;  
  
 
Regards, 
Prakash Kumar 


Hi, I have the same thing when doing the conversation in asp.net core on a Windows Server 2012 R2 machine. Strangely enough, there is a difference when I generate the document and download it, compared to when a customer does it. Mine looks good, the one from the customer is scrambled, see the attached redacted screenshot. The generation is done on the same website in both cases. 
The font of both body and headers is Calibri.


Is there a beta for the Volume 4 so I can try the font embedding?

Attachment: scrambled_calibri_cb0e7682.zip


PV Pieter van Kampen December 7, 2018 08:30 AM UTC

I have sent you a word document (calibri), its converted PDF, and how it looks scrambled at my customers' PC. As my customer stores it for later evidence, I think it is better to always embed the fonts in a PDF document.

Thanks

Pieter


PK Prakash Kumar D Syncfusion Team December 11, 2018 10:52 AM UTC

Hi Paul, 
  
Thank you for updating us.  
  
We can reproduce the reported issue from the shared information and it was fixed in our 2018 volume 4 beta release. We suggest you upgrade to our latest version (16.40.40) of Essential Studio which has more bug fixes and enhancements which is available for download under the following link. 
  
 
 
Kindly try the above and let us know whether the issues are resolved at your end. 
 
Regards, 
Prakash Kumar 



PV Pieter van Kampen December 12, 2018 12:40 AM UTC

Thank you, the conversion works, I am collecting confirmation whether it solves the problem on the customer end. 

Can you point me where I can get the license key for the beta? It is not in my account.


PK Prakash Kumar D Syncfusion Team December 12, 2018 06:41 AM UTC

Hi Paul,  
 
Thank you for your interest in Syncfusion products. Please find the below KB link to get the license key 
 
You can get the license key from following link.  
  
  
  
  
 
 
Regards, 
Prakash Kumar 



PK Paul Kocher December 17, 2018 10:16 AM UTC

Hello Prakash,

I tried the conversion with the beta version. Part of it is ok - the font successfully gets embedded BUT the line-spacing is off. It looks like there's no space between the lines at all plus there are some characters like parenthesis which look odd.

Is there a setting or anything? Also I sent my original document via email. The person you were replying to is someone else so maybe check the email you received with my doc/font.

This is how it is supposed to look (my original .docx):




This is how it looks:



I wouldn't really care about that but the problem is I'm using lines to place data on it. After conversion this is what it looks like:





Any idea?


PV Pieter van Kampen December 17, 2018 10:21 AM UTC

Just wanted to confirm that for me the beta works fine. I don't have the line issue @Paul Kocher has described in the previous post. 

I used this for the conversion

            DocIORenderer render = new DocIORenderer();
            
            render.Settings.EmbedFonts = true;
            render.Settings.PdfConformanceLevel = PdfConformanceLevel.Pdf_A1B;
            render.Settings.AutoTag = true;
            PdfDocument pdfDocument = render.ConvertToPDF(doc);


PK Prakash Kumar D Syncfusion Team December 17, 2018 04:50 PM UTC

Hi Pieter, 
 
Thank you for updating us. We glad that the issue is resolved at your end.  
 
Regards, 
Prakash Kumar 
 
Hi Paul, 
 
Thank you for using Syncfusion products. 
 
We are using SkiaSharp Graphics library to layout and render the content in Word to PDF conversion in ASP.NET Core. The text height calculation of SkiaSharp is not exactly equal to GDI+ library (.Net Framework), so that line spacing is not proper in generated PDF. Already, we have planned to enhance the Word to PDF conversion in portable platforms for 2019 Volume 1 main release which will be available by March 2019 tentatively. 
 
Regards, 
Prakash Kumar


PK Paul Kocher December 18, 2018 06:22 AM UTC

Hello Prakash,

thanks for your answer. That's no problem. I will be using plain .docx until this is fixed.

Also thanks to you Pieter for sharing your settings - didn't work but still

Paul


PK Prakash Kumar D Syncfusion Team December 18, 2018 06:52 AM UTC

Hi Paul, 
 
Thank you for updating us. We will let you know once the 2019 volume 1 main release is rolled out.   
 
Regards, 
Prakash Kumar 


Loader.
Up arrow icon