Hi,
I have a grid, that I want to print, but is has to scale to fit the paper. I tried the printing example at http://www.telerik.com/community/code-library/wpf/gridview/radgridview-print-and-print-preview.aspx, but as my grid is too wide, it prints it on two pages.
So how can I scale the grid to the paper's width, so that the grid is not spread over multiple pages?
Thanks,
L
I have a grid, that I want to print, but is has to scale to fit the paper. I tried the printing example at http://www.telerik.com/community/code-library/wpf/gridview/radgridview-print-and-print-preview.aspx, but as my grid is too wide, it prints it on two pages.
So how can I scale the grid to the paper's width, so that the grid is not spread over multiple pages?
Thanks,
L
4 Answers, 1 is accepted
0
Ludwig
Top achievements
Rank 1
answered on 29 Apr 2011, 07:10 PM
no solution for this?
0
Hi,
You can modify this to fit your needs. Kind regards,
Vlad
the Telerik team
You can find the full code of the printing in the demo itself since this is not a built-in feature. For example in PrintExtensions.cs ToFixedDocument() extension method the grid is measured with infinity:
...
element.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
element.Arrange(new Rect(new Point(0, 0), element.DesiredSize));
...
You can modify this to fit your needs. Kind regards,
Vlad
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items
0
Ludwig
Top achievements
Rank 1
answered on 03 May 2011, 03:41 PM
ok, copy-pasted the code from http://www.telerik.com/community/code-library/wpf/gridview/radgridview-print-and-print-preview.aspx and changed the ToFixedDocument as follows:
But at the line 'element.Measure(sz);' it crashed with the error: 'Layout measurement override of element 'Telerik.Windows.Controls.RadGridView' should not return NaN values as its DesiredSize.'
Do you know what is going on here?
Edit: I narrowed it down to the fact that ActualWidth of the grid seems to be 0??
static FixedDocument ToFixedDocument(FrameworkElement element, PrintDialog dialog, PageOrientation orientation = PageOrientation.Portrait)...
{
// need to do this, otherwise 'Specified element is already the logical child of another element. Disconnect it first.' occurs
foreach (var col in (element as RadGridView).Columns)
{
col.Header = null;
}
dialog.PrintTicket.PageOrientation = orientation;
PrintCapabilities capabilities = dialog.PrintQueue.GetPrintCapabilities(dialog.PrintTicket);
Size pageSize = new Size(dialog.PrintableAreaWidth, dialog.PrintableAreaHeight);
Size extentSize = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);
FixedDocument fixedDocument = new FixedDocument();
// Code to scale the grid to fit page width
// Get scale of the print wrt to screen of WPF visual
double scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / element.ActualWidth, capabilities.PageImageableArea.ExtentHeight / element.ActualHeight);
// Transform the Visual to scale
element.LayoutTransform = new ScaleTransform(scale, scale);
// Get the size of the printer page
Size sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);
// Update the layout of the visual to the printer page size.
element.Measure(sz);
element.Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));
But at the line 'element.Measure(sz);' it crashed with the error: 'Layout measurement override of element 'Telerik.Windows.Controls.RadGridView' should not return NaN values as its DesiredSize.'
Do you know what is going on here?
Edit: I narrowed it down to the fact that ActualWidth of the grid seems to be 0??
0
Vic
Top achievements
Rank 1
Iron
answered on 22 Jul 2012, 10:51 PM
Hello,
Did you find a successful way to scale the grid to fit the page width?
Did you find a successful way to scale the grid to fit the page width?