Posted 4 November 2019, 3:20 am EST
I have used the sample code from the PrintingWPF example code and mostly have printing working correctly. When I print a multi page grid, the first pages looks great, but the last page has the grid offset to the right and is cutting off the last column. This is the same issue I get if I print a grid that is only 1 page long as it messes up that only page.
When I return back to the application it has also messed up the columns of the FlexGrid and they no longer fit the screen or line up with the column headers.
Here is the grid I am trying to print:
<C1:C1FlexGrid Name="lvSCResults"
Grid.Column="1"
Grid.ColumnSpan="5"
Grid.Row="2"
Grid.RowSpan="10"
Visibility="Hidden"
FontFamily="Tahoma"
FontSize="14"
AutoGenerateColumns="False"
HeadersVisibility="Column">
<C1:C1FlexGrid.Columns>
<C1:Column Header="GROUPER" Binding="{Binding grouper}" Width="*"/>
<C1:Column Header="Count" Binding="{Binding Count}" Format="n0" Width="50" HorizontalAlignment="Right" HeaderHorizontalAlignment="Right"/>
<C1:Column Header="Median Sale Price" Binding="{Binding MedianSalePrice}" Format="c0" Width="*" HorizontalAlignment="Right" HeaderHorizontalAlignment="Right"/>
<C1:Column Header="Previous Median" Binding="{Binding PreviousMedian}" Format="n2" Width="110" HorizontalAlignment="Right" HeaderHorizontalAlignment="Right"/>
<C1:Column Header="Current Median" Binding="{Binding CurrentMedian}" Format="n2" Width="110" HorizontalAlignment="Right" HeaderHorizontalAlignment="Right"/>
<C1:Column Header="Previous COD" Binding="{Binding PreviousCOD}" Format="n3" Width="110" HorizontalAlignment="Right" HeaderHorizontalAlignment="Right"/>
<C1:Column Header="Current COD" Binding="{Binding CurrentCOD}" Format="n3" Width="110" HorizontalAlignment="Right" HeaderHorizontalAlignment="Right"/>
</C1:C1FlexGrid.Columns>
</C1:C1FlexGrid>
Here Test.zip is a zip of the pdf that is printing out so you can see the issue.
Finally here is my print button function that I use to send to the printer:
private void btnPrint_Click(object sender, RoutedEventArgs e)
{
var margin = 96.0;
var scaleMode = ScaleMode.PageWidth;
var pd = new PrintDialog();
pd.PrintQueue = System.Printing.LocalPrintServer.GetDefaultPrintQueue();
pd.PrintTicket = pd.PrintQueue.DefaultPrintTicket;
pd.PrintTicket.PageOrientation = System.Printing.PageOrientation.Landscape;
if(pd.ShowDialog().Value)
{
var sz = new Size(pd.PrintableAreaWidth, pd.PrintableAreaHeight);
Model.FlexPaginator paginator = new Model.FlexPaginator(lvSCResults, scaleMode, sz, new Thickness(margin), 100);
if (lvSCResults.Visibility == Visibility.Visible)
paginator = new Model.FlexPaginator(lvSCResults, scaleMode, sz, new Thickness(margin), 100);
else if (lvTCResults.Visibility == Visibility.Visible)
paginator = new Model.FlexPaginator(lvTCResults, scaleMode, sz, new Thickness(margin), 100);
pd.PrintDocument(paginator, "Test");
}
}
FlexPaginator and PageTemplate were simply taken out of the example for now until I get it working and can begin to change it to match our plans.