Welcome Guest Search | Active Topics | Sign In | Register

Continuous page number problem Options
10bulls
Posted: Monday, August 8, 2011 11:39:50 AM
Rank: Newbie
Groups: Member

Joined: 8/8/2011
Posts: 2
I have just started evaluating EO.Pdf and so far I am quite impressed.

However, I have run into a couple of problems...

I am trying to create PDF user documentation from multiple HTML sections.

I want to include a continuous page number at the bottom of each page.
Here is some sample code to show how I am going about this.

Code:

PdfDocument pdfdoc = new PdfDocument();

for (int i = 0; i < 10; i++)
{
    string html = String.Format("<h1>Section{0}</h1>",i);
    html += "<div style=\"page-break-after: always\">Here is some text</div>";
    html += "Here is some more text";

    HtmlToPdf.Options.StartPageIndex = pdfdoc.Pages.Count + 1;
    HtmlToPdf.Options.FooterHtmlFormat = "<div style='text-align:center'>page {page_number}</div>";
               
    HtmlToPdfResult ret = HtmlToPdf.ConvertHtml(html, pdfdoc);
    // HtmlToPdf.Options.Follow(ret);
}

pdfdoc.Save(@"C:\dump\pdftest.pdf");


Unfortunately the page numbers are always numbered starting from page 1 at the beginning of each section.

I have tried setting HtmlToPdf.Options.StartPageIndex but this does not change the {page_number} variable.

I have also tried using HtmlToPdf.Options.Follow() method, which forms a continuous document, but the {page_number} variable still resets to 1 at the start of each conversion.

I may be able to work around this using the AfterRenderPage() handler, but it would be nice not to have to.

Am I doing something wrong, or it this perhaps a bug?

BTW: I have also tried concatenating all my html sections then converting once.
This gives me continuous page numbers, but throws up another problem:
My html sections contain a number of images. When running multiple conversions, these are all included fine. When running a single conversion, the pictures are OK for the first 40 pages of around 180 pages, but then after this all the picutures are blank (although the text layout is leaving correct sized gaps where the images should be).
I will investigate this some more then perhaps post this in a seperate topic.

Many thanks for any help!
eo_support
Posted: Monday, August 8, 2011 12:00:04 PM
Rank: Administration
Groups: Administration

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

Thanks for posting in the forum. As to your questions:

1. The page number issue is by design. See below for more details;

2. The image issue appears to be a bug. We are trying to reproduce it. It will be great if you can send us a test project that can demonstrate the problem;

The page number always starts from 1 for every conversion. It has no relation to StartPageIndex. StartPageIndex specifies the first page the conversion starts with. For example, you may have a document that already have 4 pages but then you just wanted to "fill in" some additional contents starting from somewhere on the second page. In that case you can set StartPageIndex to 1. Follow updates StartPageIndex.

The easiest way for you to add a continuous page index is to finish all the conversions first, then do a "post process" to add the page numbers. You can find sample code here:

http://www.essentialobjects.com/forum/postst5851_Sample-merging-multiple-PDF-files-and-adding-page-numbers.aspx

This is easier than handling AfterRenderPage event. It also allows you to add page numbers based on whatever special logics you have. For example, if the first page is just a "cover page", then you can skip that in your code.

Hope this helps. Please let us know whether you can provide a test project for the image issue. In that case we will PM you as to where to send it.

Thanks!
10bulls
Posted: Monday, August 8, 2011 2:31:36 PM
Rank: Newbie
Groups: Member

Joined: 8/8/2011
Posts: 2
Thank you for the quick response.

Using the AcmRender method worked for the page numbering.

I appreciate this is 'by design', but I find it hard to think of a situation where you wouldn't want a page number to refer to the current page within a pdf document. Might I suggest a feature request to at least add an option to set the {page_number} start offset?

I can replicate the image problem pretty easily using the following code:

You can download the .png image I am using here...
http://www.cambam.info/doc/dw/0.9.8/images/user-interface-m.png
...but it seems any image file will do.

200 pages are created, but the images stop working at page 51 in this case.
Interestingly the very last image is cut off part way.
Possibly a memory related bug?

If I use code similar to the first example, where I using multiple calls to ConvertHtml(), the document works fine and all images are included.

Thank you once again for your fast response!

Code:

PdfDocument pdfdoc = new PdfDocument();

StringBuilder sb = new StringBuilder();

for (int i = 0; i < 100; i++)
{
    string html = String.Format("<div style=\"page-break-before: always\"><h1>Section{0}</h1>", i);
    html += "<div style=\"page-break-after: always\">Here is some text<br/><img src=\"user-interface-m.png\"/></div>";
    html += "<img src=\"user-interface-m.png\"/><br/>";
    html += "Here is some more text";
    sb.Append(html);   
}

HtmlToPdf.Options.BaseUrl = "file://C:/dump/";
HtmlToPdfResult ret = HtmlToPdf.ConvertHtml(sb.ToString(), pdfdoc);

for (int i = 0; i < pdfdoc.Pages.Count; i++)
{
    EO.Pdf.Acm.AcmText text = new EO.Pdf.Acm.AcmText("page " + (i + 1).ToString());
    EO.Pdf.Acm.AcmRender render = new EO.Pdf.Acm.AcmRender(pdfdoc.Pages[i],
                                                                    10.5f, new EO.Pdf.Acm.AcmPageLayout(new EO.Pdf.Acm.AcmPadding(4, 0, 1, 0)));
    render.Render(text);
}

pdfdoc.Save(@"C:\dump\pdftest2.pdf");

eo_support
Posted: Monday, August 8, 2011 3:05:41 PM
Rank: Administration
Groups: Administration

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

Thanks for the suggestion and the test code. A {page_number} start offset does make sense. However if you run continuous HTML conversions, that value must be automatically updated so the next conversion's page number will continue. We will think about that and see if we can implement it.

As to the image issue, it could be a memory problem. We will look into that and see what we can find.

Thanks
eo_support
Posted: Thursday, August 11, 2011 4:27:23 PM
Rank: Administration
Groups: Administration

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

We have posted a new 2011.2.56 that should address both issues. You can download the new build from the download page. This build:

1. Added HtmlToPdf.Options.FirstPageNumber. You can use this property to specify the first page number;
2. It should load all images now. Note this is not without limit. If you have a lot of images, then it still can run out memory and crash;

Please take a look and let us know how it goes!

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.