Using Silverlight 4, can I print the grid in landscape mode and show all the contents? We create the “page” as a Grid and set the transposed height / width from the PrintDocument PrintableArea. Then we use CompositeTransform to set Rotation and TranslateX. Essentially, this is very similar to the solution found here .
This allows the content to rotate properly, and everything seems to stretch the width (well, height in this case) of the page, but the bottom is cropped. This is almost similar to content displayed at the normal page width (usually 8.5 "), although it was displayed at the height of the page (11 inches tall). Thus, 2.5 inches of content appears as empty content at the bottom of the page .
Note. We do not pull the existing visual element from the user interface to place it in the "page". We define DataTemplates and pass the VM to the DataContext. All content is tied and displayed correctly, as far as possible, but rendering in a printed document is what happens wrong.
Is there something we are missing? We hope to avoid having to display the bitmap of the page first, but if that's what we should do ...
UPDATE: Based on further investigation (and talking with the guy on the team that started working on the reports), the code is very heavily based on Print on the client side of Pete Brown . We expanded it a little to group and improve the report functions, but in general, layout processing is the same engine.
If you look at the Pete Brown code, the current difference we are using is the following in the GetNewPage method:
... this.CurrentPageNumber++; Grid pagePanel = new Grid(); LayoutTransformer layoutTransformer = new LayoutTransformer { Content = pagePanel, Tag = this.CurrentPageNumber }; if (printableArea.Height > printableArea.Width) { // printable area is in Portrait mode. layoutTransformer.Height = printableArea.Width; layoutTransformer.Width = printableArea.Height; var transform = new CompositeTransform { Rotation = 90, TranslateX = printableArea.Width, ScaleX = 1, ScaleY = 1 }; layoutTransformer.LayoutTransform = transform; layoutTransformer.ApplyLayoutTransform(); layoutTransformer.RenderTransform = transform; } else { // printable area is in Landscape mode layoutTransformer.Height = printableArea.Height; layoutTransformer.Width = printableArea.Width; } Size pageSize = new Size(layoutTransformer.Width, layoutTransformer.Height); layoutTransformer.HorizontalAlignment = HorizontalAlignment.Stretch; layoutTransformer.VerticalAlignment = VerticalAlignment.Stretch; RowDefinition headerRow = new RowDefinition { Height = GridLength.Auto }; RowDefinition itemsRow = new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }; RowDefinition footerRow = new RowDefinition { Height = GridLength.Auto }; pagePanel.RowDefinitions.Add(headerRow); pagePanel.RowDefinitions.Add(itemsRow); pagePanel.RowDefinitions.Add(footerRow); ...
This works great when automatically rotating content, but the width is still chopped off, as if it makes the page width more like a portrait. Despite the fact that I changed all the dimensions that need to be interchanged. It seems that calls to InvalidateMeasure() and InvalidateArrangement() have no meaning to change the output. The strange thing is that when I change ScaleX to something larger than 1, it stretches the cropped content to fill most of the page. Thus, almost like the parent container is truncated before the conversion, even though the code says otherwise. It basically looks like the clipping that Shawn Wildermuth's blog posted about . So I'm still looking for ideas / solutions ...