[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

How can I set a printer's papersize?

Posted on 2000-01-21
15
Medium Priority
?
382 Views
Last Modified: 2010-04-04
Hello,
  My program use many report,and it's papersize isn't same,How can I let the user Preview the report use the correspond papersize,for example:
  Set the Printer's papersize to A3;
  Report_PaperSize_A3.Preview;
  Set the Printer's PaperSize to A4;
  Report_PaperSize_A4.Preview;
  How can I relize it?
  thank u.
  zhijun_chen
 
0
Comment
Question by:zhijun_chen
  • 6
  • 4
  • 3
  • +2
15 Comments
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2376495
You can use the TQuickRep.PaperSize property:

eg:
QuickRep1.PaperSize := A4;

Set is to default to use the paper size currently loaded into the printer.

Cheers,

Raymond.
0
 
LVL 17

Expert Comment

by:inthe
ID: 2376511
you can change teh paper size and bin of printer like so:

unit Unit1;

interface

uses
  Windows, Messages,Printers, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
Device : array[0..255] of char;
Driver : array[0..255] of char;
Port   : array[0..255] of char;
hDMode : THandle;
PDMode : PDEVMODE;
begin
  Printer.GetPrinter(Device, Driver, Port, hDMode);
  if hDMode <> 0 then begin
    pDMode := GlobalLock(hDMode);
    if pDMode <> nil then begin

     {Set to legal}
      pDMode^.dmFields := pDMode^.dmFields or dm_PaperSize;
      pDMode^.dmPaperSize := DMPAPER_LEGAL;

     {Set to custom size}
      pDMode^.dmFields := pDMode^.dmFields or
                          DM_PAPERSIZE or
                          DM_PAPERWIDTH or
                          DM_PAPERLENGTH;
      pDMode^.dmPaperSize := DMPAPER_USER;
      pDMode^.dmPaperWidth := 100 {SomeValueInTenthsOfAMillimeter};
      pDMode^.dmPaperLength := 100 {SomeValueInTenthsOfAMillimeter};

     {Set the bin to use}
      pDMode^.dmFields := pDMode^.dmFields or DMBIN_MANUAL;
      pDMode^.dmDefaultSource := DMBIN_MANUAL;

      GlobalUnlock(hDMode);
   end;
  end;
  Printer.PrinterIndex := Printer.PrinterIndex;  Printer.BeginDoc;
Printer.Canvas.Font.Name := 'Courier New';
Printer.Canvas.Font.Size := 10;
Printer.Canvas.Font.Color:=ClRed;
Printer.Canvas.TextOut(100,100, 'Test 1');
  Printer.EndDoc;
end;
end.




Regards Barry
0
 

Author Comment

by:zhijun_chen
ID: 2376530
Thank u,all
  I want it work with QuickRep, How can do it?
  To Inthe:
  u perhas miss a word:
  Printer.SetPrinter(.....), it doesn't work.
  zhijun_chen
 
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
LVL 12

Expert Comment

by:rwilson032697
ID: 2376535
You will need to include printers in your uses clause.

Did you try my suggestion? This allows you to preview the report with any required paper size or the existing default paper size in the printer.

Cheers,

Raymond.
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2376570
You can set the papersize after you dropped a QuickReport on the form by right-clicking on it and selecting 'Report Settings'
0
 

Author Comment

by:zhijun_chen
ID: 2376615
Thank u,rwilson
  I have try your suggestion,But it doesn't work, the Quickreport's preview
window still is the default settings,for example, if I set the printer's papersize A4 as My printer's default(In  windows), the Quickreport's preview window still be A4.

  To Epsylon,
  I want to create the report at runtime.
  thank u,anyway.
  zhijun_chen
0
 
LVL 17

Expert Comment

by:inthe
ID: 2376622
did you try changing the printers papersize by code first then calling preview?
0
 

Author Comment

by:zhijun_chen
ID: 2376632
Hello inthe,
  I have try, but it doesn't work.
  I think the only solution is to change the windows's default printer settings at runtime, but how can do it?
  thank u.
0
 
LVL 17

Expert Comment

by:inthe
ID: 2376689
maybe you can use the quickreports settings sometyhing like:

//add to uses QRPRNTR,printers;
 {the orientation needs printers unit}


var
a: TPrinterSettings;
begin
a.PaperSize := A3;
a.Copies := 1;
a.Orientation := PoPortrait;
a.ApplySettings;

then call preview..
0
 
LVL 17

Expert Comment

by:inthe
ID: 2377400
did you try?
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2377718
This is based on I found in my PAQ collection, it may be of use:


What you need to do is to add a public property of your preview form of type TQuickRep like the following:

type
  TfrmPreview = class(TForm)
    QRPreview: TQRPreview;
    .....
  public
    { Public declarations }
    CurrentReport : TQuickRep;
  end;

In the OnPreview event of the report, you would use something like:

procedure TfrmMyReport.QuickRep1Preview(Sender: TObject);
begin
  with frmPreview do
  begin
    CurrentReport := QuickRep1;
    QRPreview.QRPrinter := TQRPrinter(Sender);
    Show;
  end
end;

That lets you reference the calling report through the preview's CurrentReport variable.  Then to change the papersize you would do something like the following:

  with CurrentReport.PrinterSettings do
  begin
{ Set the paper size }
    PaperSize := A3;
    ApplySettings; // Needed?
  end;
  QRPreview.qrprinter.Print;

Cheers,

Raymond.
0
 
LVL 17

Expert Comment

by:inthe
ID: 2387155
with regards to:

I think the only solution is to change the windows's default printer settings at runtime, but how can do it?


maybe use the PrintSetupDialog component
(i cant remember if it is standard component or i downloaded it)
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2387200
TPrinterSetupDialog is a standard component

Raymond.
0
 
LVL 1

Accepted Solution

by:
mscatena earned 400 total points
ID: 2394107
The following code can change the paper size:

procedure ChangePaperSize(PaperSize, Comp, Alt: integer);
var
  ADevice, ADriver, APort: array[0..255] of char;
  DeviceMode: THandle;
  M: PDevMode;
  s: string;
begin
  // Força use of Printer due to VCL bug. Do not remove
  S := Printer.Printers[Printer.PrinterIndex];
  // Get current data
  Printer.GetPrinter(ADevice, ADriver, APort, DeviceMode);
  M := GlobalLock(DeviceMode);
  try
    if M <> nil then
    begin
      // Change paper size
      M^.dmFields := DM_PAPERSIZE;
      if PaperSize = DMPAPER_USER then
        M^.dmFields := M^.dmFields or DM_PAPERLENGTH or DM_PAPERWIDTH;
      M^.dmPaperLength := Alt;
      M^.dmPaperWidth := Comp;
      M^.dmPaperSize := PaperSize;//
      // Update
      Printer.SetPrinter(ADevice, ADriver, APort, DeviceMode);
    end;
  finally
    GlobalUnlock(DeviceMode);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ChangePaperSize(DMPAPER_LETTER, 0, 0);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  ChangePaperSize(DMPAPER_USER, StrToInt(EdComp.Text), StrToInt(EdAlt.Text));
end;
0
 
LVL 17

Expert Comment

by:inthe
ID: 2394329
mscatena ,
please leave comments only,do you not see i already posted that before ?
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Suggested Courses

613 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question