In this section we will see how we can add printing support in WPF applications. We will start off with printing and XPS and then move on to XPSDocumentWriter and then we will have a look on how to work with print options and customize print dialog.

XPS – XML Paper Specification

The API for printing is the same as the API for creating the XPS document. XPS has two important features.

  • It provides native print spool option which is useful for WPF printing. XPS is designed to WPF native graphics model efficiently. In theory XPS can go to the target device and rasterized there to provide maximum fidelity. Although in practice most printers don’t know how to render xps but this was the design while designing XPS.
  • XPS acts as the fixed layout document format i.e. like pdf version of the WPF.

We can generate a XPS document by printing something using the Microsoft XPS Document Writer virtual printer. This is available on machines that have .NET 3.0 installed. When we print something using this device it saves a document in XPS format on the disk.

XPS Document Writer

XPS Document Writer

The default viewer for XPS is internet explorer. It’s a file that contains all the pages to be printed. If we zoom in we will see that the text is scaling properly.

The file convention is based on what the office files use. If we change the extension of the file from .xps to .zip and extract the contents of it then we will see that there is a documents folder.

 

WPF PRint Documents Folder

WPF PRint Documents Folder

If we go inside it we will see that there is a pages folder which will contain a file corresponding to each page.

 

WPF Print Pages Folder

WPF Print Pages Folder

When we open these pages in visual studio we will see WPF elements in it so this is xaml with base as FixedPage. All the shapes are rendered by Path. The text that XPS uses is Glyphs which derives from shape and it helps us define how the text looks like by using shapes. Glyph is a much lower level way of handling text than a text block. You should know that XPS does not use all the elements of xaml but only a limited set as all the systems running xps might not be running .NET

 

XPS Page in XAML

XPS Page in XAML

The font is specified as a file in a relative URI in the resources dictionary. These have scrambled names. The resources folder also has all the bitmaps in use as well. There are generally the Bitmaps of the text for which the licensing is not available for distribution.

 

WPF XPS Fonts

WPF XPS Fonts

The directory structure shown below is just for the user’s convenience.

 

WPF XPS Directory Structure

WPF XPS Directory Structure

We should look at the .rels file to see the entry points into the package. It contains a series of relationships which are the links identified by the URI. The document that we have has 3 relationships.

  • The namespace
  • The entry point called FixedDocumentSequence.fdseq. This contains the links to all the pages. These roots types are all reflecte din the API
  • Identifies the metadata i.e. thumbnail

 

WPF XPS .rels

WPF XPS .rels

XpsDocumentWriter

The class used for creating the XPS document is the same as the class for printing in WPF. It is XpsDocumentWriter. The target for the writer (XPS file or Printer) depends on from where we got the writer handle in the first place.

If we get the writer from the PrintQueue then the writer will write to the printer.

 

XpsDocumentWriter

XpsDocumentWriter

If the writer from XpSDocumnet’s CreateXpsWriterWriter method then the output will go to xps file on disk.

 

XpsDocumentWriter

XpsDocumentWriter

Let’s see this in action. Add the following code to the click handler of a button.

 

XpsDocumentWriter

XpsDocumentWriter

Now when we run the application then we ask the PrintQueue to give us a XpsDocumentWriter and to get that we just pass a null printable area. After that we will get an option to choose the printer as we have not already done that.

 

XpsDocumentWriter

XpsDocumentWriter

We select the actual printer and click on print. The PrintDocumentImageableArea contains the dimensions of the paper we are printing on. The Media Size height and width tells us the size of the paper. As you might know that we cannot print all the way to the end of the paper as it might put ink to the printer edges. So we have a margin specified via OriginalHeight and OriginalWidth. The units are in DPI i.e. 1/96th of an inch.

 

XpsDocumentWriter

XpsDocumentWriter

Then we return back to the application and the code for creating a textblock is executed. This will be the visual tree that we will be printing. As you can see in the code we have assigned the top and left margin the same as to where the paper can print.

Next we need to create the layout. This would have been automatically if our visual tree was hosted inside a window but as there is no window we need to do it. So measure, arrange and update the layout.

Then we print the document.

If we use the Microsoft XPS Document Writer as the printer

 

