Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have rewritten my answer to this question, because I did find a better way to print a set of FlowDocuments, while showing the Print Dialog only once. The answer comes from MacDonald, Pro WPF in C# 2008 (Apress 2008) in Chapter 20 at p. 704.</p> <p>My code bundles a set of Note objects into an IList called notesToPrint and gets the FlowDocument for each Note from a DocumentServices class in my app. It sets the FlowDocument boundaries to match the printer and sets a 1-inch margin. Then it prints the FlowDocument, using the document's DocumentPaginator property. Here's the code:</p> <pre><code>// Show Print Dialog var printDialog = new PrintDialog(); var userCanceled = (printDialog.ShowDialog() == false); if(userCanceled) return; // Print Notes foreach(var note in notesToPrint) { // Get next FlowDocument var collectionFolderPath = DataStore.CollectionFolderPath; var noteDocument = DocumentServices.GetFlowDocument(note, collectionFolderPath) ; // Set the FlowDocument boundaries to match the page noteDocument.PageHeight = printDialog.PrintableAreaHeight; noteDocument.PageWidth = printDialog.PrintableAreaWidth; // Set margin to 1 inch noteDocument.PagePadding = new Thickness(96); // Get the FlowDocument's DocumentPaginator var paginatorSource = (IDocumentPaginatorSource)noteDocument; var paginator = paginatorSource.DocumentPaginator; // Print the Document printDialog.PrintDocument(paginator, "FS NoteMaster Document"); } </code></pre> <p>This is a pretty simple approach, with one significant limitation: It doesn't print asynchronously. To do that, you would have to perform this operation on a background thread, which is how I do it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload