[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

How change papersize programmatically?

Posted on 1997-09-15
3
Medium Priority
?
171 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 800 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

650 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