Adding an image to an extended feature enabled PDF flattens it

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

Hi Smita,


Sorry for the inconvenience faced. I’ve observed the issue, extended features are being lost while we add image in PDF form using incremental approach. I’ve already logged an investigation ticket as PDFNEWNET-35475 for further investigation and resolution. We will update you via this forum thread as soon as it is resolved.

Please feel free to contact us for any further assistance.

Best Regards,