Batch Printing: How to Print Documents in One Print Job
A typical requirement when printing loads of documents is managing the print jobs. A group of separate documents might be subsumed in a single print job. We just published a new sample in our source code library that show how to achieve this. Using TX Text Control, you have 2 options to realize this easily: You can append the document to TX Text Control in order to create one large document. You create your own print job in order to handle the printing yourself. The first option can be…

A typical requirement when printing loads of documents is managing the print jobs. A group of separate documents might be subsumed in a single print job. We just published a new sample in our source code library that show how to achieve this.
Using TX Text Control, you have 2 options to realize this easily:
- You can append the document to TX Text Control in order to create one large document.
- You create your own print job in order to handle the printing yourself.
The first option can be easily solved using TX Text Control and it's Append method. This method can be used to load existing documents to the end of the current document. The drawback of this approach is that the page numbering will be continued instead of restarted. This might be useful for other applications, but not for this goal.
The second approach is a little bit more complex, but still easy to solve using TX Text Control.
The general idea behind this approach is to use a .NET PrintDocument in order to print each single page of every document using TX Text Control separately in the PrintPage event of the PrintDocument.
First, we create a new PrintDocument:
PrintDocument pd = new PrintDocument();
pd.QueryPageSettings += new QueryPageSettingsEventHandler(pd_QueryPageSettings);
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
pd.Print();
In the QueryPageSettings event, we need to specify whether the current page should be printed landscape or portait. Additionally, a new document is loaded when all pages of the current document are already printed. Global page and document counters are used to track the printed pages:
void pd_QueryPageSettings(object sender, QueryPageSettingsEventArgs e)
{
if (pageIndex == 0)
{
if (documentIndex != lb_documents.Items.Count)
LoadDocument();
}
textControl1.Selection.Start =
textControl1.GetPages()[textControl1.Pages - pageIndex + 1].Start;
TXTextControl.SectionFormat sf = textControl1.Sections.GetItem().Format;
e.PageSettings.Landscape = sf.Landscape;
}
In the PrintPage event, we can use the Print method of TX Text Control to print a single page and to pass to the PrintPageEventArgs events of our attached PrintPage event. Additionally, we need to check whether to print more pages or not.
void pd_PrintPage(object sender, PrintPageEventArgs e)
{
textControl1.Print(textControl1.Pages - pageIndex + 1, e);
pageIndex--;
if (pageIndex != 0 || documentIndex != lb_documents.Items.Count)
e.HasMorePages = true;
else
e.HasMorePages = false;
}
You can download this sample in our source code library:
Related Posts
New Sample: Printing to Different Paper Trays
We just released a new sample for TX Text Control .NET for Windows Forms. This sample shows how to print specific pages of a document to different paper sources of the current printer. The sample…
Printing into a PrintPreview Control
TX Text Control .NET for Windows Forms implements a print preview dialog that can be easily opened using the PrintPreview method. Sometimes, it is necessary to customize the print preview dialog…
Printing Without the Status Dialog
The default print controller of .NET displays a status dialog that shows the status of the printing process like this: 'Page 5 of document' If you want to print without such a print status dialog,…
Landscape Printing with a PrintDocument
In one of the Print method's overload, TX Text Control .NET for Windows Forms allows a PrintDocument to be passed. The PrintDocument class is used to send output to a printer. In order to use…
Printing into a PrintDocument
TX Text Control .NET for Windows Forms's Print method introduces many advantages over the Print method of the ActiveX control. It enables you to print into a PrintDocument of the…