IonicWind Software

IWBasic => General Questions => Topic started by: Brian on January 05, 2020, 12:49:59 pm

Title: Paper Size
Post by: Brian on January 05, 2020, 12:49:59 pm
Hello,

Could anyone show me how to interrogate the printer (or driver, I suppose) to return the size of paper currently in the printer, eg, Letter or A4? I think you could use a DEVMODE struct, but I will be honest, and say I don't know how to do it! I think Letter size would return 1, and A4 would be 15

Brian
Title: Re: Paper Size
Post by: h3kt0r on January 09, 2020, 08:30:57 am
I don't know if this may help (or not), but here is a library written in C and compiled with LCC.
More than 200 functions, documentation included and there's a working example written for PowerBAsic (i guess).

See attached zip archive.
Title: Re: Paper Size
Post by: Brian on January 09, 2020, 09:23:12 am
I will take a look at that, thank you

And AstroGrep looks very useful. I have just downloaded it now

Brian
Title: Re: Paper Size
Post by: Brian on January 09, 2020, 12:03:17 pm
Well, I made a start on the printer DLL. Then I got stuck on the CopyMemory call. Too complicated for my tiny brain! Any ideas?

Brian
Title: Re: Paper Size
Post by: LarryMc on January 09, 2020, 03:46:50 pm
I found this as part of gdi+ for the vb.NET version but I couldn't find anything like it in the version we're using. Maybe someone who knows more will have better luck.

https://www.dotnetheaven.com/article/gdi-papersize-class-in-vb.net

LarryMc

Title: Re: Paper Size
Post by: fasecero on January 09, 2020, 07:12:20 pm
I've been searching and it seems they always mention GetDeviceCaps, here it is an example, it looks easy to translate. No idea if is this what you are looking for.

Code Select
  ResolutionWidth& = GetDeviceCaps(Printer_hDC&, %LOGPIXELSX)
  ResolutionHeight& = GetDeviceCaps(Printer_hDC&, %LOGPIXELSY)

  pixelsLeftMargin& =GetDeviceCaps(Printer_hDC, %PHYSICALOFFSETX)
  pixelsTopMargin& =GetDeviceCaps(Printer_hDC, %PHYSICALOFFSETY)

  pixelsPrintWidth&  = GetDeviceCaps(Printer_hDC&, %HORZRES)
  pixelsPrintHeight& = GetDeviceCaps(Printer_hDC&, %VERTRES)

  pixelsPhysicalWidth& = GetDeviceCaps(Printer_hDC, %PHYSICALWIDTH)
  pixelsPhysicalHeight& = GetDeviceCaps(Printer_hDC, %PHYSICALHEIGHT)

  PhysicalPaperWidthInch@ = pixelsPhysicalWidth&/ResolutionWidth&
  PhysicalPaperHeightInch@ = pixelsPhysicalHeight&/ResolutionHeight&

  LeftMarginInch@ = pixelsLeftMargin&/ResolutionWidth&
  RightMarginInch@ = (pixelsPhysicalWidth& - pixelsPrintWidth& - pixelsLeftMargin&)/ResolutionWidth&
  TopMarginInch@ = pixelsTopMargin&/ResolutionHeight&
  BottomMarginInch@ = (pixelsPhysicalHeight& - pixelsPrintHeight& - pixelsTopMargin&)/ResolutionHeight&

https://forum.powerbasic.com/forum/user-to-user-discussions/programming/17995-getphyspagesize

PD: AstroGrep looks very useful, indeed. I still have to try Andy's program.
Title: Re: Paper Size
Post by: LarryMc on January 09, 2020, 09:11:09 pm
duh!

I've got some of those calcs in my print preview code in the IWB IDE!

Sorry :P

My brain hasn't been working too well here lately.
Title: Re: Paper Size
Post by: Andy on January 09, 2020, 10:20:29 pm
Hi every one.

This is how to do it easily, as I have said before, the registry holds many things in it.

Attached is the program.

All printers are in the registry key...

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers

Most printers (physical or software) have a sub folder called "DsDriver".

In the "DsDriver" sub key there is an entry called "printMediaReady".

"printMediaReady" has the default paper size value.

The command GETDEFAULTPRINTER looks at the key...

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows
In here the default printer is listed with some other things as well, on my PC the entry "Device" has this...

HP DJ 2130 series,winspool,Ne02:   (my printer - HP DJ 2130 series - before the first comma)

Andy.
:)
Title: Re: Paper Size
Post by: fasecero on January 10, 2020, 05:48:55 pm
Larry, it happens to me all the time. Also, I take a break from time to time, and when I come back I have no idea what I was doing ^^ Andy, I don't have a printer but I can spot printMediaReady as you stated inside 'Microsoft Print to PDF' with a value of "A4".
Title: Re: Paper Size
Post by: Andy on January 11, 2020, 05:30:08 am
Well spotted,

Yes even most "software" printers will have an entry.

Andy.
 :)