Print Templates, Part IV: User's Settings: Using User's Settings - Doc JavaScript | WebReference

Print Templates, Part IV: User's Settings: Using User's Settings - Doc JavaScript


Print Templates, Part IV: User's Settings

Using User's Settings

The main difference between template6.html and the other print templates we have presented in this series is that it uses the actual Page Setup and Print Dialog settings. All previous print templates used the STYLE definitions in .contentstyle, .masterstyle, .headerstyle, and .footerstyle. See them in Page 3.

The behavior templatePrinter has all the properties to define the content area, the master page, the header, and the footer. These properties reflect the values you enter in the Page Setup dialog box and the Print Dialog box. All dimensions are stored in templatePrinter as inches. The style object, on the other hand, expects dimensions to be in 1/100th of an inch. Therefore, you need to divide the templatePrinter's settings by 100 before storing them in the style object. You also need to append the "in" dimension to every numeric value.

Let's start with the master page's width and height:


oMasterStyleClass.style.width =
  printer.pageWidth/100 + "in";
oMasterStyleClass.style.height =
  printer.pageHeight/100 + "in";  

The margins of the content with respect to its container master page are set next:


oContentStyleClass.style.marginTop =
  printer.marginTop/100 + "in";
oContentStyleClass.style.marginLeft =
  printer.marginLeft/100 + "in";

The content width is computed by subtracting the marginLeft and marginRight values from the master page's pageWidth:

oContentStyleClass.style.width = (printer.pageWidth -
(printer.marginLeft + printer.marginRight))/100 + "in";

Similarly, the content height is computed by subtracting the marginTop and marginBottom from the master page's pageHeight:

oContentStyleClass.style.height = (printer.pageHeight -
(printer.marginTop + printer.marginBottom))/100 + "in";

The header's left position is set at the marginLeft value:


oHeaderStyleClass.style.left =
  printer.marginLeft/100 + "in";

While its top position is set at the unprintableTop value:


oHeaderStyleClass.style.top =
  printer.unprintableTop/100 + "in";

The header's width is set to the content width:


oHeaderStyleClass.style.width =
  oContentStyleClass.style.width;  

Similarly for the footer, its left position is set to marginLeft:


oFooterStyleClass.style.left =
  printer.marginLeft/100 + "in";

Its width is set to the content width:


oFooterStyleClass.style.width =
  oContentStyleClass.style.width;

And finally, its bottom position is set to the unprintableBottom value:


oFooterStyleClass.style.bottom =
  printer.unprintableBottom/100 + "in";

Next: How to assemble the pages on line

https://www.internet.com


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/4.html