Word: Printout Scaling Issue (PrintZoomPaperHeight) from Delphi

D

Dan Kelly

I'm currently writing an in-house Document Register. One of the aims is to
allow users to print selected documents directly from the Register.

To make things easy, the printer is set once, and documents are scaled to
the appropriate paper size for that printer.

All well and good except that Word is giving me grief when using the full
form of WordApplication.PrintOut.

In order to scale the document being set I am setting PrintZoomPaperWidth
and PrintZoomPaperHeight to the appropriate sizes, however the first call
seems to be ignored.

For example: From a freshly run application (no instance of Winword.exe) in
the background I open the document to be printed using:

WordApp.Documents.Open(Filename, EmptyParam, ....)

I then set various settings as OleVariants, including:

PrintZoomPaperWidth := Printer.PageWidth * 2.48;
PrintZoomPaperHeight := Printer.PageHeight * 2.48;

And call:

WordApp.PrintOut(Background, Append, ... PrintZoomPaperWidth,
PrintZoomPaperHeight);

If I call the above with the default printer set to A4 paper, with an A3
document defined the printer asks for A3 printer, and prints only a portion
of the sent document.

However when I call the procedure a second time (with Winword.exe still
connected) the file is printed properly scaled to A4.

Completely repeatable - if Word is open, the settings are obeyed, if not,
the first print is at actual size, rather than scaled.
Any suggestions?
 
D

Doug Robbins - Word MVP

I assume that

Printer.PageWidth

is a Delphi function because in Word, .PageWidth is an attribute of the
PageSetup Object

It also seems probable that you may not be making correct use of the
PrintZoomPaperWidth and PrintZoomPaperHeight attributes.

PrintZoomPaperWidth Optional Variant The width to which you want Word
to scale printed pages, in twips (20 twips = 1 point; 72 points = 1 inch).
PrintZoomPaperHeight Optional Variant The height to which you want
Word to scale printed pages, in twips (20 twips = 1 point; 72 points = 1
inch).


I believe that if you want to print out on A4 paper, you should use

ActiveDocument.PrintOut _
PrintZoomPaperWidth:=11906, _
PrintZoomPaperHeight:=16838

11906 and 16838 being the size of A4 paper in twips
--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
D

Dan Kelly

Doug,

THanks for the reply - it doesn't *directly* fix the problem, but does
provide some information that I was looking for.

Printer.PageWidth is, as you thought, the page size from Delphi. In this
case in pixels - the 2.8 was the factor that I had managed to calculate to go
from Printer paper size to Word Paper size.

With the information you have given me about the twips I can adjust my
program to scale more accurately.

However the issue is that for the **first** run of the procedure Word
ignores the PrintZoomPaperWidth / Height settings. Even if I substitute the
A4 values into the application it still asks for A3 paper the first time
around.
 
D

Doug Robbins - Word MVP

I suspect that Word might be getting confused by your using variants such as
PrintZoomPaperWidth that have the same name as attributes of the PrintOut
command.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
D

Dan Kelly

Doug Robbins - Word MVP said:
I suspect that Word might be getting confused by your using variants such as
PrintZoomPaperWidth that have the same name as attributes of the PrintOut
command.

The Delphi command WordApplication.PrintOut() direcly access the PrintOut
command so naming the variables passed to in with the same names as what it
requires shouldn't be a problem.

Anyway, I've found a solution, which is to set WordApplication.PrintPreview
equal to True before calling the PrintOut command with the appropriate
settings.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top