TX Text Control .NET Server

Printing

Topic

A service that prints delivery notes or merged letters sends documents to a printer without any user interface. ServerTextControl prints through the PrintDocument class of .NET, with the printer, page range and number of copies you choose, and it prints several documents in one print job. For web applications, a PDF that users print in the browser is often the better way.

Printing in the browser is described in Printing in the Document Viewer section and in Viewing and Printing in the Document Editor section.

Requirements

ServerTextControl.Print takes a System.Drawing.Printing.PrintDocument, which uses the printers installed on Windows. That class comes with System.Drawing.Common, a dependency of the Classic package TXTextControl.TextControl.ASP.SDK and not of the Core package, so the examples use Classic in a .NET console application on Windows, as the blog article Print MS Word DOCX Documents in .NET using C# Without Interop does. Create Your First Application compares the two packages.

Applications that run on Linux or in containers create a PDF instead and let users print it, as described in Let Users Print in the Browser.

Choose the Formatting Printer

TX Text Control formats text with the measurements of a device: the exact character widths, kerning and spacing. ServerTextControl.FormattingPrinter sets the name of the printer whose measurements are used, so that a document printed on that printer has the same line and page breaks as on screen:

ValueFormats with
The name of a printerThe measurements of that printer; if it isn't installed, the standard printer is used
"Standard"The standard printer of the system
"Display"The measurements of the display device, which are similar on all machines

On a server, the formatting printer matters for two reasons:

  • Templates look different on another machine when it formats with another printer. Using the same printer, or "Display" on both machines, avoids this, as the blog article WYSIWYG: What You Need to Know! explains.
  • Printers slow down initialization. A network printer or a printer in energy-saving mode that responds late delays the creation of an instance, as the blog article Initialize Text Control Without a Printer (Completely) describes.

GetSupportedFonts and GetSupportedPaperSizes return the fonts and paper sizes of the formatting printer.

Let Users Print in the Browser

In a web application, users print on their own printers, not on the server's. Create a PDF on the server and let users print it:

  • Save the document as PDF and return it from a controller, as Save as DOCX and PDF shows. Creating the PDF needs no printer driver.
  • Show the document in the Document Viewer, whose Print button and printDocument method print it from the browser, as Printing in the Document Viewer section describes.

Next Steps