ConvertToPDF in .NET Core fails randomly

Hello,

I am following the example:

https://www.syncfusion.com/kb/8472/how-to-convert-a-word-document-to-pdf-in-asp-net-core-application

And with the following code:

souce and output are filepaths from my local pc

var streamInput = new FileStream(source, FileMode.Open);
var outputStream = new FileStream(output, FileMode.Create);

WordDocument wordDocument = new WordDocument();
wordDocument.Open(streamInput, FormatType.Docx);

DocIORenderer render = new DocIORenderer();
PdfDocument pdfDocument = render.ConvertToPDF(wordDocument);
pdfDocument.Save(outputStream);

streamInput.Dispose();
outputStream.Dispose();
wordDocument.Dispose();
render.Dispose();
pdfDocument.Close();

I am able to convert word documents to PDF.

But randomly, even with the same doc sometimes get converted and sometimes no.

I get the following error in the ConvertToPDF line:

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Any clue?

Regards,
Juan Antonio

17 Replies

MJ Mohanaselvam Jothi Syncfusion Team March 23, 2018 11:27 AM UTC

System.AccessViolationException occurred 
  HResult=0x80004003 
  Message=Attempted to read or write protected memory. This is often an indication that other memory is corrupt. 
  Source=<Cannot evaluate the exception source> 
  StackTrace: 
   at SkiaSharp.SkiaApi.sk_stream_read(IntPtr stream, IntPtr buffer, IntPtr size) 
   at SkiaSharp.SKStream.Read(IntPtr buffer, Int32 size) 
   at SkiaSharp.SKStream.Read(Byte[] buffer, Int32 size) 
   at Syncfusion.DocIORenderer.Drawing.FontExtension.get_FontStream() 
   at Syncfusion.DocIORenderer.Rendering.PDFDrawingContext.DrawString(String text, WCharacterFormat charFormat, WParagraphFormat paraFormat, RectangleF bounds, Single clipWidth, LayoutedWidget ltWidget) 
   at Syncfusion.DocIORenderer.Rendering.PDFDrawingContext.DrawTextRange(WTextRange txtRange, LayoutedWidget ltWidget, String text) 
   at Syncfusion.DocIORenderer.Rendering.PDFDrawingContext.Draw(IStringWidget stringWidget, LayoutedWidget ltWidget, String text) 
   at Syncfusion.DocIORenderer.Rendering.PDFDrawingContext.Draw(LayoutedWidget layoutedWidget, Boolean isHaveToInitLayoutInfo) 
   at Syncfusion.DocIORenderer.Rendering.PDFDrawingContext.Draw(LayoutedWidget layoutedWidget, Boolean isHaveToInitLayoutInfo) 
   at Syncfusion.DocIORenderer.Rendering.PDFDrawingContext.Draw(LayoutedWidget layoutedWidget, Boolean isHaveToInitLayoutInfo) 
   at Syncfusion.DocIORenderer.Rendering.PDFDrawingContext.Draw(LayoutedWidget layoutedWidget, Boolean isHaveToInitLayoutInfo) 
   at Syncfusion.DocIORenderer.Rendering.PDFDrawingContext.Draw(LayoutedWidget layoutedWidget, Boolean isHaveToInitLayoutInfo) 
   at Syncfusion.DocIORenderer.Rendering.PDFDrawingContext.Draw(Page page) 
   at Syncfusion.DocIORenderer.DocIORenderer.DrawDirectWordToPDF(DocumentLayouter layouter) 


To confirm whether you are facing same issue, kindly provide us the stack trace details of the error. Thereby we will analyze and update you more details.


Please let us know if you have any other questions.

Regards,
Mohanaselvam J
 



LO LOPES April 25, 2018 01:44 PM UTC

I'm getting same issue with version 16.1.0.24.

Is it normal ? Do I need to use a patch or another version ?

Regards


MJ Mohanaselvam Jothi Syncfusion Team April 26, 2018 06:23 AM UTC

Hi Lopes,

Thank you for your update.

We have fixed the AccessViolationException issue while accessing the font in Word to PDF conversion in ASP.Net core application and included in our 2018 volume 1 SP1 release. We recommend you to use our latest version v16.1.0.37 NuGet packages to resolve the reported issue at your end.

You can download our latest Essential Studio 2018 Volume 1 SP 2 Release  v16.1.0.37 under the following link.
https://www.syncfusion.com/forums/137209/essential-studio-2018-volume-1-service-pack-release-v16-1-0-37-available-for-download

Please refer the below URL in NuGet Package Sources in your application to get ASP.NET Core NuGet packages:
http://nuget.syncfusion.com/nuget_aspnetcore/nuget/getsyncfusionpackages/aspnetcore


