Welcome Guest Search | Active Topics | Sign In | Register

Merging PDF as Background for another PDF Options
Adam Saunders
Posted: Wednesday, January 11, 2017 4:19:02 AM
Rank: Member
Groups: Member

Joined: 4/7/2016
Posts: 10
I haven't had any luck in finding anything that would help steer me in the right direction with this. I'm looking to have an existing PDF document containing one page that can be used as a background for every page of a generated PDF.

Is this possible? I've seen a lot of systems capable of layering an existing PDF over and under another document, but not sure how I would accomplish this with EO.PDF?
eo_support
Posted: Wednesday, January 11, 2017 8:23:29 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

If you use HTML to PDF, you would do something like this:

Code: C#
//Load the existing document
PdfDocument doc = new PdfDocument(your_existing_pdf);

//Start from page 0, this output to the existing page 
//instead of adding new pages
HtmlToPdf.Options.StartPageIndex = 0;

//Output HTML to the existing PDF file
HtmlToPdf.ConvertUrl(url, doc);


The above code will use all the existing page in your PDF file, and then add new pages. So for example, if your background PDF file is 1 page and your HTML output is 3 pages, then the first page will have background, and the second and the third won't. If you wish it to have background page in all three pages, you can follow these steps:

1. Run the conversion once to get the total page number:

Code: C#
//Get the total page number for an HTML
PdfDocument doc = new PdfDocument();
HtmlToPdf.ConvertUrl(url, doc);
int pageCount = doc.Pages.Count;


2. Duplicate your background PDF file to contain that many pages by using PdfDocument.Merge

Code: C#
//Create a single PDF file with the same page repeating pageCount times
PdfDocument[] docs = new pdfDocument[pageCount];
for (int i = 0; i < pageCount; i++)
{
    docs[i] = new PdfDocument(your_existing_pdf_file);
}
PdfDocument result = PdfDocument.Merge(docs);


You can then run ConvertHtml again on the above result PdfDocument and have background on every page.

Hope this helps. Please let us know if you still have any more questions.

Thanks!
Adam Saunders
Posted: Wednesday, January 11, 2017 8:56:02 AM
Rank: Member
Groups: Member

Joined: 4/7/2016
Posts: 10
This is incredibly useful. Thank you so much!!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.