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

    • Dent
      [SOLVED] How do I read this result?
      By Dent
      Hi,
      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
      [SOLVED] form not recognising input upon submit
      By Dent
      Hey,
      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 https://online.leedsbuildingsociety.co.uk/public/mortgages/quick_enquiry.do
      Here's the code:-
      Local $oIE = _IECreate("https://online.leedsbuildingsociety.co.uk/public/mortgages/quick_enquiry.do") 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.
    • Dent
      How do I click an image?
      By Dent
      How do I click the 'Calculate' image at the bottom of this page? https://www.platform.co.uk/webapp/WEBAPP.EXE?WSYD_EVENT=PW10kkfF
    • Dent
      Unpredictable results
      By Dent
      I'm having unpredictable results - rather than post all the code right away (as it's quite lengthy) I've attached an image of the code section in question and an image of the result I'm getting and an image of the result I'm expecting.
      As you'll see, box 1 and 2 under Source have the default 'Please select' whereas they should have 'Working Tax Credits' and 'Disability living allowance' in 1 and 2 respectively.
      Whilst watching the code run I can see the correct results are being selected but by the time the script finishes executing those boxes have changed back to default.
      Here's the site https://www.platform.co.uk/webapp/WEBAPP.EXE?WSYD_EVENT=PW10kkfF
      I should mention that if I add in a delay e.g. Sleep(500) then selection remains as expected - but I would rather not do this as it slows the script down.
      If $MonthlyUniversalTaxCreditIncomeOne > 0 Then $oSelect = _IEGetObjByName($oIE, "AP1AMT1") $oSelect.Value = ($MonthlyUniversalTaxCreditIncomeOne * 12) $oSelect = _IEGetObjByName($oIE, "OGICMB1A") _IEFormElementOptionSelect($oSelect, 8, 1, "byValue") Else EndIf If $MonthlyStateDisabilityIncomeOne > 0 Then $oSelect = _IEGetObjByName($oIE, "AP1AMT2") $oSelect.Value = ($MonthlyStateDisabilityIncomeOne * 12) $oSelect = _IEGetObjByName($oIE, "OGICMB1B") _IEFormElementOptionSelect($oSelect, 10, 1, "byValue") Else EndIf


    • Dent
      How to handle an OnQuit pop-up in IE
      By Dent
      I've written a program with the help of others on here (thank-you) that interacts with this website http://nationwide-intermediary.co.uk/calculators/aff_calc
      You will notice if you visit that website that when you try to navigate away or close the window/tab there is a pop-up that checks that you want to leave the site.
      Currently to handle this I simply
      Send("{ENTER}") After a short delay to allow time for the pop-up to appear. This works but isn't ideal as often this program will run without user attention to the computer and so if focus is taken away from IE when the {ENTER} is sent it will not get executed and IE will remain open.
      Is there a better way to handle this pop-up and close the browser?