Products Technologies Demo Docs Blog Support Company

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 width and height to set the Landscape property, and applies size and margin values.

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 PrintDocument of the System.Drawing.Printing namespace, it is necessary to specify page settings and page orientation programmatically.

In TX Text Control .NET for Windows Forms, the ratio of the page width to the page height indicates whether a document is of landscape or portrait orientation. However, this property is not passed to the PrintDocument object automatically.

The following function creates a new PrintDocument object and passes the appropriate values from the current instance of TX Text Control .NET for Windows Forms, including page orientation, page size and page margins:

private void PrintDocument(TXTextControl.TextControl tx)
{
    PrintDocument pd = new PrintDocument();

    if(tx.PageSize.Width > tx.PageSize.Height)
        pd.DefaultPageSettings.Landscape = true;
    else
        pd.DefaultPageSettings.Landscape = false;

    pd.DefaultPageSettings.PaperSize = new PaperSize("new size", tx.PageSize.Width, tx.PageSize.Height);
    pd.DefaultPageSettings.Margins = new Margins(tx.PageMargins.Left, tx.PageMargins.Right, tx.PageMargins.Top, tx.PageMargins.Bottom);

    tx.Print(pd);
}

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Related Posts

.NETPrintingSample

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…


.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

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: