c# - Convert WPF (XAML) Control to XPS Document -


Can I take an existing WPF (XAM) control, convert it to database and convert it to an XPS document Which can be displayed and printed using WPF XPS Document Viewer? if so, how? If not, how should I do 'Reporting' in WPF using XPS / PDF / etc?

Actually, I want to take control of an existing WPF, it will be used to get useful data and then it will be printable and ideally for the end-user in the document building and as long as the user Especially the document will not save, will not hit on the disk. Is this possible?

Really roaming with a pile of various samples, all of which are incredibly complex and document writers Use of Container, Print Cues and Print Tickets, I got an article about Eric Sink - Simplified code is only 10 lines long

  Public Zero CreateMyWPFControlReport (MyWPFControlDataSource Useful Data) {/ Setup / Print to WPF control MyWPFControl controlToPrint; ControlToPrint = New MyWPFControl (); ControlToPrint.DataContext = Useful Data; Fixed document fixedDoc = new fixed document (); PageContent Page Resources = New PageContent (); Fixed page fixed page = new fixed page (); // Create the first page of the fixed page. Page. Children (controlToPrint); ((System.Windows.Markup.IddChild) pageContent) .AddChild (fixedPage); FixedDoc.Pages.Add (pageContent); // Create any other necessary page here // View the document document Viewer1.Document = fixedDoc; }  

My sample is quite simple, it does not include Page Sizing and Orientation, which covers issues of a different set which does not expect work. Neither does it involve any functionality because MS has forgotten to include a Save button with the document viewer.

The feature is relatively simple to save (and is also from Eric Sync article)

  Public Zero SaveCurrentDocument () {// Configure File File Save dialog box Microsoft.Win32. SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog (); Dlg.FileName = "MyReport"; // default file name dlg.DefaultExt = ".xps"; // default file extension dlg.philter = "xps document (.xps) | * .xps"; // Extract files by extension // save the file dialog box faucet & lt; Bool & gt; Results = dlg.ShowDialog (); // Process file dialog box Save result if (result == true) {// save document string filename = dlg.FileName; Fixed document document = Viewer1.Document; XpsDocument xpsd = New XpsDocument (File Name, FileAccess.ReadWrite); System.Windows.Xps.XpsDocumentWriter xw = XpsDocument.CreateXpsDocumentWriter (xpsd); Xw.Write (doc); Xpsd.Close (); }}  

So the answer is yes, you can take an existing WPF (XAM) control, you can create a database and convert it to an XPS document - and not all that difficult is.


Comments