Landscape printing with a PrintDocument
Blogged by Björn Meyer on July 03, 2006 and tagged with Samples, .NET, Printing.
In one of the Print method's overload, TX Text Control .NET 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, 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, 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);
}