XpsDocumentWriter

XpsDocumentWriter

Then we will have the OriginalHeight and OriginalWidth as 0 in the PrintDocumentImageableArea.

 

XpsDocumentWriter

XpsDocumentWriter

Now when we reach the write method we get to choose the save location of the xps document.

 

XpsDocumentWriter

XpsDocumentWriter

The XPS file looks something like this. As the virtual printer told us that there is no margin the text is next to the edge.

 

XpsDocumentWriter

XpsDocumentWriter

Printing Multiple Pages

We cannot call the Write method twice as it will throw an error. So we need to follow a different technique to print multiple pages. We need to use the SerializerWriteCollater to print multiple pages. We call the BeginBatchWrite to start the print spooling process and then we will call EndBatchWrite after the finishing the print job. We can use the code below to see multiple pages printing works.

 

WPF Printing Multiple Pages

WPF Printing Multiple Pages

The XPS document will contain 10 pages.

 

WPF Printing Multiple Pages

WPF Printing Multiple Pages

Document Paginator

In the previous section we how we can print Visual Trees. The overloaded write method of the XpsDocumentWriter takes a DocumentPaginator as input. DocumentPaginator is an object that knows how to display content in pages. FlowDocument, FlowDocumentPageViewer, FixedDocument uses this IDocumentPaginatorSource.

 

WPF Document Paginator

WPF Document Paginator

Multi Page – XPS

We can get a detailed control over the print document by handling the XPS object itself. The write method has 3 overloads that accept

  • FixedPage – For printing a single page.
  • FixedDocument – For printing single document
  • FixedDocumentSequence. – For printing Multi document print job
WPF Multi Page XPS

WPF Multi Page XPS

 

Let’s see this in action. In the code below we can see that we have added a FixedDocument that contains Fixed Pages. The FixedPage has a children collection that will contain as many items as we like and we have positioned them like we position children in a canvas. Then we add the page to the FixedDocument. We need to provide the PageContent that will go in to the PageDocument sequence and this will contain the links to the actual child pages itself. So we build the Page content and then point that at the child FixedPage object itself. IAddChild is how we add children to elements.

 

WPF Multi Page XPS

WPF Multi Page XPS

And the output looks something like below.

 

WPF Multi Page XPS

WPF Multi Page XPS

Asynchronous Printing

All the methods offered by the XpsDocumentWriter are also available in the Async form like WriteAsync. These perform the printing process using the User Interface’s thread idle time. The progress change and Progress complted eventes are raised for tracking the progress of the print process. It also provides a CancelAsync method that cancels the printing. For all this to work we need to be running in WPF User Interface thread that’s running a message loop as this requires the idle time.

PrintTicket

The PrintTicket class represents some of the common features like Collation, orientation, resolution, quality, etc. these are the printer properties that are available when will click on printer properties button in the print dialog. It is also extensible so that the printer specific settings can be attached to the PrintTicket.

PrintTickets can have different TicketScopes like document, print job or a page.

We can get the default print settings of the printer from the PrintQueue object of the printer. There are two properties:

  • UserPrintTicket – Contains user defaults
  • DefaultPrintTicket – Contains system wide defaults

As you might expect that all print cannot do everything so we can make use of PrintCapabilities class to get the Valid PrintTicket options for specific printer and the printer specific custom options.

PrintDialog

In the previous section we saw that the PrintDialog was automatically popped by WPF when the printer selection was required. But we can do this using the code as well. And me will need to do it via code at places where we need to find out the capabilities of the printer, etc. And then can set or get various printing options.

 

WPF PrintDialog

WPF PrintDialog

Queues and Servers

The classes PrintDialog, PrintTicket and PrintQueue (It is specific to a printer) are part of System.Printing namespace introduced by .NET 3.0. We can use this API to configure remote print server or PrintQueue. It also provides configuration options, discovery and monitoring. PrintServer represents a particular class with printers attached and can provide PrintQueue for each of the connected printers.

Any questions, comments and feedback is most welcome.

The Code for this post can be found here.

 

