Welcome Guest Search | Active Topics | Sign In | Register

What is the fastest way to add page number to existing PDFs? Options
Israel Romero
Posted: Thursday, May 10, 2018 6:46:30 PM
Rank: Newbie
Groups: Member

Joined: 5/10/2018
Posts: 3
Hi all.

I recently started using EO PDF and my new application concatenates several existing PDF documents into one large PDF. Then, it builds a table of contents (essentially another PDF doc with the index) and finally, it's supposed to add the page numbering to each one of the pages (which could be 1000+, depending on what the user selects)

To add the page number, I'm looping through each page on the document and used an HTMLToPDF.ConvertHTML statement to simply add the page number... and it works, BUT... it takes about 3-5 seconds per page! so, it finished my 1000+ pages in over 1.5 hours.

Is there a faster way to do it?

Here is my actual code:
Code: C#
private void Stamp(PdfDocument document, int offset)
        {
            int i = 0, PageNumber = 1;
            float tmpWidth = 0, tmpHeight = 0;
            HtmlToPdfOptions Options = new HtmlToPdfOptions();
            foreach (PdfPage Page in document.Pages)
            {
                if (i > offset) //It may not start the numbering on page 1
                {
                    //if the width or height of the new page are different from the page before, we need to account for them in the Options
                    if (tmpWidth != Page.Size.Width || tmpHeight != Page.Size.Height)
                    {
                        tmpWidth = Page.Size.Width;
                        tmpHeight = Page.Size.Height;
                        Options.OutputArea = new RectangleF((tmpWidth / 2), Convert.ToSingle(tmpHeight - 0.3), 10, 2);
                    }
                   //Then we add the page number to the page with the specified options
                   HtmlToPdf.ConvertHtml(PageNumber.ToString(), Page, Options);
                    PageNumber++;
                }
                i++;
            }
        }


Any insight is appreciated...
eo_support
Posted: Friday, May 11, 2018 11:28:44 AM
Rank: Administration
Groups: Administration

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

The fastest way for such case is to use the PDF Creator interface. See here for how to use the PDF creator interface:

https://www.essentialobjects.com/doc/pdf/acm/overview.aspx

Thanks!
Israel Romero
Posted: Friday, May 11, 2018 8:16:03 PM
Rank: Newbie
Groups: Member

Joined: 5/10/2018
Posts: 3
Thanks!
That worked Applause

To anyone else looking at this post - the article describes how each class is defined, but if you are looking for examples, I found the sample classes are very helpful, as the articles do not include any examples.
eo_support
Posted: Monday, May 14, 2018 10:16:53 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,221
Yes. The sample project contains a lot of source code that is meant to be a complement for the documentation.


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.