From v16.1.0.32, we have stopped shipping framework version specific NuGet packages. Instead we are including all the framework assemblies within single NuGet packages and shipping only single common NuGet package for each platform. So, please remove the old packages and install new single packages.

Please refer the below KB link to know more about Syncfusion NuGet package structure changes:
https://www.syncfusion.com/kb/8614/syncfusion-nuget-package-structure-changes

Please find the information about NuGet packages for Word to PDF conversion in ASP.Net core platform from below.
 
Old packages 
New single packages  
syncfusion.compression.netstandard12 
syncfusion.compression.netstandard 
syncfusion.compression.netstandard14 
syncfusion.compression.netstandard20 
syncfusion.docio.netstandard12 
syncfusion.docio.netstandard 
syncfusion.docio.netstandard14 
syncfusion.docio.netstandard20 
syncfusion.officechart.netstandard12 
syncfusion.officechart.netstandard 
syncfusion.officechart.netstandard14 
syncfusion.officechart.netstandard20 
syncfusion.dociorenderer.netstandard14 
syncfusion.dociorenderer.netstandard 
syncfusion.dociorenderer.netstandard20 
syncfusion.pdf.netstandard12 
syncfusion.pdf.netstandard 
syncfusion.pdf.netstandard14 
syncfusion.pdf.netstandard20 


Kindly provide us the confirmation whether the reported problem is resolved at your end in our latest version 16.1.0.37.

If you are still facing issue in our latest version 16.1.0.37 NuGet, then kindly provide us the input Word document along with the code snippets which used at your end. Thereby we will analyze further on the mentioned problem and will provide you the appropriate solution at the earliest.

Please let us know if you have any other questions.


Regards,
Mohanaselvam J
 



PP Peter peterson June 1, 2018 09:15 AM UTC

Hello, I have exactly the same issue.

Code:
 var streamInput = new FileStream(@"C:\temp\Test.docx", FileMode.Open);
            var outputStream = new FileStream(@"c:\temp\{" + Guid.NewGuid().ToString() + "}.pdf", FileMode.Create);

            WordDocument wordDocument = new WordDocument();
            wordDocument.Open(streamInput, FormatType.Docx);

            DocIORenderer render = new DocIORenderer();
            PdfDocument pdfDocument = render.ConvertToPDF(wordDocument);
            pdfDocument.Save(outputStream);

            streamInput.Dispose();
            outputStream.Dispose();
            wordDocument.Dispose();
            render.Dispose();
            pdfDocument.Close();

Word document is attached.

Issue occurs randomly.

Please let me know asap.

Nuget version: 16.1200.0.26
Attachment: Test_f577f5e3.zip


MJ Mohanaselvam Jothi Syncfusion Team June 4, 2018 11:01 AM UTC

Hi Peter,


We have fixed the AccessViolationException issue while accessing the font in Word to PDF conversion in ASP.Net core application and included in our 2018 volume 1 SP1 release. We recommend you to use our latest version v16.1.0.37 NuGet packages to resolve the reported issue at your end.

You can download our latest Essential Studio 2018 Volume 1 SP 2 Release v16.1.0.37 under the following link.
https://www.syncfusion.com/forums/137209/essential-studio-2018-volume-1-service-pack-release-v16-1-0-37-available-for-download


From v16.1.0.32, we have stopped shipping framework version specific NuGet packages. Instead we are including all the framework assemblies within single NuGet packages and shipping only single common NuGet package for each platform. So, please remove the old packages and install new single packages.

Please refer the below KB link to know more about Syncfusion NuGet package structure changes:
https://www.syncfusion.com/kb/8614/syncfusion-nuget-package-structure-changes

Kindly provide us the confirmation whether the reported problem is resolved at your end in our latest version 16.1.0.37.


Please let us know if you have any other questions.


Regards,
Mohanaselvam J
  



PH Paulo Henrique Abreu June 27, 2018 08:29 PM UTC

Hi,

I am using version 16.2.0.41 and i'm getting the same issue.






MJ Mohanaselvam Jothi Syncfusion Team June 28, 2018 09:19 AM UTC

Hi Paulo,

Thank you for your update.

We have tried to reproduce the reported AccessViolationException problem using the input Word document (Updated on 6/1/2018), but it works properly at our end.

Please refer the below online sample page link to ensure Word to PDF conversion in 16.2.0.41 version at your end:
https://aspnetcore.syncfusion.com/docio/wordtopdf

We suspect that the problem might be due to the  assembly or NuGet package references in your application. Could you please provide us the sample application along with the input Word document which used at your end to reproduce the reported problem. Thereby, we will check at our end and provide you the appropriate solution at the earliest.

