简体   繁体   中英

Paginate using DocumentPaginator from FlowDocument that contains StackPanel

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):

结果文件


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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM