I’ve got a app that simply open a PDF file and then attempts to copy select pages into a new document. The problem is that as soon as I add a page from the open document to the new document I can no longer continue enumerating through the pages of the open document. I get “An unhandled exception of type ‘System.NullReferenceException’ occurred “. Any ideas? I am using the latest version of the PDF library, runtime v4.0.30319 w/VS 2015. Here’s the bare bones version of my code. Also, this code worked without errors until I upgraded to the latest version of the PDF library which I need for some of the bug fixes.
Dim oPDoc As New Document(PDFFileName.Text)
Dim oNewDoc As Document = Nothing
For Each oPage In oPDoc.Pages
If HasBillingAccountHeader(oPage) Then
If oNewDoc IsNot Nothing Then oNewDoc.Save(sNewFile)
oNewDoc = New Document
sNewFile = String.Format(”{0}\Invoice for Client {1}.tmp.pdf”, PDFOutFolder.Text, sAcct)
End If
If oPage IsNot Nothing Then oNewDoc.Pages.Add(oPage)
Next