Hi,
I am trying to print a framework element. I am using the following code
"MainContentRegion" in the following code is a content control that holds an infragistics grid.
FrameworkElement fe = (MainContentRegion.Content as FrameworkElement); System.Printing.PrintCapabilities capabilities = printDlg.PrintQueue.GetPrintCapabilities(printDlg.PrintTicket); double scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / fe.DesiredSize.Width, capabilities.PageImageableArea.ExtentHeight / fe.DesiredSize.Height); fe.LayoutTransform = new ScaleTransform(scale, scale); fe.Measure(new Size(Int32.MaxValue, Int32.MaxValue)); Size visualSize = fe.DesiredSize; if (fe.DesiredSize.Width >= fe.ActualWidth || fe.DesiredSize.Height >= fe.ActualHeight) fe.Arrange(new Rect(new Point(0, 0), visualSize)); MemoryStream stream = new MemoryStream(); string pack = "pack://temp.xps"; Uri uri = new Uri(pack); DocumentPaginator paginator; XpsDocument xpsDoc; DocumentViewer doc = new DocumentViewer(); Window _window = new Window(); using (Package container = Package.Open(stream, FileMode.Create)) { PackageStore.AddPackage(uri, container); using (xpsDoc = new XpsDocument(container, CompressionOption.Fast, pack)) { XpsSerializationManager rsm = new XpsSerializationManager(new XpsPackagingPolicy(xpsDoc), false); rsm.SaveAsXaml(Grid.Content);
paginator = ((IDocumentPaginatorSource) xpsDoc.GetFixedDocumentSequence()).DocumentPaginator;
paginator.PageSize = visualSize;
paginator = new VisualDocumentPaginator(paginator, new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight), new Size(10, 10));
doc.Document = xpsDoc.GetFixedDocumentSequence();
_window.Content = doc; _window.ShowDialog();
printDlg.PrintDocument(paginator, "A Flow Document"); }
PackageStore.RemovePackage(uri); }
I have to use measure and arrange to get all the data from the grid which is not visible( grid contains a scroll bar). But when i use measure and arrange on the frame work element above Xamdatagrid responds correctly where as xamdatachart doesnot fit into the page(A4) and more over it overlaps with xamdatagrid.
Regards,
Sasikumar
Hello Sasikumar,
Thank you for your post. I have been looking into it and I can suggest you see this blog:
http://es.infragistics.com/community/blogs/petar_monov/archive/2012/03/14/controls-to-images.aspx
where Peter explained how to export controls to Excel, .png, .jpg. Please let me know if this helps you or you need further assistance on this matter.
Looking forward for your reply.
Hi Stephan,
I think the topic that you have shared refers to saving Xamdatachart as an image. And moreover it uses infragistics reporting framework. I am not using either of them. As the sample code suggests i am using a flow document approach, and when the view(Framework Element/Content Control) contains both Xamdatachart(scatter Line series) and Xamdatagrid.On print operation (code shared in 1st post) the chart control either overlaps with the grid or goes out of the page. I have tried skipping measure and arrange operation for a view with both, in that case the contents of the grid are not fully displayed.
Could you please send an isolated sample project, where the issue is reproduced, so I can investigate it further for you.
Hi Stefan,
Please find the sample in attachment below. You can click on print and check the result in document viewer.
Happy Thanks Giving.
I have been looking into your sample and I modified it, so now it works as you want. Basically I added Dispatcher in order to delay the printing, so the XamDataChart could be arranged and measured correctly. Please let me know if this helps you or you need further assistance on this matter.
Thanks for the updated sample. I have added a xamdatagrid to the sample (“XamdatachartExample”). I am trying to scale the visual to a A4 page. The xamdatagrid contents are not fully displayed in the print preview. But when you use the Xamdatagrid alone provided in example(“XamDataGridPrintPreview”). Print preview displays the entire content of the grid. I am unable to figure out the difference, only possible explaination is that when a xamdatachart is used the desired size of the framework element is not accurate.
SasiKumar
Hello SasiKumar,
I have been looking into the sample you have attached and I can say that the XamDataChart and XamDataGrid need different amount of time for re-rendering after the Arrange and Measure methods are executed. This is why when you add a Dispatcher the chart renders correctly and the grid not. I can suggest you see this forum thread:
http://stackoverflow.com/questions/17141637/how-to-add-multiple-fpages-to-fixed-document-in-xps
where it is explained how to add multiple pages. You can use this approach in order to use Dispatcher for the Chart and add it to the document and after that you can add the grid without using a dispatcher. Also if you have difficulties with adding different pages/sections to the XpsDocument I can suggest you ask in the MS forums, where you can get an answer from an MS expert.