Create Stamp Object from Resource File

I’ve searched the forums [and the web], but couldn’t really find anything helpful. I use Visual Basic and I’m currently using ImageStamp in Aspose.Pdf instead of Aspose.Pdf.Facades.Stamp [see also here], but I don’t have a preference either way yet.

The image I want to add as a stamp is a resource file contained in my
project. The constructor for ImageStamp(), and I think for
Facades.Stamp() as well, requires the file path to initialise a new
object. I’ve tried using a file stream, which works in getting me the images as stamps [although it’s rather ugly], however for some reason the position of the stamps gets skewed now. I swear I have not changed anyhing in my code besides how the ImageStamp object is initialised.

Old:

Dim imageStamp as new ImageStamp("C:/path/to/file.png")
[...]
Me.workingCopy.Pages(pageNumber).AddStamp(imageStamp)

New:

Dim imageStamp As ImageStamp
Dim assembly As Assembly = GetType(Stamp).Assembly

Using reader As New StreamReader(assembly.GetManifestResourceStream("$namespace.file.png"))
    imageStamp = New ImageStamp(reader.BaseStream)

    [...]

    Me.workingCopy.Pages(pageNumber).AddStamp(imageStamp)
End Using

Any suggestions?

Hi,


We are working of this query and will get back to you soon.

Hi Sorin,


Thanks for contacting support.

I have tested the scenario using one of my sample PDF files and as per my observations, when using ImageStamp object to add image stamp to PDF file, it properly appears in resultant document (either using Stream instance or loading file from system path). Furthermore, as shared in your other forum thread, Aspose.Pdf.ImageStamp is recommended approach for PDF file creation, as well as its manipulation.

Can you please share some sample application with resource files, so that we can test the scenario in our environment. We are sorry for your inconvenience.

Yes, that’s true and it works for me as well. but what I want is to create an ImageStamp from a program resource. I.e. My.Resources.StampImage [this will return a Bitmap object]. I don’t want to store the images in a specific subfolder of my program, especially since I need them as resources anyway and I don’t have control about the installation environment etc. etc.

Hi Sorin,


Thanks for your feedback. We are looking into it and will update you soon.

Best Regards,
AzraelSeraphin:
Yes, that's true and it works for me as well. but what I want is to create an ImageStamp from a program resource. I.e. My.Resources.StampImage [this will return a Bitmap object]. I don't want to store the images in a specific subfolder of my program, especially since I need them as resources anyway and I don't have control about the installation environment etc. etc.
Hi Sorin,

Thanks for sharing the details.

Can you please try saving the StampImage (holding Bitmap object) to Stream instance and then try instantiating ImageStamp from stream object. Or if you have tried following similar approach, what issues you are facing. Please share some further details, so we may further look into this matter.