Add new page with full size image to the Encrypted PDF using Aspose.PDF for .NET

I have existing PDF which is Encrypted.

following your instructions here I was able to create new page and insert image but I have to pass
lowerLeftX,lowerLeftY,upperRightX and upperRightY. my image is the whole page image.

How can I do this?
Aspose.Pdf.Generator.Pdf and created from Stream and add section containing image?
or there is a more simple way

Hi there,


Thanks for your inquiry. Please check following code snippet to add a whole page image as new page in an existing PDF document. Hopefully it will help you to accomplish the task.

string outFile =
“output.pdf”;<o:p></o:p>

string imageFile = "image1.jpg";

Document doc = new Document("output.pdf","password");

Page page = doc.Pages.Add();

FileStream fs = new FileStream(imageFile, FileMode.Open, FileAccess.Read);

// Set margins so image will fit, etc.

page.PageInfo.Margin.Bottom = 0;

page.PageInfo.Margin.Top = 0;

page.PageInfo.Margin.Left = 0;

page.PageInfo.Margin.Right = 0;

page.PageInfo.Height = Aspose.Pdf.PageSize.A4.Height;

page.PageInfo.Width = Aspose.Pdf.PageSize.A4.Width;

//Create an image object

Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();

//Add the image into paragraphs collection of the section

page.Paragraphs.Add(image1);

//Set the ImageStream to a MemoryStream object

image1.ImageStream = fs;

//Save

doc.Save(outFile);

Please feel free to contact us for any further assistance.


Best Regards,