Corrupt Images when running in azure function

Hi. I'm having an issue related to this question https://www.syncfusion.com/forums/167785/trying-to-convert-word-doc-to-pdf. The winform solution works great locally, but once I deployed it into an azure function I'm seeing the corrupted images again. The flow is:

  1. I upload a word doc with the images as word objects in it
  2. Click a view link which calls an azure function that downloads the word doc from blob storage
  3. Read it in as a SyncFusion worddocument
  4. Convert it to a syncfusion PDF using DocToPDFConverter
  5. Finally return the base64 stream.

If I call this function locally it works flawlessly, but in the hosted version the corrupt image (red X) appears again. Another interesting thing to note is the page layout also changes, some text moves to different pages, and the overall quality of the converted document seems to get worse, again only in the hosted version.

I was inspecting the base64 string that the local and hosted version produces and the hosted version produces a much shorter base64 string, almost as if it was truncated. Additionally, I can take both base64 strings and read them into a file locally and again the hosted version displays the corrupted image where the local version displays the correct image.

Could this possibly be because I'm still using the free version of syncfusion? We are planning on purchasing it, but we just haven't done so yet because we're still in the evaluation process. Thank you for your help!



8 Replies

LC Luke Carlson August 5, 2021 09:05 PM UTC

I also tried doing the conversion process in another function using the .Net framework, but the images still appear as red X's. Again though, if I run the .Net framework function locally everything works. 



LB Lokesh Baskar Syncfusion Team August 6, 2021 05:39 PM UTC

Hi Luke,

Thank you for your update.

On further analyzing, we have found metafile images (*.emf, *.wmf) that are not supported in Azure App Service and Azure functions while converting a Word document with metafile images into PDF or Image. And also, this is one of the known limitations in Azure App Service and Azure functions. In this scenario, internally, Essential DocIO preserves RedX images in the same size during the Word to PDF or Image conversions.

To preserve the expected images in the PDF, we suggest you convert the metafile image formats to bitmap image format (JPEG or PNG) and then perform Word to PDF conversion.

Note: When the Word document contains metafile images (*.emf or *.wmf), we recommend using Azure Cloud Service.

Please let us know if you have any other questions.

Regards,
Lokesh B



LC Luke Carlson August 6, 2021 07:34 PM UTC

Hi Lokesh!


If I use the Azure Cloud Service will I still need to convert to JPEG or PNG first? Also, if possible, could you explain why you suggest using the Azure Cloud Service? Is it for performance?


I can try to figure it out myself, but would it be possible for you to provide an example of how to convert the .emf/.wmf images to JPEG/PNG? I can't convert them directly in the word document as they are coming from outside sources. So is there a way to convert them with SyncFusion? 


Thank you for the quick reply and all of your help!



LB Lokesh Baskar Syncfusion Team August 9, 2021 11:38 AM UTC

Hi Luke,

Thank you for your update.

No, you need not to convert to from .emf/.wmf to JPEG or PNG when you are using Azure Cloud Service. Because azure cloud service supports the meta file images too. Please refer the below UG documentation link to know which one is better in word to PDF conversion.
https://help.syncfusion.com/file-formats/docio/faq#which-one-is-better-azure-app-service-or-cloud-service-for-word-to-pdfimage-using-docio

Please let us know if you have any other questions.

Regards,
Lokesh B



LC Luke Carlson August 10, 2021 05:13 PM UTC

The cloud service in the .Net framework is working flawlessly! Thank you for your help! 


Quick question is there anyway to speed up the conversion process? 



LB Lokesh Baskar Syncfusion Team August 11, 2021 10:12 AM UTC

Hi Luke,


Thank you for your update.


To faster the Word to PDF conversion process, we suggest you to follow all the below solutions at your end.
1. Set true for 
PreserveOleImageAsImage before opening the Word document. This will optimize the memory usage if your input Word document has embedded ole image. You can refer to this link to know more about this.
2. Set true for 
OptimizeIndenticalImages API, to optimize the memory usage of identical (duplicate) images during Word to PDF conversion.


Please refer the below code example which shows how to use above APIs:  
 
//Creates an Word document instance   
WordDocument wordDocument = new WordDocument();   
//Sets flag to preserve embedded Ole image as normal image while opening document   
wordDocument.Settings.PreserveOleImageAsImage = true;   
//Loads or opens an existing Word document   
wordDocument.Open("Template.docx", FormatType.Docx);   
//Initializes the ChartToImageConverter for converting charts during Word to pdf conversion   
wordDocument.ChartToImageConverter = new ChartToImageConverter();   
//Creates an instance of the DocToPDFConverter   
DocToPDFConverter converter = new DocToPDFConverter(); 
//Sets the flag to optimize memory usage of identical (duplicate)   
converter.Settings.OptimizeIdenticalImages = true;   
//Converts Word document into PDF document   
PdfDocument pdfDocument = converter.ConvertToPDF(wordDocument);   
//Dispose the resources   
converter.Dispose();   
//Saves the PDF file    
pdfDocument.Save("WordtoPDF.pdf");   
//Closes the instance of document objects   
pdfDocument.Close(true);   
wordDocument.Close(); 

Could you please try the above code snippet at your end and provide us confirmation. Or if you have any concerns about this means, then share your input document. Thereby, we will check on the feasible solution and will provide you the appropriate solution at the earliest.


Please let us know if you have any other questions.


Regards,
Lokesh B
 




LC Luke Carlson August 11, 2021 11:41 AM UTC

Thanks Lokesh! I'll check this out and let you know. 



LB Lokesh Baskar Syncfusion Team August 12, 2021 06:18 AM UTC

Hi Luke,

Thank you for your update.

We will wait until hear back from you.

Regards,
Lokesh B


Loader.
Up arrow icon