Issue with Printing FlexGrid

Posted by: dducharme on 4 November 2019, 3:20 am EST

  • 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.

  • Posted 4 November 2019, 4:46 pm EST

    Hello,

    I am not able to replicate the issue with the following code at my end:

    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);
                      var paginator = new FlexPaginator(_flex, scaleMode, sz, new Thickness(margin), 100);
    
    
                      pd.PrintDocument(paginator, "Test");
                 }
    
    

    Could you please try with the latest build. You can install the same from the following link:

    http://prerelease.componentone.com/dotnet40/c1wpflibrary/2019-t2/C1WPFBasicLibrary.4_4.0.20192.658.zip

    If issue still exists, could you please share your stripped-down application so that I can replicate the issue at my end and assist you accordingly.

    Thanks,

    Mohit

  • Posted 5 November 2019, 4:43 am EST

    Hi Mohit,

    Thanks for taking a look into this.

    I have updated to the latest WPF and I am still having the same issue. I have attached a stripped down version of my application with enough data to show the problem: SampleApplication.zip.

    When you run the application, to show the problem just hit print in the upper right of the application and I am seeing this issue regardless of if I print to a pdf or to an actual printer. Simply scroll to the last page and you will see that the grid is offset from the rest of them. and cutoff. And just to reiterate this is occurring if I print 1 page or 20, in every case, the last page is offset in the same manner.

  • Posted 5 November 2019, 3:56 pm EST

    Hello,

    I am very sorry to mention that I still not able to replicate the issue at my end. I have opened your sample in visual studio 2019(16.3) and run the sample without any change. Please refer to the attached PDF file which shows the result at my end. I have also checked with the physical printer and still not able to replicate the issue.

    I think it is an environment-specific issue. Could you please share the detail so that I will check on the same environment if possible.

    My environment:

    Visual Studio 2019(16.3)

    Win10 1903 x64bit

    Thanks,

  • Posted 5 November 2019, 3:59 pm EST

  • Posted 15 November 2019, 3:44 am EST

    Sorry about the delay, juggling a few different projects right now. Here is my environment:

    Microsoft Visual Studio Community v16.3.1

    Win10 1903 Pro x64

    As a quick test I ran the application on another computer and it appears that it is PC specific as it did print without issue. That said do we have any idea what could be causing it on my development PC so that I can try to resolve this? Worst case it appears it won’t be a problem for my users and I will just need to use a separate machine to produce demo output.

  • Posted 17 November 2019, 5:40 pm EST

    Hello Daniel,

    We never face this problem and no such issue is reported by the customer as of now. It is related to some machine settings. We don’t have any idea about the root cause of this.

    Could you please share the locale of your system, so that we can check with the same locale.

    Also, could you please check with MS grid. Is issue also reproducible with the MS grid?

    Thanks,

    Mohit

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels