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

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