spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column93


Print Templates, Part IV: User's Settings

Technical Lead
Thomson Reuters (Markets) LLC
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?


Printing the Pages

The function printNow() is doing most of the printing. First, we create a DEVICERECT collection:

var oDeviceRectCollection = document.all.tags("DEVICERECT");

The easier case is when the user clicks the Print w/o Prompt button in the Microsoft printing application. The dialogArguments' _IE_PrintType property should be "NoPrompt" in this case. We print all document pages when we don't allow a dialog box. The last page is determined by the DEVICERECT collection's length:

if (dialogArguments.__IE_PrintType == "NoPrompt" ||
        printer.selectedPages == false) {
  startPage = 1;
  endPage = oDeviceRectCollection.length;
}

The next question to ask is whether the user wants to print the current page only. In this case, we don't need to check anything more:

if (printer.currentPage == true) {
}

The case we are left with is the one in which the user selects the first and last page for printing. We take the user's selections from the templatePrinter element:

startPage = printer.pageFrom;
endPage = printer.pageTo;

And now comes a few consistency checks. First, we check if the start page is higher than the end page:

if (startPage > endPage) {
  alert("Error: Start page greater than end page");
  return;
}

We then check that the start page is withing the document boundaries:


if (startPage > oDeviceRectCollection.length) {
  alert("Error: Start page greater than number of
    pages in print job.");
  return;
}

Similarly, we check that the end page is within bounds. We set it to the last page if not:

if (endPage > oDeviceRectCollection.length) {
  alert("Warning: End page greater than number of pages in print job.
    Continuing Print Job.");
  endPage = oDeviceRectCollection.length;
}

We print the document in three steps. First, we call the templatePrinter's startDoc() method:

printer.startDoc("Printing from template6.htm");

We then loop over requested pages and call the printPage() function:

for (i = startPage - 1; i < endPage; i++) {
  printer.printPage(oDeviceRectCollection[i]);
}

We end the print job by the stopDoc() method:

printer.stopDoc();

Next: Template6's Code Listing


http://www.internet.com

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: September 24, 2001
Revised: September 24, 2001

URL: http://www.webreference.com/js/column93/6.html