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:

  1. You can append the document to TX Text Control in order to create one large document.
  2. 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:

Batch printing: How to print documents in one print job