WPF: Printing a FlowDocument

I am trying to get a FlowDocument to print. After spending most of the day trying several pages, I failed and chose something simpler, but now I find it difficult to explain when the text does not appear on the page. I think it should be something that I have snow. Below are two tables, placing the converter on both shows that the values ​​are populated through the DataContext FlowDocument.

                                                                                                                                                                                                                                                                                              

<Table>
    <Table.Columns>
        <TableColumn Width="Auto"/>
        <TableColumn Width="34"/>
        <TableColumn Width="Auto"/>
    </Table.Columns>
    <TableRowGroup>
        <TableRow>
            <TableCell>
                <Paragraph>
                    <Image Source="{Binding Icon,Converter={StaticResource IconConverter},ConverterParameter=32}" Width="32" Height="32"/>
                </Paragraph>
            </TableCell>
            <TableCell>
                <Paragraph>
                    <TextBlock Text="{Binding Name,Converter={StaticResource dbg}}" TextWrapping="Wrap" TextTrimming="CharacterEllipsis" VerticalAlignment="Center" FontSize="18" Foreground="Black" />
                </Paragraph>
            </TableCell>
            <TableCell>
                <Paragraph>
                    <TextBlock Text="Static text works fine" TextAlignment="Right"  />
                    <TextBlock Text="Static text works here too fine" TextAlignment="Right"  />
                </Paragraph>
            </TableCell>
        </TableRow>
    </TableRowGroup>
</Table>
<BlockUIContainer>
    <Line Stretch="Fill" Stroke="DarkBlue" X2="1"/>
</BlockUIContainer>

The document is printed using:

PrintDialog dlg = new PrintDialog();
if(dlg.ShowDialog() == true) {
  int margin = 5;
  Size pageSize = new Size(dlg.PrintableAreaWidth - margin * 2, dlg.PrintableAreaHeight - margin * 2);
  FlowDocument document = WPFUtils.LoadFlowDocument(System.IO.Path.Combine(Utils.GetApplicationPath(), "AccountPrintView.xaml"), account); // loads the document from a XAML file
  IDocumentPaginatorSource paginator = document as IDocumentPaginatorSource;
  paginator.DocumentPaginator.PageSize = pageSize;
  dlg.PrintDocument(paginator.DocumentPaginator, "Print output");
}

I sort of figure this out, I don't see a problem. I would really appreciate it if anyone could shed some light.

+3
source share
1 answer

, FlowDocumentReader? , Ctrl-P ( "" )... : Windows Flow Presentation FlowDocument

+1

Source: https://habr.com/ru/post/1726915/


All Articles