Add Image end of the PDF content using C# with Aspose.PDF for .NET

Hi,
We trying to append the image, Last page of PDF content end position accurately. Please share any example code.

Hi,


Thank you for contacting support. Using Aspose.Pdf API, you can retrieve a page by index and define the rectangle location where you require to place an image. You can also add an empty page to existing PDF file and then add the image to the newly added page. Please refer to these help topics: Add Image in the Existing PDF File and Insert an Empty Page at the End of a PDF File

Please let us know in case of any further assistance or questions.

Hi,


In addition to the above reply, you can get the rectangular coordinates of the last text fragment and PDF page (which you can retrieved by an index), and then compare the available space at the end of this page with the image size. Finally, you will be able to apply a check in the code, whether to place an image in the end of this page or add a new empty page, and then place an image. You can retrieve the rectangle coordinates of the last text fragment and PDF page by using the following code:
// Open document
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(@"C:\Pdf\test104\input.pdf");
// Create TextAbsorber object to find all instances
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber();
// Accept the absorber for the page index 1
pdfDocument.Pages[1].Accept(textFragmentAbsorber);
// Get the extracted text fragments
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
// get the rectangle location of the last text fragment
Aspose.Pdf.Rectangle lastFragmentRect = textFragmentCollection[textFragmentCollection.Count].Rectangle;
// get the rectangle of PDF page
Aspose.Pdf.Rectangle pageRect = pdfDocument.Pages[1].Rect;