Page Sizes Cannot Be Determined Before Printing Begins
One of the Newton 2.x OS Q&As
Copyright © 1997 Newton, Inc. All Rights Reserved. Newton, Newton Technology, Newton Works, the Newton, Inc. logo, the Newton Technology logo, the Light Bulb logo and MessagePad are trademarks of Newton, Inc. and may be registered in the U.S.A. and other countries. Windows is a registered trademark of Microsoft Corp. All other trademarks and company names are the intellectual property of their respective owners.
For the most recent version of the Q&As on the World Wide Web, check the URL:
http://www.newton-inc.com/dev/techinfo/qa/qa.htm
If you've copied this file locally,
click here to go to the main Newton Q&A page.
This document was exported on 7/23/97.
NEW: Page Sizes Cannot Be Determined Before Printing Begins (7/10/97)
- Q: How can my application or print format determine the exact page size before the print job actually starts?
A: There is currently no supported API to do this. You cannot rely on a particular size for the actual printable area of the paper, nor the actual printable area as viewed by your print format. This is a limitation of the current Newton OS printing architecture.
The correct way for a print format to determine its size is for the print format to call :LocalBox()
in its viewSetupFormScript
, viewSetupChildrenScript
, or viewSetupDoneScript
. This is only accurate during the current print job to the printer or fax driver. You cannot determine this size during Print/Fax preview, nor during the print format's formatInitScript
, nor in your application's on-screen views.
The size of the print format is affected by many factors that can change before the print job begins. Factors include, but are not limited to, the printer driver, the printer/fax settings, and whether a fax cover page is selected in the Fax routing slip. (The least intuitive of these variables is the fax cover page, which also controls the fax header strip at the top of the page -- affecting the height of the printable area.)
A common question is whether the print format formatInitScript
can accurately determine the page height. This special format method was designed to allow time-intensive code to execute before the print job begins. For instance, fax timeouts might be less likely if some data were processed before fax connection. However, there is no supported API to find the actual final printable area that you will have when the system opens the print format view and sends the viewSetupFormScript
message. Although you may be tempted to access undocumented slots which contain information about printer and page settings, this is both unsupported and results in unreliable bounds. (For instance, the undocumented fax cover page information affects the printable area but it's not stored in the printer nor page size structures.)
On a related note, there are user configurations slots called paperSize
and paperSizes
. You cannot use these to reliably determine the printable area, nor can you create new paperSizes
. See the Newton Programmer's Reference for more details.
You could hard-code a specific size of "main view" within your print format, but you do so at the risk of view clipping or other cosmetic problems if the actual printable area is too small in either dimension. For instance, you could determine a "lowest common denominator" page size for many printer/fax combinations, and then center a view of that size within the print format. You may waste some vertical/horizontal space if the page is larger and you still risk clipping the view if the printed page is smaller than expected. If you took this approach, you might consider registering multiple print formats that contained different page size/layout assumptions. We do not recommend hard-coding a specific page size, but it is appropriate for printing official forms whose size and design must be copied excactly.
We strongly recommend that most applications assume nothing about page size before printing occurs. During printing, get the page size by calling :LocalBox()
in the print format viewSetupFormScript
, viewSetupChildrenScript
, or viewSetupDoneScript
. (Or, use the print format pageHeight
and pageWidth
slots in viewSetupChildrenScript
or later.) Also, add new child views with appropriate center/full/right/relative justification to take advantage of varying page sizes. This will allow your application to work with any paper size, in any printer, and in any locale.