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
close icon

Exception being thrown when Converting a .docx file to pdf

When attempting to convert a microsoft word docx file to a pdf, I am getting an exception in Syncfusion.Pdf.Portal that states that the "Argument Array should be of the same length"



"   at Syncfusion.Pdf.Graphics.PdfPath.AddPath(PointF[] pathPoints, Byte[] pathTypes)
   at Syncfusion.DocIORenderer.Rendering.ShapePath.GetCurvedLeftArrowPath()
   at Syncfusion.DocToPdfConverter.Rendering.PDFDrawingContext.GetGraphicsPath(Shape shape, RectangleF bounds, PdfPen& pen)
   at Syncfusion.DocToPdfConverter.Rendering.PDFDrawingContext.DrawShape(Shape shape, LayoutedWidget ltWidget)
   at Syncfusion.DocToPdfConverter.Rendering.PDFDrawingContext.Draw(Shape shape, LayoutedWidget ltWidget)
   at Syncfusion.DocToPdfConverter.Rendering.PDFDrawingContext.Draw(LayoutedWidget layoutedWidget, Boolean isHaveToInitLayoutInfo)
   at Syncfusion.DocToPdfConverter.Rendering.PDFDrawingContext.DrawOverLappedShapeWidgets(Boolean isHaveToInitLayoutInfo)
   at Syncfusion.DocToPdfConverter.Rendering.PDFDrawingContext.Draw(Page page)
   at Syncfusion.DocIORenderer.DocIORenderer.DrawDirectWordToPDF(DocumentLayouter layouter)
   at <Application>.Services.UserFileUploadService.ConvertDocToPDFStream(String fileName, Byte[] fileData) in C:\\Users\\<user>\\source\\repos\\<ApplicationFolder>\\<Application>\\Services\\UserFileUploadService.cs:line 181
   at <Application>.Services.UserFileUploadService.<UploadDocThumbnail>d__7.MoveNext() in C:\\Users\\<user>\\source\\repos\\<ApplicationFolder>\\<Application>\\Services\\UserFileUploadService.cs:line 80
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at <Application>.Services.UserFileUploadService.<UploadThumbnail>d__5.MoveNext() in C:\\Users\\<user>\\source\\repos\\<ApplicationFolder>\\<Application>\\Services\\UserFileUploadService.cs:line 44
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at <Application>.Services.<>DocumentService.<Upload<>Documents>d__3.MoveNext() in C:\\Users\\<user>\\source\\repos\\<ApplicationFolder>\\<Application>\\Services\\<>DocumentService.cs:line 47
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at <Application>.Services.<>FormsImportService.<ImportDistrict<>>d__3.MoveNext() in C:\\Users\\<user>\\source\\repos\\<ApplicationFolder>\\<Application>\\Services\\<>FormsImportService.cs:line 26
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at <Application>.<Application>.<Run>d__2.MoveNext() in C:\\Users\\<user>\\source\\repos\\<ApplicationFolder>\\<Application>\\<Application>.cs:line 21
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at <Application>.Program.<Main>d__12.MoveNext() in C:\\Users\\<user>\\source\\repos\\<ApplicationFolder>\\<Application>\\Program.cs:line 23"


11 Replies

VA Vijayasurya Anandhan Syncfusion Team October 9, 2019 06:04 AM UTC

Hi Aaron,

Thank you for contacting Syncfusion support.

We can reproduce the issue with “
ArgumentException throws while convert the Word document to PDF” using the provided stack trace from our side and suspect it to be a defect. We will validate this issue and update you with more details on 11th October 2019. 
 
Please let us know if you have any queries. 
 
Regards, 
Vijayasurya A 



RM Ramaraj Marimuthu Syncfusion Team October 11, 2019 02:42 PM UTC

Hi Aaron,

Thank you for your patience.

We confirmed the issue “ArgumentException throws while convert the Word document to PDF” as a defect. We have logged a defect report. The fix for this issue is estimated to be available on October 25, 2019.

