Hi
In my application, I have ten stack panel. Each stack panel has formatted text in it. Main job is to print stack panel content to a4 page. If there ten stack panel then the printed document should have ten pages and each page should exactly same respective stack panel content in the application.
What I have achieved so far?
I could able to save any one stack panel as frameworkelement and serialised it to xps folder and then I could able to print it.
My Code:
Note: 'spanel0' is the name of one of the stack panel in the application.private void PrintDocument() { PrintDialog pd = new PrintDialog(); FrameworkElement fe = (spanel0 as FrameworkElement); fe.Measure(new Size(Int32.MaxValue, Int32.MaxValue)); Size visualSize = fe.DesiredSize; 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; 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(spanel0); paginator = ((IDocumentPaginatorSource) xpsDoc.GetFixedDocumentSequence()).DocumentPaginator; paginator.PageSize = visualSize; } PackageStore.RemovePackage(uri);
pd.printDocument(paginator,"printing.."); } }
Where did I stuck?
The above code is helping to print any one stack panel but I want to print all the stack panel to single document. I struggled a lot but could not able to find out a solution. Please guide me. Thanks.
Note: Rest of stack panel names are spanel1, spanel2, spanel3 and so on.