Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing Issues 1

Status
Not open for further replies.

Stretchwickster

Programmer
Apr 30, 2001
1,746
GB
Hi everyone,

I'm experiencing inconsistencies when trying to print charts from my application (written in Delphi 6 Pro) to different printers - margins move about, axis captions cover axis labels, some series don't print at all. Generally, there's lots of little quirks - what works on one printer doesn't on another.

I wondered if anyone else had experienced these problems and could suggest solutions? Is there a generic printer interface which would sort these issues out? I am working directly with the TPrinter canvas.

Your help would be much appreciated!

Clive [infinity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Are you drawing directly to the Printer.Canvas or are you using a charting add-in?
 
Yes and yes!

Let me explain...I am using a modified TChart to do all my plotting, then I'm saving the chart as a Windows Metafile (wmf), then drawing the metafile onto the canvas using TCanvas.Draw.

Clive [infinity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Your problem may be in printing a graphical file (wmf) that is structured with a fixed resolution (the screen) to a canvas with a variable resolution (the printers). If this is the issue, then what you need to do is convert the resolution of the graphic to appear in the proper location and dimensions of the target printer.

For example, if the dimensions of the graphic (in pixels) are 100 x 100 square, then on the screen it looks like a square because the horizontal and vertical pixels-per-inch of the screen are equal.

But if you send this to a printer with Printer.Canvas.Draw, it will look condensed on printers where the horizontal and vertical pixels-per-inch are different. To compensate for this, use the following functions to determine the logical pixels-per-inch of the target printer:

PrnPixelsY := GetDeviceCaps(Printer.Handle, LOGPIXELSY);
PrnPixelsX := GetDeviceCaps(Printer.Handle, LOGPIXELSX);

Now before you draw the graphic onto the printer's canvas, use the PrnPixels* variables to create a rectangle on the printer's canvas, hard-coding either the width or the height of the image to fit the printed output space. In this example, I've chosen to hard-code the width to fit in six inches on the printed page:

Rect.Top := 0;
Rect.Left := 0;
Rect.Right := Rect.Left + Trunc(PrnPixelsX * 6);

Then calculate the appropriate height for a fixed-ratio canvas:

VarHeight := MulDiv(Rect.Right - Rect.Left, WMF.Width, WMF.Height);

And adjust, if necessary for a variable-ratio canvas:

if (PrnPixelsX <> PrnPixelsY) then
VarHeight := Trunc(VarHeight * (PrnPixelsX / PrnPixelsY));

Rect.Bottom := Rect.Top + VarHeight;

Now, when you draw the graphic onto the printer canvas, use StretchDraw instead of Draw.

StretchDraw(Rect, WMF);

Also, you mentioned problems with different margins. You can use the PrnPixes* variables to calculate exact "inch-measured" margins as well, but you also need to account for differences in the physical offsets (unprintable areas) of individual printers. The following functions will help with that:

PrnOffsetTop := GetDeviceCaps(Printer.Handle, PHYSICALOFFSETY);
PrnOffsetLeft := GetDeviceCaps(Printer.Handle, PHYSICALOFFSETX);

Hope this helps.
 
That's very helpful - thank you!

Clive [infinity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top