How to Append content to the end of an existing PDF document?

I need to append an image to the end of an existing pdf document, such that a new page will be created if necessary. Is there a way to add the image to the end of the document flow, or is my only option to calculate an x.y position and programatically add a new page if necessary?


I am already doing something similar when I start with existing html and create a new pdf document:
var ms = new MemoryStream(Encoding.Unicode.GetBytes(html));
var doc = new Aspose.Words.Document(ms);
var docBuilder = new Aspose.Words.DocumentBuilder(doc);
ms.Close();
docBuilder.InsertParagraph();
docBuilder.InsertImage(myBmp);
doc.Save(outputFilename,Aspose.Words.SaveFormat.Pdf);

Is there a way I can do something similar to the above, with an existing pdf document? Or would it be more appropriate to load the pdf document into an Aspose.Words.Document and append the image that way?
Thanks,
Jeff

Hi Jeff,


Thanks for contacting support.

In order to accomplish your requirement, you need to first add an empty page to existing PDF file and then add the image to the newly added page. Please visit the following links for further information on

Besides this, you may also consider converting the image file to PDF format using Aspose.Pdf.Generator and concatenate the existing PDF file and newly created PDF document. For further information,

JeffGilbert:
OR would it be more appropriate to load the pdf document into an Aspose.Words.Document and append the image that way?
Hi Jeff,

Aspose.Words does not support the feature to load PDF documents. In order to load existing PDF file, you need to try using Aspose.Pdf.Document object.

Thanks!

Using the Aspose.Pdf.Generator was exactly what I needed.
Cheers,
Jeff

Hi Jeff,


I am glad to hear that your requirement is accomplished. Please continue using our products and in the event of any further query, please feel free to contact.

I was wrong. The Generator is not working for me after all.

Can you please tell me how to satisfy these requirements:
  1. Add an image to the end of an existing pdf document.
  2. The image must appear immediately after the existing content.
  3. The image must be on the same page as the existing content if it will fit.
  4. If the image does not fit on the same page as the the existing content, only then should a new page be created for the image.
The examples I have found so far fail to do what I need because they either place the content at specific x,y coordinates, or put the new content on a new page.

I am open to using aspose.pdf, or generator, or facades or whatever is necessary.

Thank you,
Jeff Gilbert


JeffGilbert:
  1. Add an image to the end of an existing pdf document.
  2. The image must appear immediately after the existing content.
  3. The image must be on the same page as the existing content if it will fit.
  4. If the image does not fit on the same page as the the existing content, only then should a new page be created for the image.
Hi Jeff,

Thanks for sharing the details.

In order to add image at the end of document,
  1. First you need to move to the last page of the document.
  2. Get the page height + width information of page.
  3. Traverse to the end of page contents (Image or Text) and get the location where the last object is location. i.e. If the file contains text, get the coordinates of last word in the document.
  4. Load the image in BitMap object and get the Height + Width information.
  5. If BitMap Height > Page Height - Position of last object, so remaining space cannot accommodate the image, therefore add new page and place the image inside it.
  6. If BitMap height < Page Height - Position of last object, which indicates the image can be placed in the same page, so no need to add another page.

You may consider visiting the following links for required information on
In case you still face the same issue, please feel free to contact.