Recent

Author Topic: setting printer resolution  (Read 10638 times)

dfspannie

  • New Member
  • *
  • Posts: 24
setting printer resolution
« on: December 06, 2011, 02:53:17 pm »
How do I set the printer resolution from inside a program ? ( not using  printersetupdialog )

thanks

M[a]nny

  • Full Member
  • ***
  • Posts: 130
  • Dreamer
Re: setting printer resolution
« Reply #1 on: December 06, 2011, 03:31:52 pm »
Explore unit Printers. There are many functions to use.
For example:
Code: [Select]
procedure SetXDPI(const AValue: Integer);
procedure SetYDPI(const AValue: Integer);
procedure SetPaperHeight(const AValue: Integer);
procedure SetPaperWidth(const AValue: Integer);

I also recommend to read this.
« Last Edit: December 06, 2011, 03:34:16 pm by M[a]nny »
Bad news: Time flies.
Good news: You are the pilot.

Don't try to be perfect, just be unique.

dfspannie

  • New Member
  • *
  • Posts: 24
Re: setting printer resolution
« Reply #2 on: December 06, 2011, 04:47:21 pm »
Thanks,  but I have already tried this.
I get     Error: identifier idents no member "setYDPI"
The same for setXDPI.

Maybe I'm not doing it right.

thanks again.

M[a]nny

  • Full Member
  • ***
  • Posts: 130
  • Dreamer
Re: setting printer resolution
« Reply #3 on: December 07, 2011, 08:54:43 am »
What Lazarus and FPC do you use?
Bad news: Time flies.
Good news: You are the pilot.

Don't try to be perfect, just be unique.

dfspannie

  • New Member
  • *
  • Posts: 24
Re: setting printer resolution
« Reply #4 on: December 07, 2011, 09:06:36 am »
Sorry, should have mentioned it earlier.

Lazarus 0.9.30
FPC 2.4.2
SVN 29749

Win 7, win vista, winXP - on different machines

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: setting printer resolution
« Reply #5 on: December 07, 2011, 01:42:41 pm »
XDPI,YDPI is a read only property for TPrinter. SetXDPI is in TPrinterCanvas and doesn't affect the resolution used by the printer.

On windows you'll need to use the winspool API to change the DEVMODE structure of the printer. If that is what you need I can share the code for doing that.

dfspannie

  • New Member
  • *
  • Posts: 24
Re: setting printer resolution
« Reply #6 on: December 07, 2011, 04:28:38 pm »
Yes please, thank you very much. The code will be wellcome.

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: setting printer resolution
« Reply #7 on: December 07, 2011, 04:45:00 pm »
Attached the unit printersettings.pas. To set the printer resolution call
Code: [Select]
SetPrinterSolution(PrinterName,iresolution);  For example to set the printer resolution of the default printer to 1200 just do
Code: [Select]
SetPrinterSolution(printer.PrinterName,1200); I have put it in a separate unit because:
- a lot of winspool types and functions are included
- it uses the windows unit and the unit printers has some conflicting definitions.

If you want to extend the unit to set other printer settings such as paper tray, duplex, etc. take a look at this page http://msdn.microsoft.com/en-us/library/windows/desktop/dd183565%28v=vs.85%29.aspx and change the DEVMODE structure accordingly.

Note that this changes the printer resolution for all applications, the same way as the printer settings dialog does. That is also the reason why a WM_DEVMODECHANGE is broadcast to all apps.

dfspannie

  • New Member
  • *
  • Posts: 24
Re: setting printer resolution
« Reply #8 on: December 07, 2011, 08:09:22 pm »
Thanks again.
There seems to be a problem with the download link though. When clicked, I get a blank  index.php page.
(using firefox)

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: setting printer resolution
« Reply #9 on: December 07, 2011, 08:16:51 pm »
I have seen other people complaining in other threads about getting an index.php also. A server or browser issue.
I just double checked and the download is OK.

dfspannie

  • New Member
  • *
  • Posts: 24
Re: setting printer resolution
« Reply #10 on: December 07, 2011, 08:23:16 pm »
 :) worked with Opera. Must be Firefox then.

dfspannie

  • New Member
  • *
  • Posts: 24
Re: setting printer resolution
« Reply #11 on: December 08, 2011, 11:42:30 am »
 I wrote a small program to test this.
It does not seem to work.
The XDPI/YDPI after SetPrinterSolution is called is the same as before. No change.
I tried it with different printers on different O/S 'es (XP, Vista, Win 7). No luck, though
the program reports that the change was made.

thanks again

code below.


procedure TForm1.Button2Click (Sender : TObject ) ;

var res : integer;
    result : boolean;

begin
     // get resolution before change

     labelededit1.Text:=inttostr(printer.XDPI);
     labelededit2.Text:=inttostr(printer.YDPI);



     label1.Caption:= '';

     // combobox is populated with list of printers
     // in the form's onshow event.
     // (combobox1.Items := printer.Printers;)

     if combobox1.Text = '' then
     begin
          showmessage('Pick - a - printer !!');
     end
        else   printer.SetPrinter(combobox1.Text);


     if edit1.Text = '' then showmessage('Enter resolution first !') else res := strtoint(edit1.Text);


     result := SetPrinterSolution(combobox1.text,res);


     if result = true then label1.Caption := 'Done'
     else label1.Caption := 'Not done';


     // get resolution after change

     labelededit3.Text:=inttostr(printer.XDPI);
     labelededit4.Text:=inttostr(printer.YDPI);


end;
             

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: setting printer resolution
« Reply #12 on: December 08, 2011, 12:57:23 pm »
printer.XDPI returns the logical pixel resolution from the printer DC, not the physical printer resolution.

After calling SetPrinterSolution, check the printer resolution in the control panel and you'll that it has changed. You can also change the resolution in the printer settings dialog and verify that printer.XDPI hasn't changed.

maxides

  • Newbie
  • Posts: 1
Re: setting printer resolution
« Reply #13 on: December 18, 2011, 11:32:53 am »
There seems to be a problem with the download link though. When clicked, I get a blank  index.php page.
(using firefox)
Yes, this bug is present. But... you can bypass it!  ;-)
1. Right-click on attachment link and choose "Save as...".
2. FireFox save it as "index.php"
3. Rename locally saved file "index.php" to "printersettings.zip".
That was enought in my case.

 

TinyPortal © 2005-2018