Board index » delphi » Printing problem: user changes printer resolution , fonts chang

Printing problem: user changes printer resolution , fonts chang

I have tried EVERYTHING I can think of and searched high and low for the answer.
The problem is that I have designed a print routine that prints beautifully at
300 dpi, but if user changes print resolution to 150dpi or 75dpi (haven't tried
at higher resolutions) windows substitutes a different font and the report is
almost unreadable. The text in question is printed with
Printer.Canvas.Textout(ect...) or Printer.Canvas.TextRect(ect...) for column
aligned output. Even DrawText(ect...) windows API function does the same thing
although the documentation claims the font will _not_ be changed. It appears
the font is printing to large also, and I've tryed setting the font.size
smaller to account for the resolution change but the font is still substituted.
Using Delphi 1 on Win95. Anyone have a clue?

GetDeviceCaps(ect...) returns the printer capability-does anyone know how to
set resolution to 300dpi, if printer is capable, and override a user's setup?

Eternally grateful for any help...
Miles

 

Re:Printing problem: user changes printer resolution , fonts chang


Quote
MJN...@ix.netcom.com wrote:
> I have tried EVERYTHING I can think of and searched high and low for the answer.
> The problem is that I have designed a print routine that prints beautifully at
> 300 dpi, but if user changes print resolution to 150dpi or 75dpi (haven't tried
> at higher resolutions) windows substitutes a different font and the report is
> almost unreadable. The text in question is printed with
> Printer.Canvas.Textout(ect...) or Printer.Canvas.TextRect(ect...) for column
> aligned output. Even DrawText(ect...) windows API function does the same thing
> although the documentation claims the font will _not_ be changed. It appears
> the font is printing to large also, and I've tryed setting the font.size
> smaller to account for the resolution change but the font is still substituted.
> Using Delphi 1 on Win95. Anyone have a clue?

> GetDeviceCaps(ect...) returns the printer capability-does anyone know how to
> set resolution to 300dpi, if printer is capable, and override a user's setup?

This will be an issue for me too, very soon, so I already made some
search on that. Following refrences are in my Win32 online-help, so I
suppose you just need a hint in the right direction. At a very low
level, I found that we should be able to change dmPrintQuality in the
DEVMODE structure pointed to by the PRINTER_INFO_2 structure which we
will get when using GetPrinter and send back with SetPrinter.

As you are further than I am, I didn't test that out yet, but I'd love
some feedback if it works...

Good luck!

Re:Printing problem: user changes printer resolution , fonts chang


Quote
> I have tried EVERYTHING I can think of and searched high and low for the answer.
> The problem is that I have designed a print routine that prints beautifully at
> 300 dpi, but if user changes print resolution to 150dpi or 75dpi (haven't tried
> at higher resolutions) windows substitutes a different font and the report is
> almost unreadable. The text in question is printed with
> Printer.Canvas.Textout(ect...) or Printer.Canvas.TextRect(ect...) for column
 <SNIP>
> GetDeviceCaps(ect...) returns the printer capability-does anyone know how to
> set resolution to 300dpi, if printer is capable, and override a user's setup?

I had this problem as well.  Some users were going to print reports to a
networked dot-matrix printer (~150dpi), and others would be printing to
300dpi and 600dpi lasers.  The way I got around the problem was to
create a routine that determined the target printer resolution before
the print job was sent.  Based on that, I determined a DPI "factor" that
I use throughout the job.  If they decide to switch printers from one
report to the other, I wanted to be covered instead of assuming they
would use the same printer for each program run.  Here is my sample
code:

var
   PrinterLine,
   PrinterMargin,
   PrinterLineAdvance,
   VertPixelsPerInch,
   HorzPixelsPerInch,
   PrinterTotalWidth,
   PrinterTab : integer;

 {find printer DPI and adjust printout sizes}
     VertPixelsPerInch := GetDeviceCaps(Printer.Handle, LogPixelsY);
     HorzPixelsPerInch := GetDeviceCaps(Printer.Handle, LogPixelsX);
     PrinterMargin := round(HorzPixelsPerInch * 0.5);    {Half-inch
margin
        based on printer driver}
     PrinterLineAdvance := round(VertPixelsPerInch / 6);  {Four lines
per inch}
     PrinterTotalWidth  := round(7.2 * HorzPixelsPerInch); {width of
page in pixels}
     PrinterTab := round(HorzPixelsPerInch / 4);  {quarter-inch tabs}

This code allows you to use Print.Canvas.TextOut with a margin value
(PrinterMargin), as well as a "Tab" value for printing columned text
(without using Reportsmith!).  Contact me if you have further
questions...

Bill

Re:Printing problem: user changes printer resolution , fonts chang


Quote
> I have tried EVERYTHING I can think of and searched high and low for the
answer.
> The problem is that I have designed a print routine that prints
beautifully at
> 300 dpi, but if user changes print resolution to 150dpi or 75dpi
(haven't tried
> at higher resolutions) windows substitutes a different font and the
report is
> almost unreadable. The text in question is printed with
> Printer.Canvas.Textout(ect...) or Printer.Canvas.TextRect(ect...) for

column

We had a problem like this also.  Someone posted the code below and it
helped us alot.  Apparently the pixelsperinch for the font used for the
canvas of the printer does not get set correctly (At least in D1).
Anyway, I run this after setting the font properties but before printing
and everything works great.

I hope it helps!

procedure SetPixelsPerInch;
{ensures that PixelsPerInch is set so that text print at the desired size}
var
   FontSize : integer;
begin
   FontSize := Printer.Canvas.Font.Size;
   Printer.Canvas.Font.PixelsPerInch := GetDeviceCaps(Printer.Handle,
LOGPIXELSY);
   Printer.Canvas.Font.Size := FontSize;
end;

Other Threads