create barcodes in vb.net Printing asynchronously in Visual C#

Generator PDF417 in Visual C# Printing asynchronously

Listing 18.4 Printing asynchronously
Drawing PDF-417 2d Barcode In C#.NET
Using Barcode generator for .NET Control to generate, create PDF 417 image in .NET applications.
www.OnBarcode.com
PDF-417 2d Barcode Reader In C#.NET
Using Barcode scanner for .NET framework Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
protected void OnPrint(object sender, RoutedEventArgs e) { PrintDialog printDialog = new PrintDialog(); printDialog.UserPageRangeEnabled = true; Allows choice of if (printDialog.ShowDialog() == true) pages to print { FlowDocument docCopy = CopyFlowDocument(searchResults.Document); docCopy.PagePadding = new Thickness(96); docCopy.ColumnWidth = double.NaN;
ECC200 Creation In Visual C#.NET
Using Barcode generator for .NET framework Control to generate, create ECC200 image in .NET framework applications.
www.OnBarcode.com
UPC A Generator In Visual C#.NET
Using Barcode generation for .NET framework Control to generate, create UPC-A Supplement 2 image in Visual Studio .NET applications.
www.OnBarcode.com
IDocumentPaginatorSource paginatorSource = docCopy as IDocumentPaginatorSource;
1D Barcode Generator In C#.NET
Using Barcode generation for .NET framework Control to generate, create 1D Barcode image in .NET framework applications.
www.OnBarcode.com
Draw Barcode In C#.NET
Using Barcode creator for VS .NET Control to generate, create Barcode image in .NET framework applications.
www.OnBarcode.com
Creates writer XpsDocumentWriter docWriter = PrintQueue.CreateXpsDocumentWriter(printDialog.PrintQueue);
GS1-128 Encoder In C#.NET
Using Barcode drawer for .NET Control to generate, create GS1-128 image in .NET framework applications.
www.OnBarcode.com
Code11 Generation In Visual C#.NET
Using Barcode printer for .NET framework Control to generate, create Code11 image in .NET applications.
www.OnBarcode.com
docWriter.WritingCompleted += new Subscribes to completed event System.Windows.Documents.Serialization. WritingCompletedEventHandler(docWriter_WritingCompleted); docWriter.WriteAsync(paginatorSource.DocumentPaginator); } }
PDF 417 Maker In None
Using Barcode generator for Font Control to generate, create PDF 417 image in Font applications.
www.OnBarcode.com
PDF-417 2d Barcode Maker In Java
Using Barcode drawer for Java Control to generate, create PDF 417 image in Java applications.
www.OnBarcode.com
Prints
Data Matrix 2d Barcode Generation In None
Using Barcode generation for Font Control to generate, create Data Matrix image in Font applications.
www.OnBarcode.com
Making Barcode In Visual Studio .NET
Using Barcode creator for ASP.NET Control to generate, create Barcode image in ASP.NET applications.
www.OnBarcode.com
void docWriter_WritingCompleted(object sender, System.Windows.Documents.Serialization.WritingCompletedEventArgs e) { MessageBox.Show("Done Printing!","Dictionary"); }
GS1-128 Maker In None
Using Barcode generation for Font Control to generate, create GS1 128 image in Font applications.
www.OnBarcode.com
Draw GTIN - 128 In None
Using Barcode drawer for Office Excel Control to generate, create UCC-128 image in Excel applications.
www.OnBarcode.com
Completed event handler
Draw QR Code 2d Barcode In VB.NET
Using Barcode encoder for .NET Control to generate, create QR Code image in VS .NET applications.
www.OnBarcode.com
Encode Code 128B In Objective-C
Using Barcode encoder for iPad Control to generate, create Code 128A image in iPad applications.
www.OnBarcode.com
Printing, documents, and XPS
Drawing Barcode In Visual Studio .NET
Using Barcode drawer for ASP.NET Control to generate, create Barcode image in ASP.NET applications.
www.OnBarcode.com
Encode EAN / UCC - 13 In VS .NET
Using Barcode generator for ASP.NET Control to generate, create GS1-128 image in ASP.NET applications.
www.OnBarcode.com
By default, the PrintDialog doesn t allow the user to print only certain pages. This isn t a big deal, but we thought we d turn on the option b. After that, things are about the same until we re ready to print. Now, instead of calling the Print() method on the dialog, we re calling a static method on the PrintQueue class that takes a PrintQueue as an argument and returns a writer set to print to that queue c. The next step is optional, but nice. We re subscribing to an event to tell us when printing is complete d. There s also an event that tells when each bit of the document has been printed, in case you want to update a progress display, or if the print job has been canceled. As you can see, our handler for when printing is completed pops up a message box f. Finally, we call the WriteAsync() method to do the actual printing e. We could instead called Write(), which would have printed synchronously, just as if we d used the Print() method on the PrintDialog(). When we run the code, we get the print dialog as usual, but there s no delay after we click OK. Figure 18.5 Very exciting notification about our background Instead, a few moments later, our print job being done. We should message box pops up (figure 18.5). print something a bit more complex Because we re only printing a couto make the asynchronous ple of pages, the dialog comes up approach really show off. very fast indeed. In fact, you may note that WPF printing is noticeably faster than, say, Windows Forms. It s nice how easy it is to print in the background. Also, now that we re no longer relying on the PrintDialog s Print method, we could, if we choose, skip the dialog altogether and go straight to the default printer (listing 18.5).
PDF 417 Creation In None
Using Barcode printer for Office Excel Control to generate, create PDF417 image in Microsoft Excel applications.
www.OnBarcode.com
Decoding Code 39 In Visual C#.NET
Using Barcode decoder for .NET Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
Listing 18.5 Printing without using PrintDialog
protected void OnPrint(object sender, RoutedEventArgs e) { FlowDocument docCopy = CopyFlowDocument(searchResults.Document); docCopy.PagePadding = new Thickness(96); docCopy.ColumnWidth = double.NaN; IDocumentPaginatorSource paginatorSource = docCopy as IDocumentPaginatorSource;
PrintQueue queue = LocalPrintServer.GetDefaultPrintQueue(); XpsDocumentWriter docWriter = PrintQueue.CreateXpsDocumentWriter(queue); docWriter.WritingCompleted += new System.Windows.Documents.Serialization. WritingCompletedEventHandler(docWriter_WritingCompleted); docWriter.WriteAsync(paginatorSource.DocumentPaginator); }
Gets default Queue
We ve dropped all the print dialog code, and, instead got the default queue. You might want to do this if you want your application to operate like MS Word, where the Print toolbar button prints to the default printer, whereas the Print option from
Printing FixedDocuments
the file menu gives you a dialog and options. You can also step through all the print queues and find the one you want.
18.2 Printing FixedDocuments
So far, our printing has been via the use of a FlowDocument, which works well for our particular content. But, often you want a very specifically formatted printout. We mentioned a couple of examples of this earlier printing a form or doing desktop publishing. For these applications, you want a lot more control over how a page is laid out, and that s precisely what a FixedDocument gives each page is laid out and added independently, and then the whole document is printed. That isn t to say that you have to lay out each letter in each word WPF will handle standard things like paragraphs and word-wrapping, but will give you the ability to specify, for example, where the paragraphs will go. And, if you re picky enough, you really could specify the exact location for each letter in each word. A FixedDocument is made up of pages, and each page can have any XAML content on it you like; it can use layouts to handle positioning, and any sort of controls you like although, because this is for printing, you can t interact with the controls, so you really end up with pictures of controls. We ve gone ahead and added another hyperlink to our application with the label Print Fixed and then put in a basic implementation. Our first version (listing 18.6) demonstrates putting some items in specific places on the printout. We ll look into adding content from our application in a little while.
Copyright © OnBarcode.com . All rights reserved.