Sign in to follow this  
Followers 0

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 $iHORZRES = _WinAPI_GetDeviceCaps($hPrintDc, $HORZRES)
Global $iVERTRES = _WinAPI_GetDeviceCaps($hPrintDc, $VERTRES)

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 :

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

    • 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 )
      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,
      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  
    • Dent
      By Dent
      I've written a script to automate the logging in to a website and the generation of results as shown in Capture1.JPG
      You'll see the number of results is displayed at the top, 12 in this case. What I can't work out is how to read that number into a variable.
      The section of code from the site is displayed in Capture2.JPG
      The only way I can think is to read the whole page with _IEBodyReadText($oIE) then use StringInStr to find it, however the result may be 1, 2 or 3 digits depending on the number of results so I'm not sure how that would be coded.
      Any help greatly appreciated.

    • Dent
      By Dent
      So I've written this code which successfully populates a form but when 'Calculate' is clicked it says that the loan amount & purchase price need to be entered; which of course they have been. Any idea why?
      Here's the form
      Here's the code:-
      Local $oIE = _IECreate("") If Not IsObj($oIE) Then Exit ConsoleWrite("Error in $oIE" & @CRLF) Local $oIE = _IEAttach("Leeds Building Society - Borrowing Calculator") _IELoadWait($oIE) $oSelect = _IEGetObjByName($oIE, "termYears") $oSelect.Value = $MtgTermYrs $oSelect = _IEGetObjByName($oIE, "termMonths") $oSelect.Value = $MtgTermMths $oSelect = _IEGetObjByName($oIE, "adults17Over") $oSelect.Value = ($NumOfApplicants + $OtherAdultOccupants) Local $TotalDependents = ($Deps10To5 + $Deps16To11 + $Deps112To17 + $Deps20To5 + $Deps26To11 + $Deps212To17) If $TotalDependents > 0 Then $oSelect = _IEGetObjByName($oIE, "childrenUnder17") $oSelect.Value = $TotalDependents Else EndIf $Blah2 = ($MonthlyPensionIncomeOne + $MonthlyPensionCreditIncomeOne + $MonthlyInvestmentIncomeOne) $Blah2 = $Blah2 * 12 $oSelect = _IEGetObjByName($oIE, "applicantOneGrossIncome") $oSelect.Value = ($SalaryOne + $Blah2 + $SalaryPlusDividendsLatestYrOne) $oSelect = _IEGetObjByName($oIE, "applicantOneCommission") $Blah1 = (($BonusOne + $OvertimeOne + $CommissionOne) + ($MonthlyMaintenanceIncomeOne * 12)) $oSelect.Value = $Blah1 $oSelect = _IEGetObjByName($oIE, "applicantOneOvertimeOrBonus") $oSelect.Value = ($MonthlyUniversalTaxCreditIncomeOne * 12) $Blah2 = ($MonthlyPensionIncomeTwo + $MonthlyPensionCreditIncomeTwo + $MonthlyInvestmentIncomeTwo) $Blah2 = $Blah2 * 12 $oSelect = _IEGetObjByName($oIE, "applicantTwoGrossIncome") $oSelect.Value = ($SalaryTwo + $Blah2 + $SalaryPlusDividendsLatestYrTwo) $oSelect = _IEGetObjByName($oIE, "applicantTwoCommission") $Blah1 = (($BonusTwo + $OvertimeTwo + $CommissionTwo) + ($MonthlyMaintenanceIncomeTwo * 12)) $oSelect.Value = $Blah1 $oSelect = _IEGetObjByName($oIE, "applicantTwoOvertimeOrBonus") $oSelect.Value = ($MonthlyUniversalTaxCreditIncomeTwo * 12) $oSelect = _IEGetObjByName($oIE, "applicantOneLastYearProfit") $oSelect.Value = ($NetPreTaxProfitLatestYrOne + $ShareOfNetPreTaxProfitLatestYrOne) $oSelect = _IEGetObjByName($oIE, "applicantOneYear2Profit") $oSelect.Value = ($NetPreTaxProfitPrevYrOne + $ShareOfNetPreTaxProfitPrevYrOne) $oSelect = _IEGetObjByName($oIE, "applicantTwoLastYearProfit") $oSelect.Value = ($NetPreTaxProfitLatestYrTwo + $ShareOfNetPreTaxProfitLatestYrTwo) $oSelect = _IEGetObjByName($oIE, "applicantTwoYear2Profit") $oSelect.Value = ($NetPreTaxProfitPrevYrTwo + $ShareOfNetPreTaxProfitPrevYrTwo) $PropertyValue = _IEGetObjByName($oIE, "purchasePriceValuation") $PropertyValue.Value = $PP $MortgageRequired = _IEGetObjByName($oIE, "repaymentAmount") $MortgageRequired.Value = $MtgAmt $oSelect = _IEGetObjByName($oIE, "interestOnlyAmount") $oSelect.Value = 0 $Button = _IEGetObjByName($oIE, "calculateBtn.value") _IEAction($Button, "click") _IELoadWait($oIE) Exit Obviously I've got values stored in all the variables so I haven't posted all that code.