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

Free Support Forum - aspose.com

Aspose PDF throws error stamping some PDF files

I’m using Aspose PDF 9.5.

The following error is thrown on the PdfFileStamp object AddStamp method.

Unhandled Exception: System.NullReferenceException: Object reference not set to
an instance of an object.
at Aspose.Pdf.Facades.PdfFileStamp.??¶(Stamp , Int32 )
at Aspose.Pdf.Facades.PdfFileStamp.??¶(Stamp )
at ERSClasses.MSDS2.PrintMSDS(Int32 listId) in C:\ers.Projects\Main\ClientInf
ormationSystem\ERSClasses\MSDS2.vb:line 392

The code causing that error is as follows:
Private _objStamp As New Facades.PdfFileStamp
Dim myFileStream As New FileStream(filename, FileMode.Open)
Dim myMemoryStream As New MemoryStream()
_objStamp = New PdfFileStamp(New Document(myFileStream))
_objStamp.Save(myMemoryStream)
Dim myText As New FormattedText()
myText.AddNewLineText(headerText)
Dim myStamp As New Facades.Stamp()
myStamp.BindImage(String.Format("{0}\whitebox.gif", _msdsPathBase))
myStamp.SetOrigin(0, 0)
myStamp.SetImageSize(_objStamp.Document.PageInfo.Width, 20)
_objStamp.AddStamp(myStamp)
_objStamp.Close()

Attached is one of the pdf files that throws the error

Hi there,


Thanks for your inquiry. It seems you are saving PdfFileStamp object before adding stamp so getting the issue please move save statement to end of the code as following. Hopefully it will help you to accomplish the task.


Private _objStamp As New Facades.PdfFileStamp<o:p></o:p>

Dim myFileStream As New FileStream(filename, FileMode.Open)

Dim myMemoryStream As New MemoryStream()

_objStamp = New PdfFileStamp(New Document(myFileStream))

'_objStamp.Save(myMemoryStream)

Dim myText As New FormattedText()

myText.AddNewLineText(headerText)

Dim myStamp As New Facades.Stamp()

myStamp.BindImage(String.Format("{0}\whitebox.gif", _msdsPathBase))

myStamp.SetOrigin(0, 0)

myStamp.SetImageSize(_objStamp.Document.PageInfo.Width, 20)

_objStamp.AddStamp(myStamp)

_objStamp.Save(myMemoryStream)

_objStamp.Close()


Please feel free to contact us for any further assistance.


Best Regards,

Your suggestion worked great. Thanks!

Hi there,


Thanks for your feedback. It is good to know that you have managed to accomplish the requirements.

Please keep using our API and feel free to ask any question or concern. We will be more than happy to extend our support.

Best Regards,