views:

379

answers:

1

I'm trying to get a FlowDocument to print. After spending much of the day trying multiple pages I failed and opted for something simpler, but I'm now at a loss to explain when text isn't output to the page. This has to be something I've got snowblind to I think. There are two tables below, placing a converter on both shows that the values are being populated through the DataContext of the 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'm sort of at my wits end with this, I can't see the problem. I'd really appreciate it if anyone could shed some light.

A: 

This isn't really an answer per se, but are you in a position to use the FlowDocumentReader? It has the Print stuff already pre-wired on Ctrl-P (and exposes a "Print" method)...that said, you might try this: Printing a Windows Foundation Presentation FlowDocument

JerKimball
I've used pretty much the same code somewhere else in another app though. I thought it may be something really obvious but perhaps not. :(
Echilon