Print flowdocument scroll viewer on multiple pages

房东的猫 提交于 2019-12-11 01:08:51

问题


I'm trying to print my FlowDocument (which is wrapped into a FlowDocumentScrollViewer) because I have a lot of texts/Textbox/combobox and the page height can become high !

I'm using this :

PrintDialog printDialog = new PrintDialog();
if (printDialog.ShowDialog() == true)
{
    Scrollvvv.Document.ColumnWidth = printDialog.PrintableAreaWidth;
    Scrollvvv.Document.ColumnGap = 0;
    printDialog.PrintDocument(((IDocumentPaginatorSource)Scrollvvv.Document).DocumentPaginator, ServicesLangue.RM.GetString("TITRE_MODIFIER_SALON_EXPOSANT"));
}

My xaml looks like :

<FlowDocumentScrollViewer Name="Scrollvvv" VerticalScrollBarVisibility="Auto">
    <FlowDocument Name="flowDoc" PagePadding="10">
        <Section>
            <BlockUIContainer>
                <Grid Name="grid_principale">
                    <!-- Lot of stuffs here -->
                </Grid>
            </BlockUIContainer>
        </Section>
    </FlowDocument>
</FlowDocumentScrollViewer>

The thing is : It prints all my data in 1 page, the width is ok (i might add some margin but that's ok) but it compresses all my controls to fit in one page in height.

How to fix this ? I'd just want to disable this auto Height and keep the original size.


回答1:


The problem is that you are putting everything inside single BlockUIContainer. DocumentPaginator has trouble in paginating the BlockUIContainer i.e. splitting it into multiple pages. If your UI is static you can use multiple BlockUIContainers to wrap your UI. i.e.

    <BlockUIContainer>
      <Grid Name="grid_principale">
       <!-- Grid content here -->
      </Grid>
    </BlockUIContainer>
    <BlockUIContainer>
      <Grid Name="grid_principale2">
       <!-- Grid content here -->
      </Grid>
    </BlockUIContainer>

This will generate multiple pages. Also you will have to set your FlowDocument.PageHeight before printing.



来源:https://stackoverflow.com/questions/18544103/print-flowdocument-scroll-viewer-on-multiple-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!