Please use the below feedback link to track the status of the reported bug.
https://www.syncfusion.com/feedback/9461/argumentexception-throws-while-convert-the-word-document-to-pdf

Please let us know if you need any further assistances in this.

Regards,
Ramaraj Marimuthu
 



VA Vijayasurya Anandhan Syncfusion Team November 1, 2019 02:48 PM UTC

Hi Aaron,

Thank you for your patience.

We have resolved the reported issue with “ArgumentException throws while convert the Word document to PDF
” and the patch for this fix can be downloaded from the following location.

Recommended approach - exe will perform automatic configuration
Please find the patch setup from below location:

http://syncfusion.com/Installs/support/patch/17.3.0.14/1005680/F148161/SyncfusionPatch_17.3.0.14_1005680_11012019084937302_F148161.exe 

Advanced approach – use only if you have specific needs and can directly replace existing assemblies for your build environment
Please find the patch assemblies alone from below location:

http://syncfusion.com/Installs/support/patch/17.3.0.14/1005680/F148161/SyncfusionPatch_17.3.0.14_1005680_11012019084937302_F148161.zip 

NuGet:
 
http://syncfusion.com/Installs/support/patch/17.3.0.14/1005680/F148161/SyncfusionNuget_17.3.0.14_1005680_11012019084937302_F148161.zip

Assembly Version: 17.3.0.14
Installation Directions :
This patch should replace the files “Syncfusion.Compression.Portable.dll”, “Syncfusion.OfficeChart.Portable.dll” , “Syncfusion.DocIO.Portable.dll”, “Syncfusion.DocIORenderer.Portable.dll”, “Syncfusion.Pdf.Portable.dll” and “Syncfusion.SkiaSharpHelper.Portable.dll” under the following folder.
$system drive:\ Files\Syncfusion\Essential Studio\Platform\$Version # \precompiledassemblies\$Version#\4.0
E.g. : $system drive:\Program Files\Syncfusion\Essential Studio\ASP.NET CORE\17.3.0.14\precompiledassemblies\17.3.0.14\4.0

Note :
To change how you receive bug fixes, ask your license management portal admin to change your project’s patch delivery mode.

https://www.syncfusion.com/account/license

Disclaimer :
Please note that we have created this patch for version 17.3.0.14 specifically to resolve the issue reported in the forum 148161.

If you have received other patches for the same version for other products, please apply all patches in the order received.
This fix will include in our 2019 Volume 3 SP1 release which will be available in start of November 2019.

Please let us know if you have any questions.

Regards,
Vijayasurya A



AA Aaron June 11, 2021 04:11 PM UTC

is it possible that a similar bug was introduced in the latest version?





HC Hemalatha Chiranjeevulu Syncfusion Team June 14, 2021 07:26 AM UTC

Hi Aaron,

Thank you for your update.

We suspect that the reported issue might be due to assemblies are not referred properly in your machine or NuGet conflicts or the project linking settings in your application.

If you are using assemblies in your application, we suggest you remove the Syncfusion.DocIO.Portable assembly from GAC by using the following command in command prompt(ex: VS2017 Native/Cross tools command prompt) in administrator mode.

gacutil -u Syncfusion.DocIO.Portable

To know more about uninstalling the assemblies from GAC, please refer here.

If you are using NuGet packages, we suggest you try the below solution to resolve the exception issur at your side:
  1.Kindly remove the NuGet packages (Syncfusion.DocIO.Net.Core) referred in your application
  2.Delete the respective NuGet packages in “.nuget” folder which is available in “C:\Users\{XXX}\.nuget\packages” folder location.
  3.Then install the latest version v19.1.0.67 NuGet packages again in your application.
  4.Clean the solution, rebuild, and run the application.

Please let us know if you have any other questions.

Regards,
Hemalatha C



AA Aaron June 14, 2021 03:50 PM UTC

Unfortunately that doesnt resolve the issue.  It changes the error however to be an error findinkg SkiaSharp




