Use existing PDF as Template for new generated PDF

Hello, 

i have one PDF document with one page. The page displays the company layout such as Header and Footer. I know want to take this document to be the "backround" of the new pdf i generate. I cant split the existing document in header or footer. If i use the DrawPdfTemplate my PageSettings Margins for the new document are used and so the template isn´t where it supposed to be. 

How can i achive the result to use the existing document to be present in all my new pages in the new PDF File. 


Thanks


3 Replies

GK Gowthamraj Kumar Syncfusion Team August 23, 2021 12:43 PM UTC

Hi Markus, 
 
Thank you for contacting Syncfusion support. 
 
We can add the existing PDF document page template as background for all the page in a newly generated PDF document. Please refer the below documentation for more information,

KB: https://www.syncfusion.com/kb/11735/how-to-add-page-as-background-in-an-existing-pdf-document-using-c
KB: https://www.syncfusion.com/kb/3677/how-to-use-the-existing-pdf-as-a-background-for-the-new-pdf-file
 
 
Please let us know if you need any further assistance with this. 
 
Regards, 
Gowthamraj K 



MN Markus Nebauer August 23, 2021 01:28 PM UTC

Hi Gowthamraj,

with the second link can´t set my needed margins as i mentioned before.

The first link worked but i need to save the generated PDF first reopen it draw Backround and save it again.

With this workaround i can live but would be nice if i can directly set the PDF Template that igonores my page margins.



GK Gowthamraj Kumar Syncfusion Team August 24, 2021 02:50 PM UTC

Hi Markus, 
 
Thank you for your update. 
 
We can set the page margin to the PageSettings before adding the page in a PDF document. Please try the below code on your end let us know the result. 
 
//Loads the Pdf document 
            PdfLoadedDocument ldoc = new PdfLoadedDocument("../../Data/Essential_Pdf.pdf"); 
            //Gets the particular page from Loaded document pages 
            PdfLoadedPage lpage = ldoc.Pages[0] as PdfLoadedPage; 
 
            //Create template for the Loaded Page 
            PdfTemplate template = lpage.CreateTemplate(); 
            //Creates new Pdf document 
            PdfDocument doc = new PdfDocument(); 
             
            //Sets document page margins to zero 
            doc.PageSettings.Margins.All = 0; 
            //Adds new Page 
            PdfPage page = doc.Pages.Add(); 
             
            //Draws Loaded page as background in the new pdf page using template of the loaded page. 
            page.Graphics.DrawPdfTemplate(template, new PointF(0, 0), page.Size); 
            //Save the document and dispose it. 
            doc.Save("../../sample1.pdf"); 
            doc.Close(); 
 
Note: We do not have support for changing/modifying the margins from existing PDF document. 
  
If still you are facing an issue, please share the input document, output document, expected result to check the issue on our end. So, that it will be helpful for us to analyze and assist you further on this.   
 
Regards, 
Gowthamraj K 


Loader.
Up arrow icon