TX Text Control Source Code Library

Printing to different paper trays

Printing to different paper trays is daily business. The first page of a business letter is often printed on pre-printed letterhead. Or the envelope should be printed in the same print job, but using another paper source.

TX Text Control .NET for Windows Forms has been built for the .NET Framework and therefore it is very flexible, and can be used with the standards of .NET. This sample implements a very nice dialog box that can be used to specify the different paper sources for specific pages.

The first combo box allows you to select the required printer. In the Page settings, you can select a specific page in combination with an available paper source. By clicking Add settings, the selected combination is added and displayed in the grid view.

Apart from the code to select the printer or to get the available paper sources, the printing code is very simple. First, a new PrintDocument is created in order to attach a QueryPageSettings event. Then TX Text Control's Print method is called:

PrintDocument myDoc = new PrintDocument(); myDoc.QueryPageSettings += new QueryPageSettingsEventHandler(myDoc_QueryPageSettings); _tx.Print(myDoc);

This event is fired every time before a new page is printed and can be used to change the printer and page settings. We are using the event to change the paper sources according to our list of page settings.

void myDoc_QueryPageSettings(object sender, QueryPageSettingsEventArgs e) { pageCount++; foreach (PageSetting testSetting in MyPageSettings) { if (testSetting.PageNumber == pageCount) { e.PageSettings.PaperSource = testSetting.PaperSource; break; } else e.PageSettings.PaperSource = myDoc.PrinterSettings.PaperSources[0]; } }

Note that at least TX Text Control .NET for Windows Forms 14.0 trial version and Visual Studio .NET 2005 are required to run this sample.

Call us: +1 704-544-7445 (United States)





Buy Now

About Text Control

Founded in 1991, Text Control is an award-winning Visual Studio Industry Partner and leading vendor of word processing and reporting components for Microsoft development technologies. The products help thousands of developers add comprehensive word processing functionality to their applications. Text Control is 100% self-owned and independent of all investor decisions. Customers benefit from these years of experience, large user-base, and at the same time, appreciate developing with a mature, reliable product.

SD Times 100SD Times 100SD Times 100SD Times 100SD Times 100SD Times 100Visual Studio 2015 Launch PartnerVisual Studio 2013 Launch PartnerVisual Studio 2012 Launch PartnerVisual Studio Partner