Paginate using DocumentPaginator from FlowDocument that contains StackPanel

2.2k views Asked by At

I want to generate paginated documents from FlowDocument object that contains a StackPanel element. I tried using DocumentPaginator.

So far I have tried this code below, but no luck for me, that is, only one truncated page is generated and its content is cut in half vertically.

// stackPanel contains elements that their total heights 
// make the page should break into several pages.
StackPanel stackPanel = ...;

BlockUIContainer blockUiContainer = new BlockUIContainer(stackPanel);
FlowDocument flowDoc = new FlowDocument(blockUiContainer);
flowDoc.PageHeight = InchToPoint(paperSizeA4.Height); // paperSizeA4.Height: integer value
flowDoc.PageWidth = flowDoc.ColumnWidth = InchToPoint(paperSizeA4.Width); // paperSizeA4.Width: integer value
flowDoc.PagePadding = new Thickness(40);

DocumentPaginator docPaginator = ((IDocumentPaginatorSource)flowDoc).DocumentPaginator;
docPaginator.ComputePageCount();


When I print the document to PDF, this is the result, as I said before, only one page and its content is cut in half vertically (the document in this image is 50% zoomed out):

The result document


Am I missing something to make the paginating works? Or did I implement it in a wrong way?

1

There are 1 answers

0
Kohanz On

BlockUIContainer cannot span multiple pages. I suggest taking out the StackPanel and using a BlockUIContainer for each element in the list.