Hi,
On adding an image to a PDF which has extended features ON with the below code still flattens it.
using (FileStream fs = new FileStream(inputFilePath, FileMode.Open, FileAccess.ReadWrite))<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
{
Document pdfDocument = new Document(fs);
//set coordinates
int lowerLeftX = 100;
int lowerLeftY = 100;
int upperRightX = 200;
int upperRightY = 200;
//get the page where image needs to be added
Aspose.Pdf.Page page = pdfDocument.Pages[1];
//load image into stream
FileStream imageStream = new FileStream(Server.MapPath("Lib\\Image.png"), FileMode.Open);
//add image to Images collection of Page Resources
page.Resources.Images.Add(imageStream);
//using GSave operator: this operator saves current graphics state
page.Contents.Add(new Operator.GSave());
//create Rectangle and Matrix objects
Aspose.Pdf.Rectangle rectangle = new Aspose.Pdf.Rectangle(lowerLeftX, lowerLeftY, upperRightX, upperRightY);
Aspose.Pdf.DOM.Matrix matrix = new Aspose.Pdf.DOM.Matrix(new double[] { rectangle.URX - rectangle.LLX, 0, 0, rectangle.URY - rectangle.LLY, rectangle.LLX, rectangle.LLY });
//using ConcatenateMatrix (concatenate matrix) operator: defines how image must be placed
page.Contents.Add(new Operator.ConcatenateMatrix(matrix));
XImage ximage = page.Resources.Images[page.Resources.Images.Count];
//using Do operator: this operator draws image
page.Contents.Add(new Operator.Do(ximage.Name));
//using GRestore operator: this operator restores graphics state
page.Contents.Add(new Operator.GRestore());
//save updated document
pdfDocument.Save();
}
Regards,
Smita