c# - wpf print multiple pages of xaml controls -


I am trying to implement a WPF print function. This is working by the time the user fits on one page and does not want to print. My application enables users to create XML in runtime, now I want to enable them to print XML controls.

I have checked the total height of all XML controls, delivered by PageHeight and reduced that number, so I know how many pages I have to print.

Next I am creating a list of Framework Elements for each page (see the logic below) and store each list (stands for each page) in an array.

At the end I want to make a preview that contains every page and enables the user to print all the pages. To do this, I have to put the pages together in a document, but I do not know how to please see my code:

  package package = package. Open ("test.xps", FileMode.Create); // Open new XPS document based on package XpsDocument document = new XpsDocument (package); // XpsDocumentWriter author = XpsDocument.CreateXpsDocumentWriter (doc) Create an example of XpsDocumentWriter; // Write the canvas (in the form of the view) double height = element in the document Actualheart; Double width = element.ActualWidth; System.Windows.Controls.PrintDialog printDlg = New System.windows. Control. PrintDialog (); Size page size = new size (printDlg.PrintableAreaWidth, printDlg.PrintableAreaHeight); Int pagecount = (int) math Calling (Height / Pauzis High.); If (page size. Height> height) {var grid = as element grid; Var children = grid children; List & lt; Framework Element & gt; [] Pages = new list & lt; Framework Element & gt; [Page number -1]; Int i = 0; Double currenth = 0; Forward (children in Framework Element C) {current right + = C. Rider size height; If (current highte & lieutenant; pageisan.height) {page [i] = new list & lt; Framework Element & gt; (); Pages [i] .Add (c); } And {i ++; CurrentHeight = 0; Pages [i] = new list & lt; Framework Element & gt; (); Pages [i] .Add (c); }} For (int j = 0; j & lt; page count; j ++) {var collator = writer.CreateVisualsCollator (); Collator.BeginBatchWrite (); Forward ([ja] in framework element c pages {collator.Write (c); } Collator.EndBatchWrite (); }} doctor. Stop it (); Package.Close (); String file name = @ "C: \ user \ rzimmermann \ document \ Visual Studio 2012 \ Projects \ MvvmLightPrintFunction \ MvvmLightPrintFunction \ bin \ Debug \ test.xps"; Document viewer = new document view (); Doctor = new XpsDocument (file name, FileAccess.Read); the audience. Document = doctor Getfix Document Sequence (); Window Show window = new window (); ShowWindow.Width = 400; ShowWindow.Height = 300; ShowWindow.Content = Viewer; ShowWindow.Show ();   

Thanks a lot.

@kenny You need to use fixed pages right for a great tutorial delivery: < / p>

As far as adding a page to a document you can:

  doc.Pages.Add (page 1 content); Doc.Pages.Add (page2Content);   

// ect.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -