I want to know what is the best pratice to move an existing image with c# ?
I’m currently using Aspose.pdf with ImagePlacementAbsorber to know where is images on PdfPage.
After that, I’m struggling to move an existing image with aspose.
If possible can you please share a sample PDF along with an expected output PDF that you want to achieve. We will check the feasibility and share our feedback with you.
For example, in this pdf, I want to move center image from first page. There is an other image I want to move in the second page, it’s the monitor image. It has been recognized as an image with the imageplacementabsorber.
Do you want to move the images to some other page or simple want to move it inside same page at different location? Do you have information of location or coordinates at where you want to place it?
I want to move in the same page and after that yes, I want to move other page. Just for your information, I have an control with an adorner to move it and when I stop to moving my goal is to move that image into the pdf.
Yes like I said before, with my adorner I can have the position of my rectangle when I stop moving my adorner. But I don’t have any idea how to proceed to move an existing image from Page.Ressources.Images to the new position. Only way to know the position of an image, is to use ImagePlacementAbsorber and there is an lot of property from Ximage that we can’t modify.
We tried something below but we are not sure if it will meet your requirements. We are not sure how your adorner will return the rectangle coordinates and those coordinates will be translated inside PDF via API:
// Load the PDF document
Document pdfDocument = new Document("input.pdf");
// Initialize ImagePlacementAbsorber to find images
ImagePlacementAbsorber absorber = new ImagePlacementAbsorber();
pdfDocument.Pages.Accept(absorber);
// Loop through images found in the PDF
foreach (ImagePlacement imagePlacement in absorber.ImagePlacements)
{
// Get image's position and dimensions
Aspose.Pdf.Rectangle rect = imagePlacement.Rectangle;
// Move the image by modifying the matrix
imagePlacement.Matrix.Transform(new Aspose.Pdf.Rectangle(0, 0, 100, 100));
}
// Save the updated PDF
pdfDocument.Save("output.pdf");
Therefore, we have logged an investigation ticket as PDFNET-58332 in our issue management system. We will look into details of this feature and let you know once the ticket is resolved. In the meanwhile, can you please share extracted coordinates by your adorner with the screenshot of page with those coordinates? It will help us in investigation.
This code snippet “imagePlacement.Matrix.Transform(new Aspose.Pdf.Rectangle(0, 0, 100, 100));” don’t move any images.
I have put my case testing in attachment with a screenshoot with the red adorner on the image I want to move. The red adorner is what I get from ImagePlacement Absorber.
The code we shared with you didn’t work in our environment either that is why we logged an issue in our issue tracking system to address this case. We apologize if sharing it caused any kind of confusion for you that it should work. Nevertheless, further details provided by you have been added to the already logged ticket and as soon as we make some progress towards its resolution, we will inform you and showcase the code snippet in our examples as well.