HC Hemalatha Chiranjeevulu Syncfusion Team June 15, 2021 09:21 AM UTC

Hi Aaron,

Thank you for your update.

We have already faced similar kind of problem and it is fixed in our latest version of SkiaSharp NuGet. Essential DocIO internally uses SkiaSharp graphics library for measuring techniques during Word to PDF conversion process. We suspect that the reported exception issue might be due to SkiaSharp references in your project. To resolve this, we suggest you to remove all the SkiaSharp references and use SkiaSharp.NativeAssets.Linux v2.80.2 NuGet in addition to DocIORenderer NuGet package.

If you are performing Word to PDF conversion in Linux environment, please refer the below link to know more about Word to PDF conversion in Linux environment:
https://help.syncfusion.com/file-formats/docio/word-to-pdf#word-to-pdf-conversion-in-linux-os

If you are still facing the same issue means, could you please share us the below things from your side:
  1. Code snippet which used at your side.
  2. Input Word document.
  3. Environment details (OS)
  4. NuGet packages which used in your application
  5. Syncfusion product version which used in your application

This will be more helpful for us to reproduce the exact issue at our end. Thereby we will analyze further on the reported problem and update you with appropriate solution at the earliest.

Please let us know if you have any other questions.

Regards,
Hemalatha C



AA Aaron June 15, 2021 04:24 PM UTC

I gave this a try and this is what I have found.
1) The native linux assets still pull in the base skia libarary.
     
2)DocIORender installs the SkiaSharpHelper library as a dependency


Even if I remove the project references after installing the required nuget packages, I still get the same error.
1. Code snippet which used at your side.
private MemoryStream ConvertDocToPDFStream(string fileName, byte[] fileBytes) {
            var renderer = new DocIORenderer();
            var fileType = Syncfusion.DocIO.FormatType.Doc;
            if (fileName.EndsWith(".docx")) {
                fileType = Syncfusion.DocIO.FormatType.Docx;
            }

            try {
                using (var memoryStream = new MemoryStream(fileBytes)) {
                    using (var wordDoc = new WordDocument(memoryStream, fileType)) {
                        using (var pdfDoc = renderer.ConvertToPDF(wordDoc)) {
                            var stream = new MemoryStream();
                            pdfDoc.Save(stream);

                            return stream;
                        }
                    }
                }
            }
            catch (Exception ex) {
                throw;
            }
        }
2. Input Word document. - Attached
3. Environment details (OS)
   Windows 10, Visual Studio 2019
