Skype:TextControlSupport
Orders:877-462-4772
TX Text Control - word processing components.
« »

Printing into a PrintDocument

Blogged by Björn Meyer on June 12, 2006 and tagged with Printing, .NET, Samples.

TX Text Control .NET's Print method introduces many advantages over the Print method of the ActiveX control. It enables you to print into a PrintDocument of the System.Drawing.Printing namespace. TX Text Control .NET's Print method uses the following settings of this object:

  • DocumentName
  • PrintController
  • PrinterSettings.FromPage
  • PrinterSettings.ToPage
  • PrinterSettings.Copies
  • PrinterSettings.Collate
  • PrinterSettings.PrinterName
  • PrinterSettings.PrintToFile
  • PrinterSettings.PrintRange
  • DefaultPageSettings.Color

If you would like to print one specific page of the document, not only FromPage and ToPage must be specified, but also the PrintRange property. The following code sample prints page 2 of TX Text Control and sets the current page size.

int m_curPage = 2;
PrintDocument myPrintDoc = new PrintDocument();
myPrintDoc.DefaultPageSettings.PaperSize = new PaperSize("default", thisTX.PageSize.Width, thisTX.PageSize.Height);
myPrintDoc.DefaultPageSettings.Margins = new Margins(thisTX.PageMargins.Left, thisTX.PageMargins.Right, _
thisTX.PageMargins.Top, thisTX.PageMargins.Bottom);
myPrintDoc.PrinterSettings.PrintRange = PrintRange.SomePages;
myPrintDoc.PrinterSettings.FromPage = m_curPage;
myPrintDoc.PrinterSettings.ToPage = m_curPage;
thisTX.Print(myPrintDoc);

As you can see, the PrintPage property must be specified with SomePages which indicates that the FromPage and ToPage is considered.

« Prev:How to build a context formatting bar
» Next:AJAX document viewer sample released

top

Top 10 Bestselling Product Award 2007Top 25 Publisher Product Award 2007Top 10 Bestselling Product Award 2007 in JapanTop 25 Bestselling Product Award 2006Top 25 Bestselling Publisher Award 2006Reader's Choice Award, dot.net magazin, 3rd place