Note: If you have any confidential data in your Word document and application, please replace with some dummy data and provide us the same. We just need your sample to recreate the problem you face.

Please refer the below KB documentation to know more about Word to PDF conversion in ASP.NET Core platform:
Word to PDF conversion in ASP.NET Core

Please let us know if you have any other questions.

Regards,
Mohanaselvam J
 



PH Paulo Henrique Abreu June 28, 2018 04:53 PM UTC

Hi Mohanaselvam,

I am using your sample and works, but the shapes of doc is filling totaly black. 
Look in attachment.

Files in zip:
 - InvoiceWithError - Error in invoice converted in PDF
 - InvoiceDocx - Original invoice in DOCX
 - ConvertToPDFCode - Code of convertion DOCX to PDF
 - InvoiceShape - Shapes in red and textBox in blue in DOCX

Thanks!



Attachment: InvoiceBug_95d071ad.zip


JA Jose Antonio June 28, 2018 09:52 PM UTC

I am having the same issue in my tests.

What i have seen is that if i put AutoTag to false and ExportBookmarks to None, the issue happens after 2 or 3 attempts (never on first attempt).
If i put AutoTag to true and ExportBookmarks to Heading, the error never happens, but the generated PDF is about 8MB (compared to 66kb); it has embedded the same font a hundred times.

I hope this info will help you fix this issue.


MJ Mohanaselvam Jothi Syncfusion Team June 29, 2018 12:15 PM UTC

Hi,

Thank you for your update.

Regarding shape preservation problem:
We have tried to reproduce the reported problem using the given details, but it works properly at our end. For your reference, we have attached a sample application which we tried at our end to reproduce the problem.

Please find the sample from the below link:
http://www.syncfusion.com/downloads/support/forum/136584/ze/WordToPDFSample-35480118.zip

Please find the input and generated PDF at our end from the below link:
http://www.syncfusion.com/downloads/support/forum/136584/ze/Documents-396663982.zip

Regarding generated PDF is about 8MB:
We suspect that you have used DOCX Word document to perform Word to PDF conversion. In case of DOCX file, you may think the file size is small but it is a zip archive (compressed) file with extension “docx”. Whereas, PDF is not compressed file, so it varies in the file size when compared to DOCX file.



We suspect that the above reported problems are might be due to the contents in the input word document which used at your end. We need to investigate with the contents in your input Word document to reproduce the exact problem at our end. So, could you please provide us the input Word document which used at your end. Thereby, we will analyze further and provide you the appropriate solution at the earliest.

Note: If you have any confidential data in your Word document, please replace with some dummy data and provide us the same. We just need your document to recreate the problem you face.


Please let us know if you have any other questions.

Regards,
Mohanaselvam J
 



PH Paulo Henrique Abreu June 29, 2018 04:49 PM UTC

Hi Mohanaselvam,

I has test my document in your sample, and the same error occurs.

I am send in attachment my document.

Thanks for help.



Attachment: DummyInvoice_6767c9d5.zip


PH Paulo Henrique Abreu July 5, 2018 12:06 PM UTC

Hi, some news about error?

Thanks


DB Dilli Babu Nandha Gopal Syncfusion Team July 5, 2018 12:47 PM UTC

Hi Paulo, 
 
Thank you for your update. 
 
We can reproduce the mentioned shape color preservation issue when converting the given Word document as PDF using DocIO and the fix for the issue will be included in our upcoming release 2018 Volume 2 SP1 release which will be available in July 2018 tentatively.

 
Please let us know if you have any concerns. 
 
Regards, 
Dilli babu 



SR Stepan Ryzhkov August 8, 2018 02:01 PM UTC

Hello, I am having the same issue. Sample project with docx file is attached.

Attachment: SyncTestApp_d92a1d57.rar


DB Dilli Babu Nandha Gopal Syncfusion Team August 9, 2018 04:51 PM UTC

Hi Stepan, 

Yes, we can reproduce the reported AccessViolationException while converting Word to PDF in ASP.NET Core application from our side. This issue has been fixed recently and included in our latest service pack release 16.2.0.46v which was rolled out by July 2018. The setup can be downloaded from the following link. 

Please let us know if the issue has been resolved at your end. 

Regards, 
Dilli babu. 



SR Stepan Ryzhkov August 13, 2018 10:45 AM UTC

Hello, thanks, it's helped.


DB Dilli Babu Nandha Gopal Syncfusion Team August 13, 2018 11:22 AM UTC

Hi Stepan, 

We are glad to know that the reported issue has been resolved. Please let us know if you need any further assistance on this.  

Regards, 
Dilli babu. 


Loader.
Up arrow icon