spacer

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

home / experts / javascript / column93


Print Templates, Part IV: User's Settings

Data Center Architect
The Computer Merchant, Ltd
US-MA-chelsea

Justtechjobs.com Post A Job | Post A Resume
Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs


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, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint


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