4. NuGet packages which used in your application
     <package id="AjaxUploader" version="4.0.2.7" targetFramework="net462" />
  <package id="Antlr" version="3.5.0.2" targetFramework="net462" />
  <package id="Azure.Core" version="1.15.0" targetFramework="net462" />
  <package id="Azure.Storage.Blobs" version="12.9.0" targetFramework="net462" />
  <package id="Azure.Storage.Common" version="12.8.0" targetFramework="net462" />
  <package id="Humanizer.Core" version="2.11.10" targetFramework="net462" />
  <package id="Microsoft.AspNet.FriendlyUrls" version="1.0.2" targetFramework="net462" />
  <package id="Microsoft.AspNet.FriendlyUrls.Core" version="1.0.2" targetFramework="net462" />
  <package id="Microsoft.AspNet.Mvc" version="5.2.7" targetFramework="net462" />
  <package id="Microsoft.AspNet.Razor" version="3.2.7" targetFramework="net462" />
  <package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net462" />
  <package id="Microsoft.AspNet.WebApi.Client" version="5.2.7" targetFramework="net462" />
  <package id="Microsoft.AspNet.WebApi.Core" version="5.2.7" targetFramework="net462" />
  <package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.7" targetFramework="net462" />
  <package id="Microsoft.AspNet.WebPages" version="3.2.7" targetFramework="net462" />
  <package id="Microsoft.Azure.KeyVault.Core" version="3.0.5" targetFramework="net462" />
  <package id="Microsoft.Bcl.AsyncInterfaces" version="5.0.0" targetFramework="net462" />
  <package id="Microsoft.Extensions.Caching.Abstractions" version="5.0.0" targetFramework="net462" />
  <package id="Microsoft.Extensions.Caching.Memory" version="5.0.0" targetFramework="net462" />
  <package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="5.0.0" targetFramework="net462" />
  <package id="Microsoft.Extensions.Logging.Abstractions" version="5.0.0" targetFramework="net462" />
  <package id="Microsoft.Extensions.Options" version="5.0.0" targetFramework="net462" />
  <package id="Microsoft.Extensions.Primitives" version="5.0.1" targetFramework="net462" />
  <package id="Microsoft.NETCore.Platforms" version="5.0.2" targetFramework="net462" />
  <package id="Microsoft.Rest.ClientRuntime" version="2.3.21" targetFramework="net462" />
  <package id="Microsoft.Rest.ClientRuntime.Azure" version="3.3.19" targetFramework="net462" />
  <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net462" />
  <package id="mustache.js" version="0.8.1" targetFramework="net462" />
  <package id="NETStandard.Library" version="2.0.3" targetFramework="net462" />
  <package id="Newtonsoft.Json" version="12.0.3" targetFramework="net462" />
  <package id="SkiaSharp" version="2.80.2" targetFramework="net462" />
  <package id="SkiaSharp.NativeAssets.Linux" version="2.80.2" targetFramework="net462" />
  <package id="Syncfusion.Compression.Base" version="19.1.0.69" targetFramework="net462" />
  <package id="Syncfusion.Compression.Net.Core" version="19.1.0.69" targetFramework="net462" />
  <package id="Syncfusion.DocIO.Net.Core" version="19.1.0.69" targetFramework="net462" />
  <package id="Syncfusion.DocIORenderer.Net.Core" version="19.1.0.69" targetFramework="net462" />
  <package id="Syncfusion.EJ2.AspNet.Core" version="19.1.0.69" targetFramework="net462" />
  <package id="Syncfusion.EJ2.PdfViewer.AspNet.Mvc5" version="19.1.0.69" targetFramework="net462" />
  <package id="Syncfusion.Licensing" version="19.1.0.69" targetFramework="net462" />
  <package id="Syncfusion.OfficeChart.Net.Core" version="19.1.0.69" targetFramework="net462" />
  <package id="Syncfusion.Pdf.AspNet.Mvc5" version="19.1.0.69" targetFramework="net462" />
  <package id="Syncfusion.Pdf.Net.Core" version="19.1.0.69" targetFramework="net462" />
  <package id="Syncfusion.Presentation.Net.Core" version="19.1.0.69" targetFramework="net462" />
  <package id="Syncfusion.PresentationRenderer.Net.Core" version="18.4.0.48" targetFramework="net462" />
  <package id="Syncfusion.SkiaSharpHelper.Net.Core" version="19.1.0.69" targetFramework="net462" />
  <package id="Syncfusion.XlsIO.Net.Core" version="19.1.0.69" targetFramework="net462" />
  <package id="System.Buffers" version="4.5.1" targetFramework="net462" />
  <package id="System.Diagnostics.DiagnosticSource" version="5.0.1" targetFramework="net462" />
  <package id="System.Drawing.Common" version="5.0.2" targetFramework="net462" />
  <package id="System.Memory" version="4.5.4" targetFramework="net462" />
  <package id="System.Memory.Data" version="1.0.2" targetFramework="net462" />
  <package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net462" />
  <package id="System.Runtime.CompilerServices.Unsafe" version="5.0.0" targetFramework="net462" />
  <package id="System.Text.Encoding.CodePages" version="5.0.0" targetFramework="net462" />
  <package id="System.Text.Encodings.Web" version="5.0.1" targetFramework="net462" />
  <package id="System.Text.Json" version="5.0.2" targetFramework="net462" />
  <package id="System.Threading.Tasks.Extensions" version="4.5.4" targetFramework="net462" />
  <package id="System.ValueTuple" version="4.5.0" targetFramework="net462" />
  <package id="WebGrease" version="1.6.0" targetFramework="net462" />
  <package id="WindowsAzure.Storage" version="9.3.3" targetFramework="net462" />
