Unplanned
Last Updated: 19 Sep 2017 19:31 by Vasim
Vasim
Created on: 30 Aug 2017 18:42
Category: PdfProcessing
Type: Feature Request
3
PdfProcessing: RadFixedDocumentEditor page created event
Currently, there is no way to know when a new page is created when content "overflows" to the next page 

This event may be needed in order to generate the header and footer based on the currently generated content. In simple header/footer scenarios, however, this event may not be needed and the headers and footers may be drawn after all pages are generated as described in the comments below.
4 comments
Vasim
Posted on: 19 Sep 2017 19:31
Thank you for the 2nd workaround, I appreciate it
ADMIN
Deyan
Posted on: 15 Sep 2017 08:56
Hello,

I have changed the feedback item' status to approved. As you are already following it you will be notified about its implementation progress.

Meanwhile, I would like to suggest one more possible workaround for the described scenario. You may cache the current document page number every time you finish exporting some employee information. This way you will have the needed information on which page some employee info ends and where the next employee content starts. This information should be enough to restart the page numbering for each employee section when drawing the headers and footers after all pages generation.

I hope this helps.

Regards, 
Deyan

P.S.: Here follows some modified code snippet showing the newly suggested workaround:

public static RadFixedDocument CreateDocumentWithHeadersAndFooters(Employee[] employees)
{
    RadFixedDocument document = new RadFixedDocument();
    Dictionary<int, int> employeeIdToEmployeeContentEndPageNumber = new Dictionary<int, int>();

    using (RadFixedDocumentEditor documentEditor = new RadFixedDocumentEditor(document))
    {
        foreach (Employee employee in employees)
        {
            GenerateEmployeeContentWithoutHeadersAndFooters(documentEditor, employee);
            int currentPageNumber = document.Pages.Count;
            employeeIdToEmployeeContentEndPageNumber.Add(employee.Id, currentPageNumber);
        }
    }

    int numberOfPages = document.Pages.Count;

    for (int pageIndex = 0; pageIndex < numberOfPages; pageIndex++)
    {
        int pageNumber = pageIndex + 1;
        FixedContentEditor pageEditor = new FixedContentEditor(document.Pages[pageIndex]);
        DrawHeaderAndFooter(pageEditor, pageNumber, numberOfPages, employees, employeeIdToEmployeeContentEndPageNumber);
    }

    return document;
}
Vasim
Posted on: 14 Sep 2017 17:03
Hi Deyan,

This workaround works well for fixed headers and page numbers; however, it does not help with dynamic headers that change their content. 

One Example:

I wanted to add employee ID top corner in the header 

During creation: I could not do so because there was no way for me to know when the page overflowed

After document creation: I cannot do that after the document is created because there is no way to know which page belongs to which employee.

Other examples:

Show continued on the overflowed page; Reset page number based on employee ID, again not possible for the same reasons as the first example

Thank you for taking your time looking into this, much appreciated
ADMIN
Deyan
Posted on: 14 Sep 2017 14:53
Hello,

For the required header/footer scenario we have one suggestion which we believe may be a good workaround to thе missing event. The suggestion is to add the headers and footers with FixedContentEditor instances for each page after all pages are created.

Could you confirm that this workaround would work for your scenario and that it removes the need of page created event?

Regards,
Deyan

P.S.: Here follows some code that illustrates the suggested workaround:

public static RadFixedDocument CreateDocumentWithHeadersAndFooters()
{
    RadFixedDocument document = new RadFixedDocument();

    using (RadFixedDocumentEditor documentEditor = new RadFixedDocumentEditor(document))
    {
        GenerateDocumentContentWithoutHeadersAndFooters(documentEditor);
    }

    int numberOfPages = document.Pages.Count;

    for (int pageIndex = 0; pageIndex < numberOfPages; pageIndex++)
    {
        int pageNumber = pageIndex + 1;
        FixedContentEditor pageEditor = new FixedContentEditor(document.Pages[pageIndex]);
        DrawHeaderAndFooter(pageEditor, pageNumber, numberOfPages);
    }

    return document;
}