Board index » delphi » Setting printer page size in printerdriver

Setting printer page size in printerdriver

Hi,

I have the following problem when printing in Delphi.
My printer output goes to a matrix printer with chained paper.

After the job is finished I use EndDoc wich sends a formfeed to the
printer. The problem is that the formfeed doesn't set the paper right.
It is short by approx. 2 lines. I know there's a Windows API call to set
this kind of information in the printer driver, but I don't know with
wich parameters to call this function.

I hope anyone can help me.

Greetings,     Paul

 

Re:Setting printer page size in printerdriver


Quote
Paul Hover <pho...@iaehv.nl> wrote:
>Hi,
>I have the following problem when printing in Delphi.
>My printer output goes to a matrix printer with chained paper.
>After the job is finished I use EndDoc wich sends a formfeed to the
>printer. The problem is that the formfeed doesn't set the paper right.
>It is short by approx. 2 lines. I know there's a Windows API call to set
>this kind of information in the printer driver, but I don't know with
>wich parameters to call this function.
>I hope anyone can help me.
>Greetings,     Paul

Here's some code I use to set orientation and paper size....
procedure TMain.PrintBtnClick(Sender: TObject);
var
        nCopies : Integer;
        ADevice, ADriver, APort: array [0..255] of Char;
        ADeviceMode: THandle;
        DevMode: PDevMode;
        Margins : TPoint;
Begin

        with Printer do
        begin
                GetPrinter (ADevice, ADriver, APort, ADeviceMode);
                SetPrinter (ADevice, ADriver, APort, 0); {force a Valid DevMode}
                GetPrinter (ADevice, ADriver, APort, ADeviceMode); {Now aDeviceMode is
valid}
                DevMode := GlobalLock(ADeviceMode);
                if NOT Assigned(DevMode) then ShowMessage('Can''t set printer.')
                else Begin
                        with DevMode^ do
                        begin
                                if CurLabel.Orientation = lrHorizontal then
                                Begin
                                        dmOrientation := DMORIENT_LANDSCAPE;
                                        dmPaperLength := MulDiv(CurLabel.Width, 254, TWIPS);
                                        dmPaperWidth := MulDiv(CurLabel.Height, 254, TWIPS);
                                End
                                else
                                Begin
                                        dmOrientation := DMORIENT_PORTRAIT;
                                        dmPaperLength := MulDiv(CurLabel.Height, 254, TWIPS);
                                        dmPaperWidth := MulDiv(CurLabel.Width, 254, TWIPS);
                                End;
                                dmFields := dmFields or DM_ORIENTATION;
                                dmPaperSize := DMPAPER_USER;
                                dmFields := dmFields or DM_PAPERSIZE or
                                  DM_PAPERLENGTH or DM_PAPERWIDTH;
                        end;
                        GlobalUnlock(ADeviceMode);
                        SetPrinter(ADevice, ADriver, APort, ADeviceMode);
                end;
        end;
        nCopies := 1;
        Printer.Title := 'LabelWriter Output';

        Printer.BeginDoc;       { Start Printing...}
        ....
        Printer.EndDoc
End;

Good luck!

David Block
CoStar Corporation

Re:Setting printer page size in printerdriver


Quote
On Fri, 02 Aug 1996 02:03:22 GMT, dbl...@vdn.com (David Block) wrote:

:Here's some code I use to set orientation and paper size....
:procedure TMain.PrintBtnClick(Sender: TObject);

I just saw your reply to another person's problem regarding orientation and
paper size setting for a printer driver.  I am not sure if this will help fix
the problem I am having, but if you don't mind, let me take a second to
describe it to you since you sound quite printer knowledgeable with Delphi.

I have an HP LaserJet 5L at home which is 600x600 dpi.  It is the default
printer.  I am working on an application for work in which I am using Turbo
Power's Async Pro 2.0 for its fax capabilities.

In my code, I determine the index for the fax printer driver and I then set
Printer.PrinterIndex equal to that value.  I then print my regular output to
this driver so that it will create the necessary fax file that Async Pro needs
to for faxing.  Anyway... when I have my HP set as the default printer and I
do it in this fashion the output that the user receives is stretched.
Meaning, an 11" page comes out 22", and the fonts are about twice as large as
normal.  However, when I set the fax printer driver as the default in windows
and then do the same output, it comes out perfectly.

So, this led me to a test... I called the PrinterSetupDialog instead of
setting Printer.PrinterIndex to see what would happen.  When I did this and
set the printer to the fax printer driver myself from the laserjet, it worked
perfectly.  This leads me to believe there is something wrong in the VCL for
the Printer object that isn't resetting it correctly when the PrinterIndex
property is changed in code.

Have you experienced anything like this?  Any suggestions?

-----
Kerry Sanders
http://www.mindspring.com/~ksanders/

Other Threads