5. Syncfusion product version which used in your application
     The syncfusion versions are listed above.

Attachment: TestWordDoc_f5fedf11.zip


HC Hemalatha Chiranjeevulu Syncfusion Team June 16, 2021 03:51 PM UTC

Hi Aaron,

Thank you for sharing us the details.

We have tried to reproduce the reported exception issue using the given details but, it works properly at our end. For your reference, we have attached the sample application which we used at our end to reproduce the reported exception issue and it can be downloaded from the below link

Sample link: https://www.syncfusion.com/downloads/support/forum/148161/ze/WordToPdf-298442570

We suspect that the reported issue might be due to NuGet packages are not referred properly in your application.
We suggest you to remove SkiaSharp.NativeAssets.Linux (it is for Linux only) and use DocIORenderer NuGet package which is enough to convert Word document to PDF conversion in ASP.NET Core platform in Windows environment. Please refer the below link to know more about NuGet packages required for Word document to PDF conversion:
https://help.syncfusion.com/file-formats/docio/nuget-packages-required#converting-word-document-to-pdf

Could you please check and confirm us whether you have faced mentioned exception issue in above sample also. If no, then share us the simplified sample or modified sample of above to replicate the same problem. Thereby, we will proceed further to replicate the same problem at our end and will provide the more details.

Additional information:
From the given details, we have found that you are using different version of each Syncfusion products (Syncfusion.PresentationRenderer.Net.Core" version="18.4.0.48). We strongly recommend you to use same version of all Syncfusion NuGets in your application to avoid assembly conflicts problem at runtime.

Please let us know if you have any other questions.

Regards,
Hemalatha C



AA Aaron June 16, 2021 04:10 PM UTC

I only attempted the linux package assets because you suggest it, I didnt believe it would fix the issue.  Further, when I install the DocIORender nuget package skiaSharp is installed as a dependency.  Your sample project doesnt include SkiaSharp.  I cant remove SkaiSharp on its own as DocIORender Depends on it.   Even if I install DocIORender and ignore the dependencies I get the same exception.  Your sample project is in .net core 3.1, do you have a sample for .net framework 4.8??



HC Hemalatha Chiranjeevulu Syncfusion Team June 17, 2021 11:14 AM UTC

Hi Aaron,

Thank you for your update.

From the given details, we suspect that you are using .NET Framework target application at your end. For .NET Framework target, we recommend you to use Syncfusion.DocToPdfConverter NuGet package in the application for Word to PDF conversion process. Please find the sample application for the same from the below link:
https://www.syncfusion.com/downloads/support/forum/148161/ze/WordToPDF1682232031
Syncfusion.DocToPdfConverter NuGet – This is for .NET Framework target application to perform Word to PDF conversion.
Syncfusion.DocIORenderer.Net.Core – This is for ASP.NET Core, Console Application (Targeting .NET Core) and Blazor target application to perform Word to PDF conversion.

We suggest you to follow up the below suggestion at your side :
1. If you are using .NET Framework targeting application, then kindly use .NET Framework related NuGet packages of Syncfusion products.
2. If you are using ASP.NET Core targeting application, then kindly use ASP.NET Core NuGet packages of Syncfusion products.
3. Kindly ensure all the Syncfusion NuGet packages are in same version and from same platform.

If you still facing any other issue at your end means, could you please share us the modified sample of above along with the code example. Thereby, we will try to replicate the same problem at our end and will update you the details.

Please let us know if you have any other questions.

Regards,
Hemalatha C


Loader.
Live Chat Icon For mobile
Up arrow icon