Print flowdocument scroll viewer on multiple pages

2019-07-12 09:00发布

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条回答
\"骚年 ilove
2楼-- · 2019-07-12 09:28

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.

查看更多
登录 后发表回答