We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Dereferencing Exception When Extracting Page Content And Splitting Pages

I have a PDF, for each page I am reading the text content, then putting the page in it’s own PDF document. Below is two versions of this code:

========================================
Version 1 - Do Loop
Exception: The given key was not present in the dictionary.
========================================

        Dim pdfDoc As New Aspose.Pdf.Document(fle.PostedFile.InputStream)
Dim NextPage As Integer = 1
Dim TotalPages As Integer = pdfDoc.Pages.Count

Do
Dim pdfPage As Aspose.Pdf.Page = pdfDoc.Pages(NextPage)


Dim TempStream As New System.IO.MemoryStream, sBuffer As String = “”
Dim device As New Aspose.Pdf.Devices.TextDevice(New Aspose.Pdf.Text.TextOptions.TextExtractionOptions(Aspose.Pdf.Text.TextOptions.TextExtractionOptions.TextFormattingMode.Raw), Encoding.ASCII)
device.Process(pdfPage, TempStream) 'Commenting this line doesn’t trigger the bug

Dim newDoc As New Aspose.Pdf.Document()
newDoc.Pages.Add(pdfPage) 'Commenting this line also doesn’t trigger the bug
'newDoc.Save()
NextPage += 1
Loop While NextPage <= TotalPages


========================================
Version 2 - Iterator
Exception: System.NullReferenceException: Page is null
========================================
        Dim pdfDoc As New Aspose.Pdf.Document(fle.PostedFile.InputStream)
Dim NextPage As Integer = 1
Dim TotalPages As Integer = pdfDoc.Pages.Count

For Each pdfPage In pdfDoc.Pages
Dim TempStream As New System.IO.MemoryStream, sBuffer As String = “”
Dim device As New Aspose.Pdf.Devices.TextDevice(New Aspose.Pdf.Text.TextOptions.TextExtractionOptions(Aspose.Pdf.Text.TextOptions.TextExtractionOptions.TextFormattingMode.Raw), Encoding.ASCII)
device.Process(pdfPage, TempStream)

Dim newDoc As New Aspose.Pdf.Document()
newDoc.Pages.Add(pdfPage)
'newDoc.Save()
NextPage += 1
Next

I should note that I tested this with version 10.6 and earlier without issue. This affects 10.7 till 11.6

edusi@saveat.com:
I have a PDF, for each page I am reading the text content, then putting the page in it’s own PDF document. Below is two versions of this code:

========================================
Version 1 - Do Loop
Exception: The given key was not present in the dictionary.
========================================
        Dim pdfDoc As New Aspose.Pdf.Document(fle.PostedFile.InputStream)
Dim NextPage As Integer = 1
Dim TotalPages As Integer = pdfDoc.Pages.Count

Do
Dim pdfPage As Aspose.Pdf.Page = pdfDoc.Pages(NextPage)


Dim TempStream As New System.IO.MemoryStream, sBuffer As String = “”
Dim device As New Aspose.Pdf.Devices.TextDevice(New Aspose.Pdf.Text.TextOptions.TextExtractionOptions(Aspose.Pdf.Text.TextOptions.TextExtractionOptions.TextFormattingMode.Raw), Encoding.ASCII)
device.Process(pdfPage, TempStream) 'Commenting this line doesn’t trigger the bug

Dim newDoc As New Aspose.Pdf.Document()
newDoc.Pages.Add(pdfPage) 'Commenting this line also doesn’t trigger the bug
'newDoc.Save()
NextPage += 1
Loop While NextPage <= TotalPages
Hi Erol,

Thanks for contacting support.

I have tested the scenario and have managed to reproduce the same problem. For the sake of correction, I have logged it as PDFNEWNET-40797 in our issue tracking system.


========================================
Version 2 - Iterator
Exception: System.NullReferenceException: Page is null
========================================
        Dim pdfDoc As New Aspose.Pdf.Document(fle.PostedFile.InputStream)
Dim NextPage As Integer = 1
Dim TotalPages As Integer = pdfDoc.Pages.Count

For Each pdfPage In pdfDoc.Pages
Dim TempStream As New System.IO.MemoryStream, sBuffer As String = “”
Dim device As New Aspose.Pdf.Devices.TextDevice(New Aspose.Pdf.Text.TextOptions.TextExtractionOptions(Aspose.Pdf.Text.TextOptions.TextExtractionOptions.TextFormattingMode.Raw), Encoding.ASCII)
device.Process(pdfPage, TempStream)

Dim newDoc As New Aspose.Pdf.Document()
newDoc.Pages.Add(pdfPage)
'newDoc.Save()
NextPage += 1
Next
I have tested the scenario and have managed to reproduce same problem. For the sake of correction, I have logged it as PDFNEWNET-40798 in our issue tracking system. We will further look into the details of these problems and will keep you posted on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.

The issues you have found earlier (filed as PDFNET-40798;PDFNET-40797) have been fixed in Aspose.Pdf for .NET 17.5.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan