Solved

How change papersize programmatically?

Posted on 1997-09-15
3
159 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
Comment Utility
Edited text of question
0
 
LVL 22

Accepted Solution

by:
pivar earned 200 total points
Comment Utility
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
Comment Utility
Thanks for your simple and perfectly working answer, pivar!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

771 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

10 Experts available now in Live!

Get 1:1 Help Now