Announcement

Collapse
No announcement yet.

Function: Modify IE Footer, Header, & Margin Info for Printing

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Function: Modify IE Footer, Header, & Margin Info for Printing

    These functions let you programatically change a users Internet Explorer printing options found under IE's File | page setup menu. Specifically it changes the header, footer, and margins. This is especially useful if you are using the Web.Print action in an AMS project to print a report or other formatted document.

    The CHANGEIESETTINGS accepts 6 arguments to manipulate the Header, Footer and 4 page margins.

    The RESTOREIESETTINGS restores the original user specified settings.


    Place this code into your Global Functions section

    Code:
    --***************************
    --  CHANGE FOOTER, HEADER, & MARGINS
    --***************************
    --Changes the Header, footer, & Margin info used when printing from IE
    function CHANGEIESETTINGS(Header, Footer, MarginTop, MarginBottom, MarginLeft, MarginRight)
    
    --Get Current Registry Key Values if they exist
    IEHeader = Registry.GetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "header", true);
    IEFooter = Registry.GetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "footer", true);
    IEMarginTop = Registry.GetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_top", true);
    IEMarginBottom = Registry.GetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_bottom", true);
    IEMarginLeft = Registry.GetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_left", true);
    IEMarginRight = Registry.GetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_right", true);
    
    --Set Values based on arguments of function
    Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "header", Header, REG_SZ);
    Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "footer", Footer, REG_SZ);
    Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_top", MarginTop, REG_SZ);
    Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_bottom", MarginBottom, REG_SZ);
    Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_left", MarginLeft, REG_SZ);
    Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_right", MarginRight, REG_SZ);
    end
    
    
    --***************************
    --Restore Header, Footer, & Margins
    --***************************
    function RESTOREIESETTINGS()
    
    --Restore User Header, footer, Margin values
    Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "header", IEHeader, REG_SZ);
    Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "footer", IEFooter, REG_SZ);
    Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_top", IEMarginTop, REG_SZ);
    Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_bottom", IEMarginBottom, REG_SZ);
    Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_left", IEMarginLeft, REG_SZ);
    Registry.SetValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Internet Explorer\\PageSetup", "margin_right", IEMarginRight, REG_SZ);
    end
    Here's an example funtion call to change the headers and set margins to .5 inches

    Code:
    -- Change header & footer to "My Custom Header/footer"  Change margins to .5 inch
    CHANGEIESETTINGS("My Custom Header", "My Custom Footer", "0.50", "0.50", "0.50", "0.50")
    Here's the function call to restore the original header, footer, & margins

    Code:
    --Restore User values for Header, Footer, & Margins
    RESTOREIESETTINGS()

  • #2
    That'll come in super handy for someone, I'm sure! Thanks for the contribution!
    New Release: Setup Factory 9.6 adds Windows 11 compatibility and support for hardware token OV/EV Code Signing certificates.

    Comment


    • #3
      Thank You!!!
      Never know what life is gonna throw at you. ZubTech

      Comment


      • #4
        Sweet! :yes :yes :yes :yes :yes :yes :yes :yes :yes :yes

        Comment


        • #5
          This is definitely one of the top 10 tips on this forum.

          KP is an animal!

          Comment


          • #6
            MSIE Header & Footer Macros

            When you use the function above to change the header and/or footer, you can insert these MSIE pre-defined macros.

            && = ampersand
            &b = right-justify
            &d = date (user short format)
            &D = date (user long format)
            &t = time (user preference)
            &T = time (military format)
            &p = page
            &P = number of pages
            &u = URL (or file path)
            &w = (window) title tag


            Also with the web browser control, you can put one on your page as a 1x1 pixel dot (in a corner). Then, you can use your own html templates to create, display, and print pages (like we commonly do with PHP).

            For example, design an HTML template (my_page_tpl.html) that has basic tags, but within the BODY you have this text: [REPLACE_THIS_CONTENT]. If you display this template in your browser, that's all you see. But, within AMS you use TextFile.ReadToString to open the document. Next, use String.Replace to change [REPLACE_THIS_CONTENT] to your dynamic runtime content. Finally, use TextFile.WriteFromString to create a presentation page (print or display) such as “my_page_final.html”.

            To me, this is the AMS way to print customized pages. I've lurked and learned here for a while. This is my first public tip; hope someone finds this useful.

            Comment


            • #7
              More on HTML Templates in AMS

              1. If you don't want to have the 1x1 pixel Web Browser Object, you can use File.Run to access the M$ Web Browser DLL directly. For example:

              Code:
              File.Run(_SystemFolder .. "\\rundll32.exe", _SystemFolder .. "\\mshtml.dll,PrintHTML \\"" .. _SourceFolder .. "\\AutoPlay\\HTML\\my_page_final.html" .. "\\"");
              2. If you do use this technique, you can still allow the end-user to choose their printer preference. Simply, include this HTML code at the end of your actual BODY tag in your HTML template:

              Code:
              onload="window.print();"
              3. If all you want to do is print an image (BMP, GIF, JPG, or PNG), with String.Replace just replace [REPLACE_THIS_CONTENT] with an HTML IMG reference to the absolute file path of the image that you want to print. The final HTML would contain something like this:

              Code:
              <img src="C:\MyProjectPath\AutoPlay\Images\this_image.jpg" border=0 />
              Last edited by CyberRBT; 03-24-2007, 07:59 PM.

              Comment


              • #8
                Good stuff, thanks for the insight :yes

                Comment

                Working...
                X
                😀
                🥰
                🤢
                😎
                😡
                👍
                👎