2

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.

Carl Binalla
  • 5,393
  • 5
  • 27
  • 46
user2088807
  • 1,378
  • 2
  • 25
  • 47

1 Answers1

4

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.

CJBS
  • 15,147
  • 6
  • 86
  • 135
Nitin
  • 18,344
  • 2
  • 36
  • 53
  • Thank you that looks much better ! However I've a few issues : - It prints my stuff in 2 columns - A blockUIContainer cannot take more than one page ? It has printed a small part on the right column, It would be better if this small part was on another page - When it has done printing my application gives me a "null pointer exception" on the showdialog of my window. How can I avoid that ? Thanks – user2088807 Sep 01 '13 at 15:36
  • (column thing fixed, i've just the null exception. Maybe I should copy my FlowDocumentScrollViewer into a new objet ? But How can I do that ? – user2088807 Sep 01 '13 at 15:50
  • glad it worked for you... where are you getting the null exception..can you share some code? – Nitin Sep 01 '13 at 16:05
  • I removed all the lines about document's stretching and it seems to work, i'll post the exception if it happens again. Thanks ! – user2088807 Sep 01 '13 at 21:07