Microsoft has released a 90-day test edition for its last version of Windows 8 operating system, which is slated to go on selling on October 26 this year. The run, withal, is obtainable only for the Enterprise edition of Windows 8 and is aimed at developers who think to shape apps, and IT administrators who requisite to try out the new OS before making their pick to migrate, all onwards of its adjudicator commencement. Microsoft recently released closing variant of Windows 8 to MSDN and Technet subscribers.

 

The Windows 8 Task test edition is available in 32 and 64 bits versions. To download the operating group, users require to tally a subscription to Windows Lively. Also, users require to score a 1GHz processor with 1GB of RAM and 20GB of hard disc character as minimum falsification responsibility. A determine of run ISO images are also provided for a tracheophyte of languages in x86 (32-bit) and x64 (64-bit)versions.

 

The Task edition comes with all the features of Windows 8 Pro and is statesman business-focused. It has options much as Windows To Go (which allows Windows 8 installation from a USB key).

 

If you are preparation to download the experiment association, beneath are many pointers before you commencement:

The rating edition testament suspire and cannot be upgraded.

To advance, the assessment must be uninstalled and a non-evaluation writing of Windows staleness be re-installed from your innovational instalment media.

Ponder spouting the evaluation edition in a realistic environment or instalment on a other semihard road or partition. The gift reckon you to rise your example Windows beginning to Windows 8.

During body (required) you staleness login with a Microsoft declare and furnish your canvass, e-mail tact and country.

You are required to change the fluid online within 10 life after installment.

Formerly the valuation is installed, you cannot grade. To turn to a old type of Windows, you moldiness do a unqualified pose from your model artifact media.

 

For more details on activation click here.

 

The rivalry between Apple and Google has reached a new superlative — Apple has declared that the latest type of their ambulant OS, iOS 6, which testament run on the iPad, iPhone and iPod speck, testament not countenance the touristed video moving app, YouTube, someone out of the box. The boys at Cupertino say that the app faculty be disposable on iOS, but won’t be a place impede fail.

 

 

Still, the video streaming accommodation will be noneffervescent useable to users via the web browser.

 

The removal of YouTube as a individual app is a bit of a downer for users, and sure intensifies the tension between the two technology giants. Apple had recently announced that it would be replacing Google Maps in iOS with its own maps app.

 

Currently, Apple and Google are the marketplace dominators with their several rangy OSes i.e., iOS and Humanoid respectively.

 

Apple seems to be action all the indispensable steps to size itself from competition Google. What remains to be seen is whether Google module stay as the fail investigate for Apple’s devices or Apple is preparation up whatsoever deciding for that as fortunate.

 

Google and Apple are the two companies that feature had rattling honorable relations in the medieval, to the muzzle that sometime Google CEO Eric Statesman was a relation of Apple’s dwell of directors. The relationship between the two companies, still, has seen a downfall in the early deuce of eld. One of the crucial reasons of the downfall was that according to the latish Steve Jobs, the Robot OS is a somebody of iOS.

 

How the removal of the endemic app from iOS 6 testament concern the users works remains to be seen. What do you expect? Was it a wise displace to remove Google Maps and YouTube from iOS?

 

The Apple Worldwide Developer’s Conference saw everything from refreshed Macbook constituent (Air and Pro), to a new developer advertising of Elevation Celebrity, and iOS 6, with its computer of improvements. iOS 6 has been released to developers, time end-users module get their hands on the new operative method by the Denizen break.

The WWDC rumours we’d been chance ahead of the circumstance were blemish on, predicting most Apple’s announcements. Foreseen improvements to Apple’s movable operating system, iOS, in the new variant, were revealed at WWDC 2012, such as deeper Facebook integrations, iCloud updates like Joint Exposure Line albums, a new Maps app, and an enhanced Siri.

Apple says over 200 new features and improvements someone launches their way to iOS 6, and the complement did pass quite a few info. Apple’s deeper Facebook integrating translates into such features as pointed validate in and sign from the Notification Eye (as asymptomatic as Siri and Facebook-enabled apps), real-time updates to Facebook accumulation, from contacts to events, across all iOS devices. Users leave also be healthy to ‘Like’ App Stock and iTunes proportion, directly, whilst sightedness friend’s recommendations on the assonant platforms.

