Cross Table Error
Hi, i've got a strange error in compiled Exe:
************** Testo dell'eccezione **************
System.ArgumentNullException: Il valore non può essere null.
Nome parametro: crossTable
in Syncfusion.Pdf.Parsing.PdfLoadedPageCollection..ctor(PdfDocumentBase document, PdfCrossTable crossTable)
in Syncfusion.Pdf.Parsing.PdfLoadedDocument.get_Pages()
in Syncfusion.Windows.Forms.PdfViewer.PdfDocumentView.UpdateByScroll()
in Syncfusion.Windows.Forms.PdfViewer.PdfDocumentView.SetZoom(Int32 percentage)
in Syncfusion.Windows.Forms.PdfViewer.PdfDocumentView.SetZoom(ZoomMode mode)
in Syncfusion.Windows.Forms.PdfViewer.PdfDocumentView.DrawingPanel_MouseWheel(MouseEventArgs e)
in Syncfusion.Windows.Forms.PdfViewer.PdfViewerControl.OnMouseWheel(MouseEventArgs e)
in System.Windows.Forms.Control.WmMouseWheel(Message& m)
in System.Windows.Forms.Control.WndProc(Message& m)
in System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
in System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
in System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Assembly caricati **************
mscorlib
Versione assembly: 4.0.0.0
Versione Win32: 4.8.9332.0 built by: NET481REL1LAST_B
Base di codice: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
Pigro Doc Facile
Versione assembly: 1.0.0.0
Versione Win32: 1.0.0.0
Base di codice: file:///C:/Program%20Files%20(x86)/A%26G%20Software/PigroDocFacile/Pigro%20Doc%20Facile.exe
----------------------------------------
Microsoft.VisualBasic
Versione assembly: 10.0.0.0
Versione Win32: 14.8.9037.0 built by: NET481REL1
Base di codice: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Microsoft.VisualBasic/v4.0_10.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
----------------------------------------
System.Windows.Forms
Versione assembly: 4.0.0.0
Versione Win32: 4.8.9332.0 built by: NET481REL1LAST_B
Base di codice: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
Versione assembly: 4.0.0.0
Versione Win32: 4.8.9332.0 built by: NET481REL1LAST_B
Base di codice: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
Versione assembly: 4.0.0.0
Versione Win32: 4.8.9037.0 built by: NET481REL1
Base di codice: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
Versione assembly: 4.0.0.0
Versione Win32: 4.8.9037.0 built by: NET481REL1
Base di codice: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Core
Versione assembly: 4.0.0.0
Versione Win32: 4.8.9316.0 built by: NET481REL1LAST_C
Base di codice: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Xml
Versione assembly: 4.0.0.0
Versione Win32: 4.8.9037.0 built by: NET481REL1
Base di codice: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
System.Runtime.Remoting
Versione assembly: 4.0.0.0
Versione Win32: 4.8.9214.0 built by: NET481REL1LAST_B
Base di codice: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Remoting/v4.0_4.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
----------------------------------------
Syncfusion.PdfViewer.Windows
Versione assembly: 33.1462.44.0
Versione Win32: 33.1462.44.0
Base di codice: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Syncfusion.PdfViewer.Windows/v4.0_33.1462.44.0__3d67ed1f87d44c89/Syncfusion.PdfViewer.Windows.dll
----------------------------------------
Syncfusion.Shared.Base
Versione assembly: 33.1462.44.0
Versione Win32: 33.1462.44.0
Base di codice: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Syncfusion.Shared.Base/v4.0_33.1462.44.0__3d67ed1f87d44c89/Syncfusion.Shared.Base.dll
----------------------------------------
Syncfusion.Tools.Windows
Versione assembly: 33.1462.44.0
Versione Win32: 33.1462.44.0
Base di codice: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Syncfusion.Tools.Windows/v4.0_33.1462.44.0__3d67ed1f87d44c89/Syncfusion.Tools.Windows.dll
----------------------------------------
Syncfusion.Pdf.Base
Versione assembly: 33.1462.44.0
Versione Win32: 33.1462.44.0
Base di codice: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Syncfusion.Pdf.Base/v4.0_33.1462.44.0__3d67ed1f87d44c89/Syncfusion.Pdf.Base.dll
----------------------------------------
Syncfusion.PdfToImageConverter.Base
Versione assembly: 33.1462.44.0
Versione Win32: 33.1462.44.0
Base di codice: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Syncfusion.PdfToImageConverter.Base/v4.0_33.1462.44.0__3d67ed1f87d44c89/Syncfusion.PdfToImageConverter.Base.dll
----------------------------------------
Syncfusion.Grid.Windows
Versione assembly: 33.1462.44.0
Versione Win32: 33.1462.44.0
Base di codice: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Syncfusion.Grid.Windows/v4.0_33.1462.44.0__3d67ed1f87d44c89/Syncfusion.Grid.Windows.dll
----------------------------------------
Accessibility
Versione assembly: 4.0.0.0
Versione Win32: 4.8.9037.0 built by: NET481REL1
Base di codice: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Accessibility/v4.0_4.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
----------------------------------------
Syncfusion.Compression.Base
Versione assembly: 33.1462.44.0
Versione Win32: 33.1462.44.0
Base di codice: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/Syncfusion.Compression.Base/v4.0_33.1462.44.0__3d67ed1f87d44c89/Syncfusion.Compression.Base.dll
----------------------------------------
mscorlib.resources
Versione assembly: 4.0.0.0
Versione Win32: 4.8.9037.0 built by: NET481REL1
Base di codice: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/mscorlib.resources/v4.0_4.0.0.0_it_b77a5c561934e089/mscorlib.resources.dll
----------------------------------------
System.Windows.Forms.resources
Versione assembly: 4.0.0.0
Versione Win32: 4.8.9037.0 built by: NET481REL1
Base di codice: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms.resources/v4.0_4.0.0.0_it_b77a5c561934e089/System.Windows.Forms.resources.dll
----------------------------------------
It happens after I print the document and try to navigate the document.
Here's the code that print the loaded document:
Private Function StampaPDF(ByVal FilePDF As String, Optional PassPdf As String = "") As Integer
Dim dialog As New PrintDialog(), docPdf As New PdfDocumentView(), NumPagine As Integer
Dim DocProtetto As Boolean = False
If PassPdf.Length = 0 Then
If TabControl1.Visible Then
For Each tabPdf As TabPageAdv In TabControl1.TabPages
Dim PDF_Viewer As PdfViewerControl = tabPdf.Controls(0)
If Path.Combine(PDF_Viewer.DocumentInformation.FilePath, PDF_Viewer.DocumentInformation.FileName) = FilePDF Then
PDF_Viewer.LoadedDocument.Security.UserPassword = String.Empty
docPdf.Load(PDF_Viewer.LoadedDocument)
Exit For
End If
Next
Else
If Path.Combine(PdfViewerControl1.DocumentInformation.FilePath, PdfViewerControl1.DocumentInformation.FileName) = FilePDF Then
PdfViewerControl1.LoadedDocument.Security.UserPassword = String.Empty
docPdf.Load(PdfViewerControl1.LoadedDocument)
End If
End If
If docPdf IsNot Nothing Then
Try
docPdf.Load(FilePDF)
Catch ex As Syncfusion.Pdf.PdfInvalidPasswordException
DocProtetto = True
End Try
End If
Else
Try
Dim loadedDoc As New PdfLoadedDocument(FilePDF, PassPdf)
loadedDoc.Security.UserPassword = String.Empty
docPdf.Load(FilePDF, PassPdf)
Catch ex As Syncfusion.Pdf.PdfInvalidPasswordException
MsgBox("La password per il file " & Path.GetFileName(FilePDF) & " è errata", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly, "Stampa PDF")
docPdf = Nothing
' StampaPDF(FilePDF)
End Try
End If
If DocProtetto Then
Dim Password As String = InputBox("Il documento " & Path.GetFileName(FilePDF) & " è protetto da password" & Environment.NewLine &
"Digita la password")
If Password <> String.Empty Then
StampaPDF(FilePDF, Password)
Else
docPdf = Nothing
End If
End If
Using docPdf
If docPdf IsNot Nothing Then
With dialog
.Document = docPdf.PrintDocument
.Document.DocumentName = Path.GetFileName(FilePDF)
.PrinterSettings.Collate = True
docPdf.PrinterSettings.PageSize = PdfViewerPrintSize.Fit
If ImpostazioniStampa Is Nothing Then
.PrinterSettings.Duplex = Duplex.Simplex
If ChkStampaFR.Checked Then
.PrinterSettings.Duplex = Duplex.Horizontal
If RBtnLatoLungo.Checked Then
.PrinterSettings.Duplex = Duplex.Vertical
End If
docPdf.PrinterSettings.Copies = NumUD_NumCopie.Value
Else
.PrinterSettings = ImpostazioniStampa
End If
If RbtnIntervallo.Checked Then
.PrinterSettings.FromPage = NudPagineDa.Value
.PrinterSettings.ToPage = NudPagineA.Value
ElseIf RbtnPaginaCorrente.Checked Then
If TabControl1.Visible Then
Dim PDF_Viewer As PdfViewerControl = TabControl1.SelectedTab.Controls(0)
.PrinterSettings.FromPage = PDF_Viewer.CurrentPageIndex
.PrinterSettings.ToPage = PDF_Viewer.CurrentPageIndex
Else
.PrinterSettings.FromPage = PdfViewerControl1.CurrentPageIndex
.PrinterSettings.ToPage = PdfViewerControl1.CurrentPageIndex
End If
End If
docPdf.PrinterSettings.Copies = NumUD_NumCopie.Value
Else
.PrinterSettings = ImpostazioniStampa
End If
docPdf.Print(StatLblNomeStampante.Text)
NumPagine = docPdf.PageCount * NumUD_NumCopie.Value
docPdf.Unload()
.Dispose()
End With
End If
End Using
Return NumPagine
End Function
Thanks for your attention
Hi Andrea De Luca,
Regards,
Yaminisri M
Hi Andrea De Luca,
After reviewing the code and
the observed behavior, we recommend loading the PDF document as a stream
instead of directly using the PdfLoadedDocument instance from the PDF Viewer.
Loading the PdfLoadedDocument directly from PdfViewerControl.LoadedDocument and reusing it in other components (such as PdfDocumentView for printing) is not a recommended or best practice. The reason is that the PdfLoadedDocument instance loaded in the PDF Viewer is owned and managed internally by PdfViewerControl, which continuously uses it for rendering, scrolling, zooming, and page navigation.
When the same document instance is reused outside the viewer and later unloaded or closed (for example, by calling Unload() or Close(True)), the viewer still holds a reference to that document. This leads to an inconsistent internal state (such as a disposed cross table), which can result in runtime exceptions during user interactions like scrolling or zooming.
Please refer to the following code snippet for your reference:
|
Private Function StampaPDF(ByVal filePdf As String, Optional passPdf As String = "") As Integer
Dim dialog As New PrintDialog() Dim docPdf As New PdfDocumentView() Dim numPagine As Integer = 0 Dim docProtetto As Boolean = False
Dim loadedDocument As PdfLoadedDocument = Nothing
If String.IsNullOrEmpty(passPdf) Then
If TabControl1.Visible Then For Each tabPdf As TabPage In TabControl1.TabPages Dim viewer As PdfViewerControl = TryCast(tabPdf.Controls(0), PdfViewerControl)
If viewer IsNot Nothing AndAlso Path.Combine(viewer.DocumentInformation.FilePath, viewer.DocumentInformation.FileName) = filePdf Then
viewer.LoadedDocument.Security.UserPassword = String.Empty loadedDocument = viewer.LoadedDocument Exit For End If Next Else If Path.Combine(pdfViewerControl1.DocumentInformation.FilePath, pdfViewerControl1.DocumentInformation.FileName) = filePdf Then
pdfViewerControl1.LoadedDocument.Security.UserPassword = String.Empty loadedDocument = pdfViewerControl1.LoadedDocument End If End If
If loadedDocument Is Nothing Then Try loadedDocument = New PdfLoadedDocument(filePdf) Catch ex As PdfInvalidPasswordException docProtetto = True End Try End If
Else Try loadedDocument = New PdfLoadedDocument(filePdf, passPdf) loadedDocument.Security.UserPassword = String.Empty Catch ex As PdfInvalidPasswordException MsgBox("Wrong password for " & Path.GetFileName(filePdf), MsgBoxStyle.Critical) Return 0 End Try End If
If docProtetto Then Dim pwd As String = InputBox("Enter password:") If pwd <> String.Empty Then Return StampaPDF(filePdf, pwd) Else Return 0 End If End If Using pdfStream As New MemoryStream()
loadedDocument.Save(pdfStream) pdfStream.Position = 0
docPdf.Load(pdfStream) With dialog .Document = docPdf.PrintDocument .Document.DocumentName = Path.GetFileName(filePdf)
docPdf.PrinterSettings.PageSize = PdfViewerPrintSize.Fit docPdf.PrinterSettings.Copies = NumUD_NumCopie.Value
If RbtnIntervallo.Checked Then .PrinterSettings.FromPage = NudPagineDa.Value .PrinterSettings.ToPage = NudPagineA.Value
ElseIf RbtnPaginaCorrente.Checked Then .PrinterSettings.FromPage = pdfViewerControl1.CurrentPageIndex .PrinterSettings.ToPage = pdfViewerControl1.CurrentPageIndex End If
.PrinterSettings.Duplex = Duplex.Simplex If ChkStampaFR.Checked Then .PrinterSettings.Duplex = If(RBtnLatoLungo.Checked, Duplex.Vertical, Duplex.Horizontal) End If docPdf.Print(StatLblNomeStampante.Text) End With
numPagine = docPdf.PageCount * NumUD_NumCopie.Value
docPdf.Unload(True) End Using
Return numPagine
End Function |
Regards,
Yaminisri M
Thank you very much.
As always you resolve al my problem and I learn
Hi Andrea De Luca,
Regards,
Lingeshwaran S
- 4 Replies
- 3 Participants
-
AD Andrea De Luca
- Apr 24, 2026 01:38 PM UTC
- Apr 29, 2026 08:19 AM UTC