Push page content down after inserting Image

Hi,

when I insert an Image in middle of pdf doc the Image overlap and hide the existing content on page, is there any way I can insert Image based on coordinate so that the rest of content pushes itself down the Image, right now after placing Image in existing pdf the Image hiding content behind it.

Thanks
saan123

@saan123,
You can insert an image and use the ConcatenateMatrix operator to define the location of an image on the page. Please refer to this help topic: Add Image to Existing PDF File

Thanks
I used the example code your referred me, It’s inserting image at a defined location but overwriting the existing text content on the page, I need to push the content down the Image so both Image and text should be visible, I am writing text in order of Column1 and Column2 so the flow is like this…Page 1-> write content on Column1 first then move and write on Column2, if we still have more content to write then continue writing on Page2 Columns1 and so on…

The input and output files are attached for Image insert and below code is used

// Open document
Document pdfDocument = new Document(“InputFile_TwoColumns.pdf”);
// Set coordinates
int lowerLeftX = 81;
int lowerLeftY = 300;
int upperRightX = 200;
int upperRightY = 400;

// Get the page where image needs to be added
Aspose.Pdf.Page page = pdfDocument.Pages[1];
// Load image into stream
FileStream imageStream = new FileStream(“GoogleImage.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);
Matrix matrix = new 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(“outputFile_WithImage.pdf”);

GoogleImage.png (30.5 KB)

InputFile_TwoColumns.pdf (6.3 KB)

outputFile_WithImage.pdf (34.1 KB)

Thanks

@saan123,
Please note, PDF is a fixed file format and the other elements do not move after the placement of an image. You can insert text and image as inline paragraph. Please refer to this help topic: Text and Image as InLine paragraph