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

Free Support Forum - aspose.com

Add Image to PDF with changed name of image gives error when opening output pdf file

I am working with Aspose .pdf for .Net with c#. When I Use the code copied from the sample code, the output file opens without problem. While adding the image to PDF file, if I change name of image using code
image.Name = “NewName”;
The output file gets created without any problem. When you try to open it under Acrobat reader, it gives error message.


We were able to notice the issue in our environment while using following code snippet with Aspose.PDF for .NET 20.6. We have logged it as PDFNET-48396 in our issue tracking system for the sake of investigation. We will further look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.

Document pdfDocument = new Document();
int lowerLeftX = 10;
int lowerLeftY = 10;
int upperRightX = 500;
int upperRightY = 500;
Page page = pdfDocument.Pages.Add();
FileStream imageStream = new FileStream(dataDir + "aspose.jpg", FileMode.Open);
page.Contents.Add(new Aspose.Pdf.Operators.GSave());
Aspose.Pdf.Rectangle rectangle = new Aspose.Pdf.Rectangle(lowerLeftX, lowerLeftY, upperRightX, upperRightY);
Matrix matrix = new Matrix(new double[] { rectangle.URX - rectangle.LLX, 0, 0, rectangle.URY - rectangle.LLY, rectangle.LLX, rectangle.LLY });
page.Contents.Add(new Aspose.Pdf.Operators.ConcatenateMatrix(matrix));
XImage ximage = page.Resources.Images[page.Resources.Images.Count];
ximage.Name = "NewName";
page.Contents.Add(new Aspose.Pdf.Operators.Do(ximage.Name));
page.Contents.Add(new Aspose.Pdf.Operators.GRestore());
page.PageInfo.Height = 288;
page.PageInfo.Width = 300;
dataDir = dataDir + "AddImage_out.pdf";

The issues you have found earlier (filed as PDFNET-48396) have been fixed in Aspose.PDF for .NET 20.7.

Thanks for the update.

I downloaded the new package from the site given .
A file named “aspose.pdf.20.7.0.nupkg” got downloaded of size approx 1.5GB.

But the file cant be opened. Must be because the “.nupkg” is non standard file extension.

Please throw some light on this.


You can directly install the API using NuGet Package Manager in Visual Studio. In case of manually download, please rename the downloaded package and change its extension as .zip. Then you will be able to extract the DLLs.