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

Free Support Forum - aspose.com

A generic error occurred in GDI+ when trying to create ImageStamp from stream

I am attempting to add an Image stamp to a PDF document created from scratch using the following code.


But every time I try to add the stamp I get an exception that reads: A generic error occurred in GDI+

var stream = typeof(SimpleReportGenerator).Assembly.GetManifestResourceStream(“SimpleReporting.assets.eec_full.jpg”);
if (stream != null)
{
var imageStamp = new ImageStamp(stream)
{
TopMargin = 10,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Top
};
foreach (Page page in _Doc.Pages)
{
page.AddStamp(imageStamp); // <<- Error happens here!
}
}

Hi Timothy,


Thank you for contacting support. Kindly send us your source PDF and image for the testing purposes. We are unable to find any problem when using one of our sample PDF files. Please also let us know which Aspose.Pdf for .NET API you are using because these details will help us to replicate this error in our working environment. Your response is awaited.

We are not starting with a document, we are creating it from scratch.


Here is the entire method from the creation of the blank doc to the save.

The image is part of the project and is set to be an embedded resource. We know that the path and the settings are correct because the stream variable is not null and contains a stream.

We are using Aspose.Pdf version 17.4.0.0 with a Total license.

public void Create()
{
	using (var doc = new Document())
	{
		var page = doc.Pages.Add();

		var stream = typeof(SimpleReportGenerator).Assembly.GetManifestResourceStream("SimpleReporting.assets.eec_full.jpg");
		if (stream != null)
		{
			var imageStamp = new ImageStamp(stream)
			{
				TopMargin = 10,
				HorizontalAlignment = HorizontalAlignment.Center,
				VerticalAlignment = VerticalAlignment.Top
			};

			page.AddStamp(imageStamp);
		}

		doc.PageInfo.Width = 612;
		doc.PageInfo.Height = 792;

		var dataDir = "C:\\report.pdf";
		doc.Save(dataDir);
	}
}
Hi Timothy,

Thank you for the details. We are still unable to replicate the same error in our environment. Kindly prepare a small application project, which reproduces this error in your environment, and then attach its zip to your reply. It will help us to replicate the same error. Your response is awaited.

Here is the project that is having the problem.


I removed the Aspose.Pdf.dll and Aspose.Pdf.XML files from the Assemblies\Aspose folder inside the project because they were so large. You will need to copy them back in before this project will compile.

I also delete the contents of the Aspose.Total.lic file so you will need to fill this back in before it will run.

~Tim

Hi Tim,


Thank you for sending a sample project. We could not replicate this error in our environment. We just copied Aspose.Pdf.dll and Aspose.Pdf.xml files in the specified folder of the project, removed your empty license file, and then added a new license file (as an embedded resource). When we executed your project, it generates a PDF in the root directory (C drive). You may not have a write permission on the root directory and thus an error occurred. It appears an environment specific error. You may also change the path of output PDF or run this sample project on any other machine.

Please let us know in case of any further assistance or questions.