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

Free Support Forum - aspose.com

Null object reference

I'm recieving + System.InvalidCastException {"Unable to cast object of type '.' to type '.'."} System.InvalidCastException when TextFragmentAbsorber is used when loading a document from a byte array.

Works fine If I Create document from a PDF file

Sample Code:

Dim license As Aspose.Pdf.License = New Aspose.Pdf.License

license.SetLicense("Aspose.Pdf.lic")

Dim ms As MemoryStream = New MemoryStream(r.MarketRiderPDF)

Dim doc As New Document(ms)

Dim textFA As New Text.TextFragmentAbsorber("@COMPANYNAME")

For Each p As Page In doc.Pages

p.Accept(textFA)

For Each frag As Text.TextFragment In textFA.TextFragments

frag.Text = rg.Parent.CompanyName

Next

Next


Hi Randy, <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for considering Aspose.Pdf.

Please download and try the latest version of Aspose.Pdf for .NET v6.5 and if you still face any issue, please share your template PDF file with us to help us regenerate the issue at our end. This way we will be able to identify and rectify the issue soon.

Thank You & Best Regards,

I download V6.5 and had the same issue, I'm acually pulling the docs from BinaryArray in a SQL Server 2008 database

Attached you will find the 2 PDF files, I'm using

SQL user to load in database:

INSERT MarketRider(MarketId,StartDt,EndDt,MarketRiderDescr,AttribMatchExpression,IsActive,CreatedBy,CreatedDt,MarketRiderPDF) SELECT 1,'1/1/2012','12/31/2049 23:59:59','IL RR GOVT','[IsGovt]',1,@CreatedBy,GetDate(),* FROM OPENROWSET(BULK N'\\IES-SQLID6\QuantiShare\IL RR GOVT 09-2010 - QUANTI.pdf', SINGLE_BLOB) AS MarketRiderPDF

INSERT MarketRider(MarketId,StartDt,EndDt,MarketRiderDescr,AttribMatchExpression,IsActive,CreatedBy,CreatedDt,MarketRiderPDF) SELECT 1,'1/1/2012','12/31/2049 23:59:59','Federal Healthcare Program','[IsHealthCare] and not[IsResidential]',1,@CreatedBy,GetDate(),* FROM OPENROWSET(BULK N'\\IES-SQLID6\QuantiShare\Federal Healthcare Program Rider PSA 02-2010 - QUANTI.pdf', SINGLE_BLOB) AS MarketRiderPDF

MarketRider.GetForRequestGroup(Rg) - Returns the 2 docs as byte() from SQL Server

1 Doc has @COMPANYNAME once and the other docs has 2 instances of @COMPANYNAME, the doc with 1 instance does not fail with a null object reference the other does where there are multiple instances. It actually fails trying to update the second fragment.

Entire Code

For Each r In MarketRider.GetForRequestGroup(rg)

'add company name to each rider

Dim license As Aspose.Pdf.License = New Aspose.Pdf.License

license.SetLicense("Aspose.Pdf.lic")

Dim ms As MemoryStream = New MemoryStream(r.MarketRiderPDF)

Dim doc As New Document(ms)

Dim textFA As New Text.TextFragmentAbsorber("@COMPANYNAME")

For Each p As Page In doc.Pages

p.Accept(textFA)

For Each frag As Text.TextFragment In textFA.TextFragments

frag.Text = rg.Parent.CompanyName

Next

Next

Hi Randy,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for sharing the template files and sample code.

I am able to reproduce your mentioned issue. Your issue has been registered in our issue tracking system with issue id: PDFNEWNET-32657. You will be notified via this forum thread regarding any update against your issue.

Sorry for the inconvenience,

Can you provide an estimated resolution date for this issue?

Hi Randy,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

I have requested our development team to share an ETA regarding your issue. As soon as I get a feedback, I will update you via this forum thread.

Sorry for the inconvenience,

Hi Randy,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

I got a response from our development team regarding the resolution of your issue. As per our current development plan, your issue will be fixed and will be included in our February official release (Aspose.Pdf for .NET v6.7). Once the issue is fixed and available for download, we will update you via this forum thread.

Thank You & Best Regards,

The issues you have found earlier (filed as PDFNEWNET-32657) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.