Products Technologies Demo Docs Blog Support Company

Batch Printing: How to Print Documents in One Print Job

Batch printing multiple documents as a single print job using TX Text Control relies on a .NET PrintDocument with PrintPage and QueryPageSettings events. Each page is rendered individually via the Print method, with page and document counters controlling orientation and job continuation.

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:

  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

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Related Posts

.NETPrintingSample

New Sample: Printing to Different Paper Trays

A new TX Text Control .NET for Windows Forms sample demonstrates printing specific document pages to different paper sources on the current printer. The project includes a configurable dialog box…


.NETPrintingSample

Printing into a PrintPreview Control

TX Text Control .NET for Windows Forms provides a built-in PrintPreview method, but the standard .NET PrintPreviewDialog offers broader customization options. This sample shows how to use the…


.NETPrintingSample

Printing Without the Status Dialog

The default .NET print controller displays a progress status dialog during printing operations. Replacing PrintControllerWithStatusDialog with StandardPrintController from System.Drawing.Printing…


.NETPrintingSample

Landscape Printing with a PrintDocument

When printing with a PrintDocument object in TX Text Control .NET for Windows Forms, page orientation is not transferred automatically. This C# function creates a PrintDocument, compares page…


.NETPrintingSample

Printing into a PrintDocument

TX Text Control .NET for Windows Forms prints into a standard .NET PrintDocument object, giving full control over page size, margins, and printer settings. To print a single page, set PrintRange…

Share on this blog post on: