Free Support Forum -

Adding a shape (line) to an existing document


I can't seem to find a way to add a shape (specifically, a line) to an existing document. The documentation has many examples on how to do this using the aspose.pdf.generator classes but I have yet to understand how to do this to an existing document.

I have a document that I create by concatenating multiple PDFs together from different authoring sources. Once combined into a single document I have to create a header and footer on all pages. The approach I have taken is to loop through every page in the document, and use the text and image stamps to insert things like logos, page numbers, timestamps, etc. with no problems. All that is left is to insert a horizontal line beneath the header are and above the footer area to have a visual separation between those areas and the page content. This has proven to be quite the challenge.


Hi Salomon,

In order to add line in existing PDF file, please try using CreateLine(…) method of PdfContentEditor class. Please take a look over following code line to accomplish your requirement.


PdfContentEditor editor = new


editor.CreateLine(new System.Drawing.Rectangle(0, 0, 100, 100), "Welcome to Aspose", 0, 0, 100, 100,

1, 1, System.Drawing.Color.Red, "D", new int[] { 2, 3 }, new string[] { "OpenArrow", "ClosedArrow" });


Furthermore, in order to add Header/Footer to existing PDF file, please try using AddHeader(…) and AddFooter(…) methods of PdfFileStamp Class.

That worked, thanks!