Public Function PdfToXod(bytaPdfBytes As Byte(), ByRef bytaXodBytes As Byte()) As Integer Try
pdftron.PDFNet.Initialize()
Using objPdfDoc As New pdftron.PDF.PDFDoc(bytaPdfBytes, bytaPdfBytes.Length)
Dim objFilter As pdftron.Filters.Filter = pdftron.PDF.Convert.ToXod(objPdfDoc)
Dim objReader As New pdftron.Filters.FilterReader(objFilter) Dim objXodBytes As New List(Of Byte)
Dim bytaBuffer(30 * 1024) As Byte 'read 30 KB at a time
Dim intBytesRead As Integer
Dim blnAllBytesRead As Boolean = False
Do
intBytesRead = objReader.Read(bytaBuffer)
Select Case True
Case intBytesRead = bytaBuffer.Length
'buffer was fully filled
objXodBytes.AddRange(bytaBuffer)
Case Else
If intBytesRead > 0 Then
'buffer was partialy filled
ReDim Preserve bytaBuffer(intBytesRead - 1)
objXodBytes.AddRange(bytaBuffer)
End If
blnAllBytesRead = True
End Select
Loop Until blnAllBytesRead
bytaXodBytes = objXodBytes.ToArray
End Using Return 0
Catch ex As Exception
Return 1
End Try End Function
I am using this function to convert PDF to XOD. Why am I getting a PDFNetException {"bad allocation"} on line "intBytesRead = bjReader.Read(bytaBuffer) but only on some PDFs. Works fine on simple small PDFs. I am not running out of memory. This one file is 6Megs but has complex blue print markup.
Public Function PdfToXod(bytaPdfBytes As Byte(), ByRef bytaXodBytes As Byte()) As Integer
Try
pdftron.PDFNet.Initialize()
Dim objPdfDoc As New pdftron.PDF.PDFDoc(bytaPdfBytes, bytaPdfBytes.Length)
Dim objFilter As pdftron.Filters.Filter = pdftron.PDF.Convert.ToXod(objPdfDoc)
Dim objReader As New pdftron.Filters.FilterReader(objFilter)
Dim objXodBytes As New List(Of Byte)
Dim bytaBuffer(30 * 1024) As Byte 'read 30 KB at a time
Dim intBytesRead As Integer
Dim blnAllBytesRead As Boolean = False
Do
intBytesRead = objReader.Read(bytaBuffer)
Select Case True
Case intBytesRead = bytaBuffer.Length
'buffer was fully filled
objXodBytes.AddRange(bytaBuffer)
Case Else
If intBytesRead > 0 Then
'buffer was partialy filled
ReDim Preserve bytaBuffer(intBytesRead - 1)
objXodBytes.AddRange(bytaBuffer)
End If
blnAllBytesRead = True
End Select
Loop Until blnAllBytesRead
bytaXodBytes = objXodBytes.ToArray