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

Comments

If you would like to comment on this blog entry, please post a comment.

Posted by Igor on Thursday, January 18, 2007 at 22:02:14:

Hi, a try used your code, but it isn't function, I need to print some pages too. Do you know if exist another way to do this?
thanks
External verification page for ISO 9000:2000 certificate
ISO 9001:2000
certified