Print Templates, Part IV: User's Settings: Printing the Pages - Doc JavaScript
Print Templates, Part IV: User's Settings
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
We end the print job by the stopDoc()
method:
printer.stopDoc();
Next: Template6's Code Listing
Produced by Yehuda Shiran and Tomer Shiran
All Rights Reserved. Legal Notices.
Created: September 24, 2001
Revised: September 24, 2001
URL: https://www.webreference.com/js/column93/6.html