我想从FlowDocument
包含StackPanel
元素的对象生成分页文档。我尝试使用DocumentPaginator
.
到目前为止,我已经尝试了下面的这段代码,但对我来说没有运气,即只生成了一个被截断的页面,其内容被垂直切成两半。
// 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();
当我将文档打印为 PDF 时,结果是,正如我之前所说,只有一页,其内容被垂直切成两半(此图像中的文档缩小了 50%):
我是否缺少使分页起作用的东西?还是我以错误的方式实施它?