added SSCLI 1.0
[windows-sources.git] / sdk / samples / WPFSamples / XpsPrint / csharp / xpsprinthelper.cs
blobf19c7dd73c57f5de7e255c59e6c533790bc76a04
1 // XpsPrint SDK Sample - XpsPrintHelper.cs
2 // Copyright (c) Microsoft Corporation. All rights reserved.
4 using System;
5 using System.Collections.Generic;
6 using System.IO;
7 using System.IO.Packaging;
8 using System.Printing;
9 using System.Windows.Controls;
10 using System.Windows.Documents;
11 using System.Windows.Documents.Serialization;
12 using System.Windows.Media;
13 using System.Windows.Xps;
14 using System.Windows.Xps.Packaging;
15 using System.Windows.Xps.Serialization;
16 using SDKSample;
19 namespace SDKSampleHelper
21 // ----------------------- class AsyncSaveEventArgs -----------------------
22 /// <summary>
23 /// Event arguments class for asynchronous print events.</summary>
24 public class AsyncPrintEventArgs : EventArgs
26 private String _status;
27 private bool _completed;
29 public String Status
31 get { return _status; }
34 public bool Completed
36 get { return _completed; }
39 public AsyncPrintEventArgs(String status, bool completed)
41 _completed = completed;
42 _status = status;
44 }// end:class AsyncSaveEventArgs
47 // ------------------------- class XpsPrintHelper -------------------------
48 public class XpsPrintHelper
50 internal delegate void AsyncPrintChangeHandler(
51 object printHelper, AsyncPrintEventArgs asycnInformation);
53 internal event AsyncPrintChangeHandler OnAsyncPrintChange;
55 #region Constructors
56 public XpsPrintHelper(String contentPath)
58 _wpfContent = new WPFContent(contentPath);
59 _contentDir = contentPath;
61 #endregion Constructors
63 #region Print Interface
64 // -------------------------- GetPrintDialog --------------------------
65 /// <summary>
66 /// Displays a printer dialog that allows the
67 /// user to chose the printer to output to.</summary>
68 /// <returns>
69 /// The print dialog with the results of the user selection;
70 /// or NULL if the user clicks "Cancel" to the dialog.</returns>
71 public PrintDialog GetPrintDialog()
73 PrintDialog printDialog = null;
75 // Create a Print dialog.
76 PrintDialog dlg = new PrintDialog();
78 // Show the printer dialog. If the return is "true",
79 // the user made a valid selection and clicked "Ok".
80 if (dlg.ShowDialog() == true)
81 printDialog = dlg; // return the dialog the user selections.
83 return printDialog;
84 }// end:GetPrintDialog()
87 // ------------------------- PrintSingleVisual ------------------------
88 /// <summary>
89 /// Prints a single visual element.</summary>
90 /// <param name="pq">
91 /// The print queue to print to.</param>
92 /// <param name="async">
93 /// true to print asynchronously; false to print synchronously.</param>
94 public void PrintSingleVisual(PrintQueue pq, bool async)
96 // Create a single visual element.
97 Canvas v = _wpfContent.CreateFirstVisual(true);
99 // Create a document writer to print to.
100 XpsDocumentWriter xdwPrint = GetPrintXpsDocumentWriter(pq);
102 // Transform the visual to fit the printer.
103 Visual transformedVisual = PerformTransform(v, pq);
105 // Print either asynchronously or synchronously.
106 if (async)
107 PrintVisualAsync(xdwPrint, transformedVisual);
108 else
109 PrintVisual(xdwPrint, transformedVisual);
110 }// end:PrintSingleVisual()
113 // ----------------------- PrintMultipleVisuals -----------------------
114 /// <summary>
115 /// Prints a collection of multiple visual elements.</summary>
116 /// <param name="pq">
117 /// The print queue to print to.</param>
118 /// <param name="async">
119 /// true to print asynchronously; false to print synchronously.</param>
120 public void PrintMultipleVisuals(PrintQueue pq, bool async)
122 // Create a collection of visuals
123 List<Visual> vc = new List<Visual>();
125 //Create Visuals
126 Visual v;
127 v = _wpfContent.CreateFirstVisual(true);
128 Visual transformedVisual = PerformTransform(v, pq);
129 vc.Add(transformedVisual);
131 v = _wpfContent.CreateSecondVisual(true);
132 transformedVisual = PerformTransform(v, pq);
133 vc.Add(transformedVisual);
135 v = _wpfContent.CreateThirdVisual(true);
136 transformedVisual = PerformTransform(v, pq);
137 vc.Add(transformedVisual);
139 // Retrieve Print Ticket from PrintQueue and
140 // change the orientation to Landscape.
141 PrintTicket pt = pq.UserPrintTicket;
142 pt.PageOrientation = PageOrientation.Landscape;
144 // Create an printing XPSDocumentWriter
145 XpsDocumentWriter xdwPrint = GetPrintXpsDocumentWriter(pq);
147 // Print either asynchronously or synchronously.
148 if (async)
149 PrintVisualsAsync(xdwPrint, vc);
150 else
151 // Print content using helper function
152 PrintVisuals(xdwPrint, vc);
153 }// end:PrintMultipleVisuals()
156 // ------------------ PrintSingleFlowContentDocument ------------------
157 /// <summary>
158 /// Prints the content of a single flow document.</summary>
159 /// <param name="pq">
160 /// The print queue to print to.</param>
161 /// <param name="async">
162 /// true to print asynchronously; false to print synchronously.</param>
163 public void PrintSingleFlowContentDocument(PrintQueue pq, bool async)
165 // Create a paginated flow document.
166 DocumentPaginator idp =
167 _wpfContent.CreateFlowDocument().DocumentPaginator;
169 // Create a document writer to print to.
170 XpsDocumentWriter xdwPrint = GetPrintXpsDocumentWriter(pq);
172 // Scale the paginated flow document to a visual for printing.
173 Visual visual = _wpfContent.AdjustFlowDocumentToPage(idp, pq);
175 // Print either asynchronously or synchronously.
176 if (async)
177 PrintVisual(xdwPrint, visual);
178 else
179 PrintVisualAsync(xdwPrint, visual);
180 }// end:PrintSingleFlowContentDocument()
183 // ------------------ PrintSingleFixedContentDocument -----------------
184 /// <summary>
185 /// Prints the content of a single fixed document.</summary>
186 /// <param name="pq">
187 /// The print queue to print to.</param>
188 /// <param name="async">
189 /// true to print asynchronously; false to print synchronously.</param>
190 public void PrintSingleFixedContentDocument(PrintQueue pq, bool async)
192 // Create a FixedDocument with associated PrintTicket.
193 FixedDocument fd = _wpfContent.CreateFixedDocumentWithPages(pq);
195 // Create a document writer to print to.
196 XpsDocumentWriter xdwPrint = GetPrintXpsDocumentWriter(pq);
198 // Print either asynchronously or synchronously.
199 if (async)
200 PrintSingleFixedContentDocumentAsync(xdwPrint, fd);
201 else
202 PrintSingleFixedContentDocument(xdwPrint, fd);
203 }// end:PrintSingleFixedContentDocument()
207 // ---------------- PrintMultipleFixedContentDocuments ----------------
208 /// <summary>
209 /// Prints the content of a multiple fixed document sequence.</summary>
210 /// <param name="pq">
211 /// The print queue to print to.</param>
212 /// <param name="async">
213 /// true to print asynchronously; false to print synchronously.</param>
214 public void PrintMultipleFixedContentDocuments(PrintQueue pq, bool async)
216 // Create a multiple document FixedDocumentSequence.
217 FixedDocumentSequence fds =
218 _wpfContent.LoadFixedDocumentSequenceFromDocument();
220 // Create a document writer to print to.
221 XpsDocumentWriter xdwPrint = GetPrintXpsDocumentWriter(pq);
223 // Set the event handler for creating print tickets for
224 // each document within the fixed document sequence.
225 xdwPrint.WritingPrintTicketRequired +=
226 new WritingPrintTicketRequiredEventHandler(
227 MultipleFixedContentDocuments_WritingPrintTicketRequired);
228 _firstDocumentPrintTicket = 0;
230 // Print either asynchronously or synchronously.
231 if (async)
232 PrintMultipleFixedContentDocumentsAsync(xdwPrint, fds);
233 else
234 PrintMultipleFixedContentDocuments(xdwPrint, fds);
235 }// end:PrintMultipleFixedContentDocuments()
239 // -------------------- PrintDocumentViewerContent --------------------
240 /// <summary>
241 /// Prints the content displayed in a
242 /// given DocumentViewer control.</summary>
243 /// <param name="dv">
244 /// The DocumentViewer content to print.</param>
245 /// <param name="pq">
246 /// The print queue to print to.</param>
247 /// <param name="async">
248 /// true to print asynchronously; false to print synchronously.</param>
249 public void PrintDocumentViewerContent(
250 DocumentViewer dv, PrintQueue pq, bool async)
252 // Create a document writer for printing
253 XpsDocumentWriter xdwPrint = GetPrintXpsDocumentWriter(pq);
255 // Scale the DocumentViewer content for the printer.
256 DocumentPaginator idp = dv.Document.DocumentPaginator;
257 Visual visual = _wpfContent.AdjustFlowDocumentToPage(idp, pq);
259 // Print either asynchronously or synchronously.
260 if (async)
261 PrintVisual(xdwPrint, visual);
262 else
263 PrintVisualAsync(xdwPrint, visual);
264 }// end:PrintDocumentViewerContent()
266 #endregion // Print Interface
269 #region Synchronous Print Methods
271 // ------------------------- PrintVisualAsync -------------------------
272 /// <summary>
273 /// Synchronously prints a given visual
274 /// to a specified document writer.</summary>
275 /// <param name="xpsdw">
276 /// The document writer to output to.</param>
277 /// <param name="v">
278 /// The visual to print.</param>
279 private void PrintVisual(XpsDocumentWriter xpsdw, Visual v)
281 xpsdw.Write(v); // Write visual to single page
285 // --------------------------- PrintVisuals ---------------------------
286 /// <summary>
287 /// Synchronously prints of a given list of
288 /// visuals to a specified document writer.</summary>
289 /// <param name="xpsdw">
290 /// The document writer to output to.</param>
291 /// <param name="vc">
292 /// The list of visuals to print.</param>
293 private void PrintVisuals(XpsDocumentWriter xpsdw, List<Visual> vc)
295 // Setup for writing multiple visuals
296 VisualsToXpsDocument vToXpsD =
297 (VisualsToXpsDocument)xpsdw.CreateVisualsCollator();
299 // Iterate through all visuals in the collection
300 foreach (Visual v in vc)
302 vToXpsD.Write(v); //Write each visual to single page
305 // End writing multiple visuals
306 vToXpsD.EndBatchWrite();
310 // ------------------ PrintSingleFlowContentDocument ------------------
311 /// <summary>
312 /// Synchronously prints a given paginated flow
313 /// document to a specified document writer.</summary>
314 /// <param name="xpsdw">
315 /// The document writer to output to.</param>
316 /// <param name="idp">
317 /// The paginated flow document to print.</param>
318 private void PrintSingleFlowContentDocument(
319 XpsDocumentWriter xpsdw, DocumentPaginator idp)
321 xpsdw.Write(idp); // Write the IDP as a document
324 // ----------------- PrintSingleFixedContentDocument ------------------
325 /// <summary>
326 /// Synchronously prints of a given fixed
327 /// document to a specified document writer.</summary>
328 /// <param name="xpsdw">
329 /// The document writer to output to.</param>
330 /// <param name="fd">
331 /// The fixed document to print.</param>
332 private void PrintSingleFixedContentDocument(
333 XpsDocumentWriter xpsdw, FixedDocument fd)
335 xpsdw.Write(fd); // Write the FixedDocument as a document.
339 // ---------------- PrintMultipleFixedContentDocuments ----------------
340 /// <summary>
341 /// Synchronously prints multiple fixed documents from a given
342 /// FixedDocumentSequence to a specified DocumentWriter.</summary>
343 /// <param name="xpsdw">
344 /// The document writer to output to.</param>
345 /// <param name="fds">
346 /// The fixed document sequence to print.</param>
347 private void PrintMultipleFixedContentDocuments(
348 XpsDocumentWriter xpsdw, FixedDocumentSequence fds)
350 xpsdw.Write(fds); // Write as a collection of documents.
353 #endregion // Synchronous Print Methods
356 #region Asynchronous Print Methods
358 // ------------------------- PrintVisualAsync -------------------------
359 /// <summary>
360 /// Initiates asynchronous output of a given
361 /// visual to a specified document writer.</summary>
362 /// <param name="xpsdw">
363 /// The document writer to output to.</param>
364 /// <param name="v">
365 /// The visual to print.</param>
366 private void PrintVisualAsync(XpsDocumentWriter xpsdw, Visual v)
368 _xpsdwActive = xpsdw; // Save the active document writer.
370 xpsdw.WritingCompleted +=
371 new WritingCompletedEventHandler(AsyncPrintCompleted);
373 xpsdw.WriteAsync(v); // Write the visual to a single page.
377 // ------------------------- PrintVisualsAsync ------------------------
378 /// <summary>
379 /// Initiates asynchronous output of a given list of
380 /// visuals to a specified document writer.</summary>
381 /// <param name="xpsdw">
382 /// The document writer to output to.</param>
383 /// <param name="vc">
384 /// The list of visuals to print.</param>
385 private void PrintVisualsAsync(XpsDocumentWriter xpsdw, List<Visual> vc)
387 _xpsdwActive = xpsdw; // Save the active document writer.
389 xpsdw.WritingCompleted +=
390 new WritingCompletedEventHandler(AsyncPrintCompleted);
392 xpsdw.WritingProgressChanged +=
393 new WritingProgressChangedEventHandler(AsyncPrintingProgress);
395 // Setup for writing multiple visuals
396 VisualsToXpsDocument vToXpsD =
397 (VisualsToXpsDocument)xpsdw.CreateVisualsCollator();
399 _batchProgress = 0;
400 _activeVtoXPSD = vToXpsD;
402 // Iterate through all visuals in the collection.
403 foreach (Visual v in vc)
405 vToXpsD.WriteAsync(v); //Write each visual to a single page.
407 }// end:PrintVisualsAsync()
410 // --------------- PrintSingleFlowContentDocumentAsync ----------------
411 /// <summary>
412 /// Initiates asynchronous output of a given paginated
413 /// flow document to a specified document writer.</summary>
414 /// <param name="xpsdw">
415 /// The document writer to output to.</param>
416 /// <param name="idp">
417 /// The paginated flow document to print.</param>
418 private void PrintSingleFlowContentDocumentAsync(
419 XpsDocumentWriter xpsdw, DocumentPaginator idp)
421 _xpsdwActive = xpsdw; // Save the active document writer.
423 xpsdw.WritingCompleted +=
424 new WritingCompletedEventHandler(AsyncPrintCompleted);
426 xpsdw.WriteAsync(idp); // Write the IDP as a document.
427 }// end:PrintSingleFlowContentDocumentAsync()
430 // --------------- PrintSingleFixedContentDocumentAsync ---------------
431 /// <summary>
432 /// Initiates asynchronous print of a given fixed
433 /// document to a specified document writer.</summary>
434 /// <param name="xpsdw">
435 /// The document writer to output to.</param>
436 /// <param name="fd">
437 /// The fixed document to print.</param>
438 private void PrintSingleFixedContentDocumentAsync(
439 XpsDocumentWriter xpsdw, FixedDocument fd)
441 _xpsdwActive = xpsdw; // Save the active document writer.
443 xpsdw.WritingCompleted +=
444 new WritingCompletedEventHandler(AsyncPrintCompleted);
446 xpsdw.WriteAsync(fd); // Print the FixedDocument.
450 // -------------- PrintMultipleFixedContentDocumentsAsync -------------
451 /// <summary>
452 /// Initiates asynchronous print of multiple fixed documents from a
453 /// given FixedDocumentSequence to a specified DocumentWriter.</summary>
454 /// <param name="xpsdw">
455 /// The document writer to output to.</param>
456 /// <param name="fds">
457 /// The fixed document sequence to print.</param>
458 private void PrintMultipleFixedContentDocumentsAsync(
459 XpsDocumentWriter xpsdw, FixedDocumentSequence fds)
461 _xpsdwActive = xpsdw; // Save the active document writer.
463 xpsdw.WritingCompleted +=
464 new WritingCompletedEventHandler(AsyncPrintCompleted);
466 xpsdw.WritingProgressChanged +=
467 new WritingProgressChangedEventHandler(AsyncPrintingProgress);
469 // Write the FixedDocumentSequence as a
470 // collection of documents asynchronously.
471 xpsdw.WriteAsync(fds);
472 }// end:PrintMultipleFixedContentDocumentsAsync()
475 // ---------------------------- CancelAsync ---------------------------
476 /// <summary>
477 /// Cancels the current asynchronous print opertion.</summary>
478 public void CancelAsync()
480 _xpsdwActive.CancelAsync();
483 #endregion // Asynchronous Print Methods
486 #region Async Event Handlers
488 // ------------------------ AsyncPrintCompleted -----------------------
489 /// <summary>
490 /// Creates an "async operation complete" event handler
491 /// for print completion of a FixedDocumentSequence.</summary>
492 private void AsyncPrintCompleted(
493 object sender, WritingCompletedEventArgs e)
495 string result = null;
496 if (e.Cancelled)
497 result = "Canceled";
498 else if (e.Error != null)
499 result = "Error";
500 else
501 result = "Asynchronous Print Completed";
503 if (OnAsyncPrintChange != null)
505 AsyncPrintEventArgs asyncInfo =
506 new AsyncPrintEventArgs(result, true);
507 OnAsyncPrintChange(this, asyncInfo); // update display status
509 }// end:AsyncPrintCompleted()
512 // ----------------------- AsyncPrintingProgress ----------------------
513 /// <summary>
514 /// Creates an "async operation progress" event handler for tracking
515 /// the progress in printing a FixedDocumentSequence.</summary>
516 private void AsyncPrintingProgress(
517 object sender, WritingProgressChangedEventArgs e)
519 _batchProgress++;
521 if (OnAsyncPrintChange != null)
523 String progress = String.Format("{0} - {1}",
524 e.WritingLevel.ToString(), e.Number.ToString());
525 AsyncPrintEventArgs asyncInfo =
526 new AsyncPrintEventArgs(progress, false);
527 OnAsyncPrintChange(this, asyncInfo); // update display status
530 // Will only called EndBatchWrite when serializing Multiple Visuals
531 if (_activeVtoXPSD != null && _batchProgress == 3)
533 _activeVtoXPSD.EndBatchWrite();
535 }// end:AsyncPrintingProgress()
538 // ----- MultipleFixedContentDocuments_WritingPrintTicketRequired -----
539 /// <summary>
540 /// Creates a PrintTicket event handler for
541 /// printing a FixedDocumentSequence.</summary>
542 private void MultipleFixedContentDocuments_WritingPrintTicketRequired(
543 Object sender, WritingPrintTicketRequiredEventArgs e)
545 if (e.CurrentPrintTicketLevel ==
546 PrintTicketLevel.FixedDocumentSequencePrintTicket)
548 // Create a PrintTicket for the FixedDocumentSequence. Any
549 // PrintTicket setting specified at the FixedDocumentSequence
550 // level will be inherited by lower level (i.e. FixedDocument or
551 // FixedPage) unless there exists lower level PrintTicket that
552 // sets the setting differently, in which case the lower level
553 // PrintTicket setting will override the higher level setting.
554 PrintTicket ptFDS = new PrintTicket();
555 ptFDS.PageOrientation = PageOrientation.Portrait;
556 ptFDS.Duplexing = Duplexing.TwoSidedLongEdge;
557 e.CurrentPrintTicket = ptFDS;
560 else if (e.CurrentPrintTicketLevel ==
561 PrintTicketLevel.FixedDocumentPrintTicket)
563 // Use different PrintTickets for different FixedDocuments.
564 PrintTicket ptFD = new PrintTicket();
566 if (_firstDocumentPrintTicket <= 1)
567 { // Print the first document in black/white and in portrait
568 // orientation. Since the PrintTicket at the
569 // FixedDocumentSequence level already specifies portrait
570 // orientation, this FixedDocument can just inherit that
571 // setting without having to set it again.
572 ptFD.PageOrientation = PageOrientation.Portrait;
573 ptFD.OutputColor = OutputColor.Monochrome;
574 _firstDocumentPrintTicket++;
577 else // if (_firstDocumentPrintTicket > 1)
578 { // Print the second document in color and in landscape
579 // orientation. Since the PrintTicket at the
580 // FixedDocumentSequence level already specifies portrait
581 // orientation, this FixedDocument needs to set its
582 // PrintTicket with landscape orientation in order to
583 // override the higher level setting.
584 ptFD.PageOrientation = PageOrientation.Landscape;
585 ptFD.OutputColor = OutputColor.Color;
588 e.CurrentPrintTicket = ptFD;
589 }// end:else if (CurrentPrintTicketLevel==FixedDocumentPrintTicket)
591 // Even though we don't show code for specifying PrintTicket for
592 // the FixedPage level, the same inheritance-override logic applies
593 // to FixedPage as well.
595 }// end:MultipleFixedContentDocuments_WritingPrintTicketRequired()
598 // -------------- CreateFixedDocumentSequencePrintTicket --------------
599 /// <summary>
600 /// Creates a FixedDocumentSequence compatible PrintTicket.</summary>
601 /// <returns>
602 /// A FixedDocumentSequence compatible PrintTicket.</returns>
603 private PrintTicket CreateFixedDocumentSequencePrintTicket()
605 // Create a local print server
606 LocalPrintServer ps = new LocalPrintServer();
608 // Get the default print queue
609 PrintQueue pq = ps.DefaultPrintQueue;
611 // Get the default user print ticket
612 PrintTicket pt = pq.UserPrintTicket;
614 // Set Duplexing value for each document in the job
615 pt.Duplexing = Duplexing.OneSided;
617 return pt;
618 }// end:CreateFixedDocumentSequencePrintTicket()
621 // ------------------ CreateFixedDocumentPrintTicket ------------------
622 /// <summary>
623 /// Creates a FixedDocument compatible PrintTicket.</summary>
624 /// <param name="isLandscaped">
625 /// true to output in landscape; false to output in portrait.</param>
626 /// <returns>
627 /// A FixedDocument compatible PrintTicket.</returns>
628 private PrintTicket CreateFixedDocumentPrintTicket(bool isLandscaped)
630 // Create a local print server
631 LocalPrintServer ps = new LocalPrintServer();
633 // Get the default print queue
634 PrintQueue pq = ps.DefaultPrintQueue;
636 // Get the default user print ticket
637 PrintTicket pt = pq.UserPrintTicket;
639 // Set Duplexing value for the document
640 pt.Duplexing = Duplexing.TwoSidedLongEdge;
642 if (isLandscaped)
643 pt.PageOrientation = PageOrientation.Landscape;
645 return pt;
646 }// end:CreateFixedDocumentPrintTicket()
648 #endregion // Async Event Handlers
651 #region Helper Methods
653 // -------------------- GetPrintXpsDocumentWriter() -------------------
654 /// <summary>
655 /// Returns an XpsDocumentWriter for the default print queue.</summary>
656 /// <returns>
657 /// An XpsDocumentWriter for the default print queue.</returns>
658 private XpsDocumentWriter GetPrintXpsDocumentWriter()
660 // Create a local print server
661 LocalPrintServer ps = new LocalPrintServer();
663 // Get the default print queue
664 PrintQueue pq = ps.DefaultPrintQueue;
666 // Get an XpsDocumentWriter for the default print queue
667 XpsDocumentWriter xpsdw = PrintQueue.CreateXpsDocumentWriter(pq);
668 return xpsdw;
669 }// end:GetPrintXpsDocumentWriter()
671 // --------------- GetPrintXpsDocumentWriter(PrintQueue) --------------
672 /// <summary>
673 /// Returns an XpsDocumentWriter for a given print queue.</summary>
674 /// <param name="pq">
675 /// The print queue to return the XpsDocumentWriter for.</param>
676 /// <returns>
677 /// An XpsDocumentWriter for the given print queue.</returns>
678 private XpsDocumentWriter GetPrintXpsDocumentWriter(PrintQueue pq)
680 XpsDocumentWriter xpsdw = PrintQueue.CreateXpsDocumentWriter(pq);
681 return xpsdw;
682 }// end:GetPrintXpsDocumentWriter(PrintQueue)
685 // -------------------- GetPrintXpsDocumentWriter() -------------------
686 /// <summary>
687 /// Returns a scaled copy of a given visual transformed to
688 /// fit for printing to a specified print queue.</summary>
689 /// <param name="v">
690 /// The visual to be printed.</param>
691 /// <param name="pq">
692 /// The print queue to be output to.</param>
693 /// <returns>
694 /// The root element of the transformed visual.</returns>
695 private Visual PerformTransform(Visual v, PrintQueue pq)
697 ContainerVisual root = new ContainerVisual();
698 const double inch = 96;
700 // Set the margins.
701 double xMargin = 1.25 * inch;
702 double yMargin = 1 * inch;
704 PrintTicket pt = pq.UserPrintTicket;
705 Double printableWidth = pt.PageMediaSize.Width.Value;
706 Double printableHeight = pt.PageMediaSize.Height.Value;
708 Double xScale = (printableWidth - xMargin * 2) / printableWidth;
709 Double yScale = (printableHeight - yMargin * 2) / printableHeight;
711 root.Children.Add(v);
712 root.Transform = new MatrixTransform(xScale, 0, 0, yScale, xMargin, yMargin);
714 return root;
715 }// end:PerformTransform()
718 #endregion // Helper Methods
721 #region Private Data
722 private int _batchProgress = 0;
723 private int _firstDocumentPrintTicket = 0;
724 private String _contentDir = null;
725 private WPFContent _wpfContent = null;
726 private VisualsToXpsDocument _activeVtoXPSD = null;
727 private XpsDocumentWriter _xpsdwActive = null;
728 #endregion // Private Data
730 }// end:class XpsPrintHelper
732 }// end:namespace SDKSampleHelper