Null reference error when exporting XLSX to pdf

Questions, comments and suggestions concerning VintaSoft Imaging .NET SDK.

Moderator: Alex

Post Reply
nnansen
Posts: 6
Joined: Fri Nov 04, 2022 11:36 pm

Null reference error when exporting XLSX to pdf

Post by nnansen »

Hello,
I am encountering an issue when attempting to convert an XLSX file to a pdf file. When attempting to export the xlsx file, the XlsxDocumentEditor.Export() method is failing and throwing a null reference exception. I have ensured all argument's fields are populated if they are not nullable when debugging. I have attempted with the code below and with the documentation recommended ImageCollection method, both give the same error.

Code: Select all

public static void ConvertExcelToPDF(string filePath, string outputPath)
{
    
        // Use OpenXML editor to export the xlsx to pdf. This allows text in the workbook
        // to be captured and saved in TextRegion of page. Previously we rendered an image
        //  of the worksheet which didn't capture the text values.
        using (XlsxDocumentEditor editor = new XlsxDocumentEditor(filePath))
        {
            // When exporting, the editor would create an oddly sized page. Using DocumentLayoutSettings to 
            // instruct the export to create a standard (8.5x11in) sized document.
            DocumentLayoutSettings documentLayoutSettings = new DocumentLayoutSettings()
            {
                PageLayoutSettings = new PageLayoutSettings(ImageSize.FromPaperKind(PaperSizeKind.Letter, DocumentResolution)),
            };

            RenderingSettings renderingSettings = new RenderingSettings(DocumentResolution);
            documentLayoutSettings.EnvironmentProperties.SourceFilename = outputPath;
            
            editor.Export(outputPath, documentLayoutSettings, renderingSettings);
        }
    	using (PdfDocument document = new PdfDocument(outputPath))
    	{
        	// This saves the converted file with our standard compression settings.
        	using (new StopwatchLog($"Optimizing and saving PDF file after conversion from Excel file."))
        	{
            		SavePdfDocument(document, outputPath);                    
        	}

    }
    
}
The stack trace has some unrecognizable information, but it does seem to indicate something within OpenXml.Xlsx is having issues:

Code: Select all

   at ᥠ.珰(ᵪ A_0)
   at ᥠ.謃(뇛 A_0, ᧃ A_1, ᷮ A_2)
   at ᦭.珰(뇛 A_0)
   at ᣽.罓(꺌 A_0)
   at 뒛.珰(꺌 A_0)
   at ᢰ.罓(꺌 A_0)
   at 뒛.珰(꺌 A_0)
   at ᣆ.罓(꺌 A_0)
   at 뒛.珰(꺌 A_0)
   at ᢻ.罓(꺌 A_0)
   at 뒛.珰(꺌 A_0)
   at 띐.窙(봳 A_0)
   at 뮲.罓(꺌 A_0)
   at 뒛.珰(꺌 A_0)
   at 뤿.窙(봳 A_0)
   at 뮲.罓(꺌 A_0)
   at 뒛.珰(꺌 A_0)
   at 륫.窙(봳 A_0)
   at 뮲.罓(꺌 A_0)
   at 뒛.珰(꺌 A_0)
   at 멨.窙(봳 A_0)
   at Vintasoft.Imaging.Office.OpenXml.Xlsx.XlsxDocument.珰(멨 A_0, 뇛 A_1, 멳 A_2)
   at Vintasoft.Imaging.Office.OpenXml.Xlsx.XlsxDocument.珰(릢 A_0)
   at Vintasoft.Imaging.Office.OpenXml.Xlsx.XlsxDocument.LayoutCore()
   at Vintasoft.Imaging.Office.OpenXml.Xlsx.XlsxDocument.get_Pages()
   at Vintasoft.Imaging.Office.OpenXml.Xlsx.XlsxDocument.get_PageCount()
   at Vintasoft.Imaging.Codecs.Decoders.OpenXmlDecoder`1.GetPageCount()
   at Vintasoft.Imaging.Codecs.Decoders.DecoderBase.get_PageCount()
   at ⭺.⚢(Stream A_0, Boolean A_1, String A_2, ⚢ A_3, ⛁ A_4)
   at ⦊.⚢(Stream A_0, Boolean A_1)
   at Vintasoft.Imaging.ImageCollection.Insert(Int32 index, Stream stream, Boolean closeStreamAfterUse)
   at Vintasoft.Imaging.ImageCollection.Insert(Int32 index, Stream stream)
   at Vintasoft.Imaging.ImageCollection.Add(Stream stream)
   at Vintasoft.Imaging.Office.OpenXml.Editor.OpenXmlDocumentEditor.Export(Stream stream, EncoderBase encoder, DocumentLayoutSettings layoutSettings, RenderingSettings renderingSettings)
   at Vintasoft.Imaging.Office.OpenXml.Editor.OpenXmlDocumentEditor.Export(String filename, DocumentLayoutSettings layoutSettings, RenderingSettings renderingSettings)
   at IS.WM.Architecture.Utilities.VintaSoftPDFLibrary.ConvertExcelToPDF(String filePath, String outputPath) in D:\Git\DocuTrack\Projects\Architecture\DocumentImagingUtilities\VintaSoftPDFLibrary.cs:line 1436
Please advise on how to proceed as I cannot debug within Export to figure out what our the cause of our issue. I have a test file which will trigger it every time, but I do not see a way to upload it to this forum post creation page.

Nick Nansen
RedSail Technologies
Alex
Site Admin
Posts: 2373
Joined: Thu Jul 10, 2008 2:21 pm

Re: Null reference error when exporting XLSX to pdf

Post by Alex »

Hello Nick,

Thank you for information.

Please send us (to support@vintasoft.com) a console project that allows to reproduce the problem. We need to reproduce the problem on our side.

Best regards, Alexander
nnansen
Posts: 6
Joined: Fri Nov 04, 2022 11:36 pm

Re: Null reference error when exporting XLSX to pdf

Post by nnansen »

Alex,
I've emailed the console app solution zipped up to the support email. Please let me know if there are any info/clarification I can provide, thanks.
Alex
Site Admin
Posts: 2373
Joined: Thu Jul 10, 2008 2:21 pm

Re: Null reference error when exporting XLSX to pdf

Post by Alex »

Hello Nicholas,

In version 12.5.9.1 we have fixed the bug in XLSX renderer and optimized the memory usage in XLSX renderer. Now your XLSX document can be successfully exported to PDF document. Please use version 12.5.9.1 and let me know if you will have any question or problem.

Best regards, Alexander
Post Reply