Printing
When printing from TX Text Control .NET for Windows Forms doesn't do what you expect, TX Text Control usually shows no error: the document prints the wrong pages, looks different on paper, or doesn't print at all. The problems below start from what you see. Print a Document shows how printing works in the first place.
Printing Is Disabled or Does Nothing
The Print command of your application is grayed out or doesn't print, while other documents print.
Whether a document can be printed depends on the document. CanPrint tells you, and its value depends on DocumentPermissions.AllowPrinting and the current EditMode. AllowPrinting is true by default. A PDF document can also restrict printing: when the permissions of a loaded PDF don't allow printing, an application should disable its print command.
- Check
CanPrintbefore you call Print, and enable or disable your print command with it. - If the document is protected, check the edit mode and the DocumentPermissions that the document sets.
- For a PDF document, check LoadSettings.DocumentAccessPermissions after loading, as Respect the Permissions of a PDF shows. If you have the owner password, load the document with it in MasterPassword: then all permissions are granted.
The Whole Document Prints Instead of Some Pages
You set FromPage and ToPage of the PrintDocument, but every page of the document prints.
A page range takes effect only when the PrintRange of the printer settings is PrintRange.SomePages.
- Set
PrinterSettings.PrintRangeof thePrintDocumenttoPrintRange.SomePages. - Set
FromPageandToPage. Pages returns the number of pages, so thatToPagedoesn't exceed it. - Pass the
PrintDocumenttoPrint.
Print Without a Dialog shows the code.
A Status Dialog Appears While Printing
While the document prints, a dialog box of .NET shows the page being printed, for example:
Page 5 of document
The default print controller of .NET shows this dialog. TX Text Control uses the print controller of the PrintDocument you pass.
- Create a
StandardPrintControllerand assign it to thePrintControllerof thePrintDocument. - Pass the
PrintDocumenttoPrint.
Line and Page Breaks on Paper Differ From the Screen
The printed document breaks lines or pages in other places than the editor shows.
TX Text Control formats a document with the text dimensions of the printer that FormattingPrinter names, as The Layout Depends on the Printer explains. When the document is printed on another printer, or formatted with the value Display, the dimensions on paper can differ.
- Set
FormattingPrinterto the printer you print on. - On machines where that printer isn't installed, expect the formatting of the standard printer, or name a printer that every machine has.
Format the Document for the Printer shows the setting.
The Editor Starts Slowly
Creating the first TextControl or ServerTextControl takes seconds, especially on machines with a network or wireless default printer.
When TX Text Control initializes, it asks the default printer for its dimensions, even when FormattingPrinter is Display. A printer that is in energy saving mode or answers slowly over the network delays the initialization.
- In
Mainof Program.cs, set the static propertyDefaultFormattingPrintertoDisplaybefore the first control is created, as Start Without Waiting for a Printer shows. - Rebuild the application and compare the start time.
DefaultFormattingPrinter has no page in the reference; the blog article Initialize Text Control Without a Printer (Completely) is its source.
Documents Look Different When the Print Spooler Is Disabled
With the Windows Print Spooler service stopped or disabled, documents are laid out differently than on other machines.
Without the print spooler, TX Text Control can't reach a printer and uses the screen for formatting. Documents can then be rendered differently than usual, and a FormattingPrinter you set is no longer used. The blog article Impact by "PrintNightmare" Vulnerability on DocumentEditor describes this fallback.
- Start the Print Spooler service again, and keep it running on machines that run your application.