Solved

How change papersize programmatically?

Posted on 1997-09-15
3
162 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

763 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