Welcome Guest Search | Active Topics | Sign In | Register

Footer Page Numbers and Merging of PDFs Options
PGL
Posted: Thursday, June 20, 2013 4:54:49 PM
Rank: Newbie
Groups: Member

Joined: 6/20/2013
Posts: 6

I am successfully converting many URLs to PDFs, then merging them into 1 PDF. However, I am struggling to have the footer page numbers be accurate for the entire PDF. How can the footer know how many pages there are in the entire PDF because it is made up of so many PDFs merged together? Although there are 15 pages in the entire PDF, I am seeing page 1 of 2, then page 2 of 2, then page 1 of 3, etc.; it keeps restarting.



PdfDocument doc = new PdfDocument();
HtmlToPdfOptions opts = new HtmlToPdfOptions();
opts.HeaderHtmlFormat = String.Format(@"<center><br/><b>Date:</b>{0}<br/><br/><b>Event:</b>{1}<br/><b>Username:</b>{2}</center>",
System.DateTime.Now.ToString("dd-MMM-yyyy h:mm:sstt"), "R2342335644", username);
opts.FooterHtmlFormat = @"
<hr />
<div style=""text-align:center"">
Page {page_number}/{total_pages}
</div>
";
opts.RepeatTableHeaderAndFooter = true;
HtmlToPdf.Options.Follow(HtmlToPdf.ConvertUrl(@"http://CRF/Default.aspx?SelectedID=2097873", doc, opts));
HtmlToPdf.Options.Follow(HtmlToPdf.ConvertUrl(@"http://CRF/Default.aspx?SelectedID=2098829", doc, opts));
HtmlToPdf.Options.Follow(HtmlToPdf.ConvertUrl(@"http://
Code: C#
CRF/Default.aspx?SelectedID=2098908", doc, opts));
HtmlToPdf.Options.Follow(HtmlToPdf.ConvertUrl(@"http://EventAuditTrail.aspx?EventID=2097849", doc, opts));
HtmlToPdf.Options.Follow(HtmlToPdf.ConvertUrl(@"http://ManageOneEvent.aspx?EventID=2097849", doc, opts));
HtmlToPdf.Options.Follow(HtmlToPdf.ConvertUrl(@"http://CRF/AdjFormsForEvent.aspx?EventID=2097849", doc, opts));
HtmlToPdf.Options.Follow(HtmlToPdf.ConvertUrl(@"http://CRF/ClinicalCRFs.aspx?EventID=2097849", doc, opts));
HtmlToPdf.Options.Follow(HtmlToPdf.ConvertUrl(@"http://SourceDocs/SourceDocs.aspx?EventID=2048446", doc, opts));
doc.Save(@"c:\visual studio 2010\Projects\ConsoleApplication2\ConsoleApplication2\bin\Debug\Event.pdf");
eo_support
Posted: Thursday, June 20, 2013 4:59:10 PM
Rank: Administration
Groups: Administration

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

It will be much easier for you to generate the footer completely separately AFTER you have converted all the main contents. You will basically do something like this:

Code: C#
//Perform the main conversion
....

for (int i = 0; i < doc.Pages.Count; i++)
{
    PdfPage page = doc.Pages[i];

    //You need to set the OutputArea properly so that the output
    //goes to the bottom of the page (or anywhere else you want it
    //to go)
    HtmlToPdf.Options.OutputArea = .....

    //The first argument is your footer HTML. At this point you already
    //have information about everything, such as total page numbers
    //The second argument is the PdfPage object 
    HtmlToPdf.ConvertHtml(your_footer_html, page);
}

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

Thanks!
PGL
Posted: Friday, June 21, 2013 11:44:14 AM
Rank: Newbie
Groups: Member

Joined: 6/20/2013
Posts: 6

eo_support, I tried the code you suggested and the page numbering worked. But I was disappointed that the outputarea seemed to vary widely from page to page. It did not look good, although I used the same rectangle for each page. Any thoughts you can give me concerning the layout and positioning of this outputarea will be appreciated.

for (int i = 1; i < doc.Pages.Count; i++)
{
PdfPage page = doc.Pages[i];

//You need to set the OutputArea properly so that the output
//goes to the bottom of the page (or anywhere else you want it
//to go)
HtmlToPdf.Options.OutputArea = new RectangleF(0f, 1f, 1f, 2f);

//The first argument is your footer HTML. At this point you already
//have information about everything, such as total page numbers
//The second argument is the PdfPage object

HtmlToPdf.ConvertHtml(string.Format(
@"<div style=""text-align:center"">
Page {0}/{1}
</div>", i + 1, doc.Pages.Count), page);
}
eo_support
Posted: Friday, June 21, 2013 11:48:02 AM
Rank: Administration
Groups: Administration

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

It should not be. I am not sure why you set your outputarea's Width to just one inch. That might cause problem for you because if it is not wide enough, then the text position may change.

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.