I have a FlowDocument that varies in height due to an ItemsControl in a BlockUIContainer. In some cases, the ItemsControl extends beyond the page height. Is there a way to scale the FlowDocument to fit a page (8.5″ X 11″) right before printing if needed?
As of right now, the FlowDocument is named ‘doc’ and the method for printing I am using is:
private void Print_Click(object sender, RoutedEventArgs e)
{
PrintDialog pd = new PrintDialog();
doc.PageHeight = pd.PrintableAreaHeight;
doc.PageWidth = pd.PrintableAreaWidth;
doc.ColumnGap = 0;
doc.ColumnWidth = pd.PrintableAreaWidth;
IDocumentPaginatorSource dps = doc;
pd.PrintDocument(dps.DocumentPaginator, "Sheet");
}
I know it’s a bit late, but here is the solution I came up with.
First, we create a wrapper that will generate the document pages for us. Each page will have a scale transformation applied to it before returning it.
Using it is fairly simple:
If you’re interested, here is how we determined the scale. In our case, the document was extended past the page width, but it can easily be modified to accommodate the page height.