How to print paginated visual in WPF?

I have a ScrollViewer and very "long" content. I wrote a class that inherits from DocumentPaginator, but I don’t understand how to create a “frame” for each part of this Visual? I mean, how do I “look” at the next page of the control? I tried this, but without success:

    public override DocumentPage GetPage(int pageNumber)
    {
        double left = pageNumber * pageSize.Width;
        Point pt = new Point(left, 0);

        visual.RenderTransform = Transform.Identity;
        visual.RenderTransform = new TranslateTransform(-left, 0);

        visual.Measure(pageSize);
        visual.Arrange(new Rect(visual.DesiredSize));

        DocumentPage page = new DocumentPage(visual);
        return page;
    }

With this code, I get the first page, as it should be, the second page is exactly the same as the first, and all the other pages are empty.

+3
source share
1 answer

DocumentPaginatorpretty hard. Here are a few steps that have helped me correctly evaluate page sizes and ensure there are no blank pages:

IsPageCountValid PageCount :

    public override bool IsPageCountValid
    {
        get { return true; }
    }

public override int PageCount
{
    get
    {
        if (pageCount == 0)
        {
            this.ComputePageCount();
        }
        return pageCount;
    }
}

ComputePageCount ( ).

,

IsPageCountValid= true

, Paginator overriden .

, DocumentPaginator.PageSize.

. , / PageCount.

+1

Source: https://habr.com/ru/post/1765100/


All Articles