Blank pages when implementing DocumentPaginator

2019-03-05 05:15发布

I'm trying to implement a Paginator like this:

public class MyPaginator : DocumentPaginator{

  // ommitting details...

  public override DocumentPage GetPage(int pageNumber) {
    DocumentPage page = new DocumentPage(canvas);
    return page;
  }
}

It compiles, it runs, but the page is blank (white). the 'canvas' is an instance of System.Windows.Controls.Canvas.

When I put it in a on-screen container like ScrollViewer it renders perfectly.

XpsDocument _xpsDocument = CreateXpsDoc(myPaginatorInstance);

The only thing that is working is that the page's size is set to the size of the canvas. What am I missing?

1条回答
该账号已被封号
2楼-- · 2019-03-05 06:04

I'll answer my own tumbleweed (again):

public override DocumentPage GetPage(int pageNumber) {
  Canvas container = new Canvas();
  container.Children.Add(canvas);
  double scaleX = pageSize.Width / canvas.Width;
  double scaleY = pageSize.Height / canvas.Height;
  container.RenderTransform = new ScaleTransform(scaleX, scaleY);

  container.Width = PageSize.Width;
  container.Height = PageSize.Height;
  container.Measure(PageSize);
  container.Arrange(new Rect(new Point(0, 0), PageSize));

  Rect contentBox = new Rect(PageSize);

  return new DocumentPage(container, PageSize, contentBox, contentBox);
}
查看更多
登录 后发表回答