Welcome Guest Search | Active Topics | Sign In | Register

Header and footer on multiple pdfdocuments ? Options
Nuno Nogueira
Posted: Tuesday, September 6, 2011 10:04:14 AM
Rank: Member
Groups: Member

Joined: 2/24/2011
Posts: 25
Hello

I'm building a model where I create multiple PDF files via eo.pdf, is there any way to include header and footer as is done in method beforerenderpage?

I created several documents because some need to extract the HTML content, and other content is created manually, making it a mixed pdf.

Is there a model there somewhere? searched the documentation and did not find an example, just need to get these documents and put the header / footer.

thanks
eo_support
Posted: Tuesday, September 6, 2011 10:24:37 AM
Rank: Administration
Groups: Administration

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

We provide several methods for you to add header and footer. You can choose either one or a combination of multiple methods depending on your personal preference or which way is more convenient for you.

The basic idea of adding header and footer is the same as outputting anything else ---- except that you are outputting to a page that already has contents on it. For example, the following sample convert Google’s home page and then add a header on it:

Code: C#
//Output the main content
PdfDocument doc = new PdfDocument();
HtmlToPdf.ConvertUrl("http://www.google.com", doc);

//Output header. Points of interest:
//1. You must set OutputArea to override the default output
//    area. The default output area has a 1 inch margin on
//    all sides;
//2. The second argument of ConvertHtml is a PdfPage object.
//    This explicitly outputs to the specified page;
HtmlToPdf.Options.OutputArea = new Rectangle(0, 0, 8, 11);
HtmlToPdf.ConvertHtml("header text", doc.Pages[0]);


As such, the most straight forward way for you to create header/footer is to create all the PDF files first, then run a loop on all PdfPage object to add the footer and header.

There are several alternatives but they all based on the same idea:

1. Instead of using ConvertHtml to output header/footer, you can use ACM (The PDF Creator interface). ACM is more "object oriented" comparing with HTML which is markup based;

2. Instead of rendering header/footer afterwards in a loop, you can handle BeforeRenderPage/AfterRenderPage to render your header/footer. There is no signficant difference between these two events and rendering it in a loop. It's just a matter of different coding structures/styles;

3. If you only use HTML to PDF and only has simple header/footer, then you can set HtmlToPdf.Options.HeaderHtmlFormat and FooterHtmlFormat and have the converter to automatically add header/footer for you;

Hope this helps. Please feel free to let us know if you have any more questions.

Thanks!
Nuno Nogueira
Posted: Tuesday, September 6, 2011 10:32:06 AM
Rank: Member
Groups: Member

Joined: 2/24/2011
Posts: 25
Thanks for the reply.

I was able to perform the procedure by creating a new content, performing a merge of the documents, and using a page layout in the new document that was obtained from the merge.

Like this:



Dim pageLayout As New AcmPageLayout(New AcmPadding(0.6, 0.2, 0.6, 0.2))
Dim emptycontent As AcmContent = New AcmContent(New AcmText(""))
Dim doc3 As PdfDocument = PdfDocument.Merge(doc, doc1)
Dim render2 As New AcmRender(doc3, pageLayout)
AddHandler render2.BeforeRenderPage, New AcmPageEventHandler(AddressOf BeforeRenderPage)

render2.Render(emptycontent)



doc3.Save(Response.OutputStream)
eo_support
Posted: Tuesday, September 6, 2011 10:39:06 AM
Rank: Administration
Groups: Administration

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

Yes. That should work.

Thanks


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.