August 06, 2020, 07:21:03 am

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Paper Size

Started by Brian, January 05, 2020, 12:49:59 pm

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Brian

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

h3kt0r

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.

Brian

I will take a look at that, thank you

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

Brian

Brian

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

LarryMc

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

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

fasecero

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.

LarryMc

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.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Andy

January 09, 2020, 10:20:29 pm #7 Last Edit: January 09, 2020, 10:45:29 pm by Andy
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.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

fasecero

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".

Andy

Well spotted,

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

Andy.
 :)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.