Solved

How change papersize programmatically?

Posted on 1997-09-15
3
160 Views
Last Modified: 2010-04-04
Hi!

   I'm developing a database-application, in which I wanna make printouts on any papersize supported by the printer. My question is this:

   The user of the application has told the program that he/she wants a report written on portait-orientated A4-sized paper (210 * 297 mm). How do I change the printer's papersize programmatically, if it's not set to the requested size? I don't want to tell the user to open up the "Printer Setup" dialog,
   I wanna do it totally automatic. I can solve the orientation bit, but how do I change the papersize?
   I'm using Delphi 2.0.


                  Thanks for your help!!

//Daniel Persson, Malmoe, Sweden
0
Comment
Question by:Dippen
  • 2
3 Comments
 

Author Comment

by:Dippen
ID: 1344987
Edited text of question
0
 
LVL 22

Accepted Solution

by:
pivar earned 200 total points
ID: 1344988
Hej Daniel,

This sample code should do the trick:

---------------------------------------------------
var
  pDevMode: PDeviceMode;
  devHandle: THandle;
  device,driver,port: Array[0..255] of AnsiChar;
begin
  Printer.GetPrinter(device,driver,port,devHandle);
  pDevMode := GlobalLock(devHandle);
  pDevMode.dmFields := pDevMode.dmFields or DM_PAPERSIZE;
  pDevMode.dmPaperSize := DMPAPER_A4;
  GlobalUnlock(devHandle);

  Printer.BeginDoc;
etc...
---------------------------------------------------
With this you should be able to change other things as well, the orientation for example. Look in the WIN32 help, item DEVMODE.

If you haven't used Printer before the first line: Printer.GetPrinter, you will get an AccessViolation error. I haven't solved this yet,  but since the printer object is initialized when you use it the first time, I suspect it has to do with the printer object not been initialized before GetPrinter is run. To get around this you only have to use Printer before this. For example, get the printer name. 'name := Printer.Printers[Printer.PrinterIndex]'.

This code uses the Printer-objects internal DEVMODE structure to change the items you want.

/pivar
0
 

Author Comment

by:Dippen
ID: 1344989
Thanks for your simple and perfectly working answer, pivar!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
IdTelnet1DataAvailable handler freezes the Application 4 64
Connection between libmysql.dll and MySQL Versions 7 87
Help on project with Soap 10 48
Delphi inherited method 6 63
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now