Free Support Forum - aspose.com

Adding a shape (line) to an existing document

Hi,

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.

Thanks!

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.

[C#]

PdfContentEditor editor = new
PdfContentEditor();<o:p></o:p>

editor.BindPdf("c:/pdftest/AlignmentIssue.pdf");

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" });

editor.Save(“c:/pdftest/Line_example_out.pdf”);


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

That worked, thanks!