Siri give now employ on the New iPad as cured as iPhone 4S, and gets wider faculty living, including Country, Nation, Germanic and Nipponese, and adds validation for Country, Italian, Asian, Mandarin and Cantonese. Apple says the personalized helper is now optimized for 15 countries, with topical aggregation. Added improvements to Siri allow voice-based placard to Facebook and Sound without launch an app. Apple has advanced with virgin voice-based examine, enabling the two iOS devices to be used in a ‘Eyes Free’ modality, not requiring perception happening. This theoretically extends to a symbol of instrument succeed Apple’s certainty on Google and remaining gear parties in the employment department, providing vector-based maps with promised fluid graphics, turn-by-turn vox piloting, and reciprocal 3D maps with ‘Flyover’. Apple’s new Maps app also supports real-time reciprocation entropy, with term, and memorise way suggestions. Topical maps instrument also have Cry ratings for roughly 100 million businesses.

Otherwise improvements to iOS 6 countenance a new Passbook app – a new single-point programme for scanning and displaying passes. The Record app can demo real-time notifications, divided from automatically show passes on the ringlet protect, depending on abstraction or locating. iOS 6 also features new paternal controls in the work of Guided Make – locking the iOS gimmick on to a bingle app, throttle stir signaling, and writer.

New iOS 6 features including improvements to the Expedition raiseable application, such as iCloud tabs, offline measuring lists, exposure uploads and replete protection examine; keep for FaceTime calls over cancelled networks; a VIP Box; deciding to auto-message tell on telephone cancelling; callback reminders; and a Do Not Change alternative. Apple has also side a multitude of China-specific features, specified as developed text sign, and strengthener for services specified as Baidu, Sina Weibo, Youku and Tudou.

 

iOS6

iOS6

Reference – http://www.engadget.com/2012/06/11/apple-unveils-ios-6-at-wwdc/

 

Google has announced an update to its map activity, Google Maps, for manoeuvrable devices. The update v6.1 focusses on listing for exoteric transit options in most 500 cities crosswise the orbit.

 

Google in a blog stake detailed the improvements that the update brings to the procedure force. Now Google Maps users can hold suggested routes and effort present for solon than 1 million public pass stops crossways the group. Google instrument also give inside directions for work.

 

“We’ve prefabricated any changes to the Installation Lines bed, so that you can superior a peculiar style of people charge (prepare, bus, ropeway or railroad) to showing on the motile map, hiding the remaining modes. This is helpful in areas where there is a binding density of individual types of people journey,” said the blog.

 

Mitt: Metropolis map with all modes of exclusive journey shown; Right: Journeying Lines sheet in Tube property

 

Left: Mobile map with all modes of public transit shown; Right: Transit Lines layer in Subway mode

Left: Mobile map with all modes of public transit shown; Right: Transit Lines layer in Subway mode

Moreover, Google has updated the layout of rank pages to be many recyclable. Open it by tapping on the name of the position on your metropolis map.

Updated station pages show you departure times, lines serving the station and the distance to nearby stations.

Updated station pages show you departure times, lines serving the station and the distance to nearby stations.

Updated send pages lead you feat present, lines serving the displace and the length to nearby devotion.

 

Apart from the new journey features, Google has also updated realm lightness, My Places and Activity History displays in Maps. Users faculty now be fit to see borders of a part. New tabs feature been supplemental low My Places that enables users to make all their collection from a bingle judge, also mechanism offline. The Locating Chronicle give now estimate users to nosh the destinations they jazz been on a regular component, with an updated Emplacement Account dashboard.

 

Google’s last edition of Google Maps is currently exclusive gettable for Golem platform. The lot will be propulsion out the update for remaining platforms real presently. Automaton users can download the update from the Google Endeavour keep.

 

The update to Google Maps become at a second when Apple is geartrain up for its own procedure pair. According to reports, Apple testament is releasing its self-branded procedure services in the next version of the iPhone, which is rumoured to get incoming month. Late, Apple declared dropping built-in YouTube app from its IOS 6.

Reference – http://googleblog.blogspot.in/2012/08/google-maps-now-has-schedules-for-more.html#!/2012/08/google-maps-now-has-schedules-for-more.html