Sign in to follow this  
Followers 0
jguinch

Set Internet Explorer printing margins to minimum size

1 post in this topic

#1 ·  Posted (edited)

Because there is no GPO/GPP to set the printing margins to the minimum size in Internet Explorer, I was searching a way to achieve it with a script. Well, not easy...

An easy way to set the margins to there minimum size is to set margin values to 0 from the Page setup window in Internet Explorer. When you re-open the Page setup window, the margins are set to there minimum sizes. It's because the minimum margins are based on the default printer's capabilities. When we set the margins values in the Page setup window, Internet Explorer checks if each value can me supported by the default printer, else it uses the minimum size from the printer capabilities.

We could think that we have just to set the registry margins values to 0 but no, the Page setup window keeps 0 for each margin, so it doesn't work.

Here is the code I made to define the margins, without using the Page setup from Internet Explorer :

#Include <WinAPI.au3>
#include <WinAPISys.au3>

Global Const $PHYSICALOFFSETX = 112
Global Const $PHYSICALOFFSETY = 113
Global Const $LOGPIXELSX = 88
Global Const $LOGPIXELSY = 90
Global Const $PHYSICALWIDTH = 110
Global Const $PHYSICALHEIGHT = 111
Global Const $HORZRES = 8
Global Const $VERTRES = 10

Global $aRes = DllCall("GDI32.dll", "hwnd", "CreateDC", "str", "winspool", "str", _WinAPI_GetDefaultPrinter(), "long", 0, "long", 0)
If @error Then Exit
Global $hPrintDc = $aRes[0]

Global $iLOGPIXELSX = _WinAPI_GetDeviceCaps($hPrintDc, $LOGPIXELSX)
Global $iLOGPIXELSY = _WinAPI_GetDeviceCaps($hPrintDc, $LOGPIXELSY)
Global $iPHYSICALWIDTH = _WinAPI_GetDeviceCaps($hPrintDc, $PHYSICALWIDTH)
Global $iPHYSICALHEIGHT = _WinAPI_GetDeviceCaps($hPrintDc, $PHYSICALHEIGHT)
Global $iHORZRES = _WinAPI_GetDeviceCaps($hPrintDc, $HORZRES)
Global $iVERTRES = _WinAPI_GetDeviceCaps($hPrintDc, $VERTRES)
Global $iPHYSICALOFFSETX = _WinAPI_GetDeviceCaps($hPrintDc, $PHYSICALOFFSETX)
Global $iPHYSICALOFFSETY = _WinAPI_GetDeviceCaps($hPrintDc, $PHYSICALOFFSETY)
Global $iMarginsLeft = $iPHYSICALOFFSETX / $iLOGPIXELSX
Global $iMarginsTop = $iPHYSICALOFFSETY / $iLOGPIXELSY
Global $iMarginsBottom = (($iPHYSICALHEIGHT - $iVERTRES) / $iLOGPIXELSY) - ($iPHYSICALOFFSETY / $iLOGPIXELSY)
Global $iMarginsRight =  (($iPHYSICALWIDTH - $iHORZRES) / $iLOGPIXELSX) - ($iPHYSICALOFFSETX / $iLOGPIXELSX)

RegWrite("HKCU\Software\Microsoft\Internet Explorer\PageSetup", "margin_bottom", "REG_SZ", $iMarginsBottom)
RegWrite("HKCU\Software\Microsoft\Internet Explorer\PageSetup", "margin_left", "REG_SZ", $iMarginsLeft)
RegWrite("HKCU\Software\Microsoft\Internet Explorer\PageSetup", "margin_right", "REG_SZ", $iMarginsRight)
RegWrite("HKCU\Software\Microsoft\Internet Explorer\PageSetup", "margin_top", "REG_SZ", $iMarginsTop)

The code was adapted from here : http://www.swissdelphicenter.ch/en/printcode.php?id=1039

I hope it will be useful for someone

 

 

Edited by jguinch

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • ur
      By ur
      For the below form, I am able to automate using below code for textboxes.

      #include <IE.au3> Local $oIE = _IEAttach("http://localhost:18170/MartAdmin/", "url") _IELoadWait($oIE) $Search = _IEGetObjById($oIE,"x-auto-16-input") _IEPropertySet($Search, 'innerText','Uday KIran') $Search = _IEGetObjById($oIE,"x-auto-18-input") _IEPropertySet($Search, 'innerText','Uday KIran') But for the Login button, there is no id or name.
      The html code when I click on Inspect element in browser, shown below.
      <button tabindex="0" class="x-btn-text" style="width: 64px; position: relative;" type="button">Log In</button> Please let me know how to click this.?
       
    • Arlen
      By Arlen
      I'm doing a script to login and check my grades for college and some other useful things. But how can I check if i'm already logged in.
      What I have tried is to _IEDocReadHTML and then try to read the string with my username or anything that indicates I am logged. But it never returns the actually real html that I am seeing on my browser. It only returned a logged out html version. Anyway I can find out when I am logged or not. Thanks.
    • Hanukka
      By Hanukka
      Hi guys, 
      I was trying to automate a webpage after getting input from excel. The script worked fine for like 5 iterations but then stopped all of a sudden, I dont have the exact error msg now, but it was pointing to this in the IE UDF:-
      Return SetError($_IESTATUS_Success, $oTemp.GetElementsByTagName($sTagName).length,
      When i looked up the forum there was a similar question which said that I have to fix KB 3008923 update by uninstalling it, but I am unable to do that. 
      here is the link for download:- ( i guess )
      https://support.microsoft.com/en-us/help/3024777/error-0x800706f7-occurs-after-you-install-kb-3004394-and-then-run-windows-update-in-windows-7-and-windows-server-2008-r2
      Does anybody know the proper steps to solve this??
      Plus I wont be able to send the code here because of privacy policy n all by the company.
      Desperately looking for a reply.....
    • Hanukka
      By Hanukka
      Hello there,
      https://stackoverflow.com/questions/901712/how-to-check-whether-a-checkbox-is-checked-in-jquery
      I want to check the checkbox in the frame which pops up after choosing "run code snippet" option. ( Internet Explorer one would be prefered )
      Can you please please send the right code or some snippet here.. 
    • taylansan
      By taylansan
      Hi All, 
      I have a question related to _IEFormElementOptionSelect in the reference file. This drop down contains three items; Homepage, Midipage, Freepage. 
      How can I get the name of these items? If I use .innertext, in another drop down list contains spaces, so I cannot split them. 
      ; Open a browser with the form example, get reference to form, get reference ; to select element, cycle 10 times selecting options byValue, byText and byIndex #include <IE.au3> Local $oIE = _IE_Example("form") Local $oForm = _IEFormGetObjByName($oIE, "ExampleForm") Local $oSelect = _IEFormElementGetObjByName($oForm, "selectExample") _IEAction($oSelect, "focus") For $i = 1 To 10 _IEFormElementOptionSelect($oSelect, "Freepage", 1, "byText") Sleep(10) _IEFormElementOptionSelect($oSelect, "midipage.html", 1, "byValue") Sleep(10) _IEFormElementOptionSelect($oSelect, 0, 1, "byIndex") Sleep(10) Next _IEQuit($oIE) ;== Question == $aItems = StringSplit($oSelect.innerText, " ") For $i = 1 To $aItems[0] - 1 ConsoleWrite("Item-" & $i & ": " & $aItems[$i] & @CRLF) Next