?
Solved

Controlling IE Printer Orientation

Posted on 2005-05-02
12
Medium Priority
?
4,792 Views
Last Modified: 2007-12-19
I received no responses when this question was posted in VB so I am switching Topic Area to HTML.  My app uses the VB WebBrowser control embed in forms to display and customize HTML docs.   This app runs locally on the user's machine [clients salestaff download the program and customize their sales brochures OFF-LINE], which means I have access to the registry and the printer object from VB,  unlike most situations using Javascript from within the Browser window.  I believe the VB ocx for the WebBrowser is the same implemented by other languages.  Working strictly in XP.

So what I need is complete control over Printer orientation and printquality.   I can set the Margins for each doc using the MAIN/PAGESETUP registry settings,   and although I noticed Orientation as a subkey in some posts here on Experts-Exchange it is not present on my system and creating the subkey appears to have no effect.   I also have found changing settings for VB's printer object prior to invoking ExecWB OLECMDID_PAGESETUP or OLECMDID_PRINT has no effect on IE's orientation.

I experimented with css and setting the media to print but could not force the orientation to Landscape and get that to reflect in the browser's PAGE SETUP or PRINT PREVIEW.  And I do not believe style sheets can control print quality.

Also ran into a dead end trying to use OLECMDID_GETPRINTTEMPLATE,  if understand correctly Microsoft disabled this as a security problem,  I could not make any sense out of their documentation.   Also read somewhere you can only create Print Templates in C++,  I work strictly in VB.

I can change the default printer manually from the control panel and have the new orientation affect the browser, but I need to that programatically or in the registry prior to the user activating the print functions.

Any help?   Hope the question is fairly clear,  if not I can provide more details.

Thanks in advance.     dk
0
Comment
Question by:DKNY-2005
  • 7
  • 5
12 Comments
 
LVL 13

Expert Comment

by:softplus
ID: 13908874
Have you tried this? http://support.microsoft.com/?scid=kb%3Ben-us%3B198901&x=7&y=15 (SAMPLE: PageSet.exe Programmatically Changes Default Printer Orientation) - you'll just need to restore the settings afterwards.
Other than that I'm not aware of any possibilities - we ran into the same problems and decided to go with PDF-components instead of printing from the browser... Wouldn't it be great if the browsers supported everything they were supposed to? HTML would be a great possibility for printing reports.
John
0
 

Author Comment

by:DKNY-2005
ID: 13910212
John,

 I believe you provided a valid answer to the Orientation question,  but it also seems to have raised another issue.
I added a sub which changes orientation using the pageset.dll and that works fine,  as it truly does change the orientation of the default printer.   I can open the Printer Settings / Properties window from the control panel and see the changes as I apply them in my VB app.   Which I thought was the end of this issue as stated in my question,  until I ran the app.

Bearing in my I have a browser control embedded in my VB form,  when I load the form it correctly picks up the printer orientation for the default printer and the OLECMDID_PAGESETUP reflects that.   If while the form is loaded I change the property using pageset.dll the browser control does not detect the change.   If I restart the project or reload the form then the OLECMDID_PAGESETUP is in synch again.

I upped the point value for this question because the additional requirements of refreshing the browser control where not anticipated when I posted the question.

And finally,  orientation when I finally have it nailed down is half of the problem.   Any ideas on print quality?  I am going to test the VB printer properties,  possibly they will carry over to the execWB for the browsers but I am suspecting that is not the case.

Thank you for your excellent and quick response so far.

   DK
 
0
 
LVL 13

Expert Comment

by:softplus
ID: 13911708
Hi DK
Just a guess, maybe this will work: Try using PostMessage to signal a change in the WIN.INI, i.e.

PostMessage( HWND_BROADCAST, WM_WININICHANGE, Null, Null)

I use this when I change the default printer through the Win.INI-File. I'm not sure how IE would handle it, and in any case it might decide to ignore it if it thinks that the printer hasn't changed. But theoretically it should refresh the default printer... Maybe you could even just pass the WebBrowser's HWND instead of broadcasting it to all applications (save some CPU cycles if other Apps are listening).

Print Quality settings will probably need to be changed through the default printer settings as well. VB's printer object is separate from the WebBrowsers (as you noticed with the orientation). If you check the ORIENT.BAS file in the pageset-package you can see how they are doing it (accessing the devmode structure). In the Devmode-Structure you can set "just about" any printer setting required. (you can't set printer-specific settings which are generally dependant on driver details - but you could access these by using the printer dialogs and saving the settings the way you want; but then you can't use the same setting on other computers / with other users / with other printers / printerdriver-versions, etc.)

John
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:DKNY-2005
ID: 13911806
John,

  I just want to be clear on the procedure and then I will test it out immediately and award these points as the accepted solution.

  First of all I set a reference to pageset.dll in my project,  I am now thinking I should remove the reference and include the  printerControl.cls and Orient.bas which will allow more control for debugging or single step execution.   Am I correct in understanding is these two objects [Module and CLS] bundled up together as the dll?.   I am not concerned with my exe size,  so adding the module and cls should do exactly the same thing as referencing the .dll,  correct?

  Then I can copy the sub SetOrientation and rename it as SetPrintQuality,  make a change to the devmode value for printquality,  -1, -2 etc.,   and I should be done.   I'll try that now but if I missed something let me know.

  Thanks.             Danny
0
 
LVL 13

Expert Comment

by:softplus
ID: 13911916
Hi Danny
yes, I'd also include the two files directly - especially if you plan on making additional changes in them. It's the same thing if they are coming from the DLL or from "local" code.

yes on the second one as well, though you might need to play with the settings to see which parameter / value really causes which change (this can vary depending on the printer driver, but general results should be similar).

When debugging, just be sure not to stop execution during the changing of parameters in the orient.bas - you could easily leave memory "open" which could cause a crash in your VB IDE (+ be sure to save often :)).

Good luck :)
John
0
 
LVL 13

Expert Comment

by:softplus
ID: 13912066
Just a quick note: Apparently the printer control has been changed since IE 5.01, meaning it won't read the default printer from the WIN.INI but rather from the registry. I'm not sure if it would then still respond to the WM_WININICHANGE message at all. You can find the key at HKEY_CU\Software\Microsoft\Internet Explorer\PageSetup, the entry is called "Printer". *maybe* you can just change the name stored here and change it back after a short time to make IE think you've changed the printer so that it might reload the current settings.

You might also try something like (haven't tried it, just saw it somewhere):
 SendMessage(HWND_BROADCAST,WM_WININICHANGE,0,"Software\Microsoft\Internet Explorer")

Hmm, interesting questions :)
John
0
 

Author Comment

by:DKNY-2005
ID: 13912522
John,

  I now have my app changing the Default Printer values for Orientation, Print Quality and Copies.  That part is working fine.   One question,  the .bas module in the example uses the form handle as follows:

'Copy our changes to "the PUBLIC portion of the DevMode" into "the PRIVATE portion of the DevMode"
    Result = DocumentProperties(Form1.hwnd, PrinterHandle, PrinterName, ByVal pFullDevMode, ByVal pFullDevMode, DM_IN_BUFFER Or DM_OUT_BUFFER)

Any idea why they need a form handle for this?   I will be calling this module from a number of forms,  if the .hwnd is really required I guess I can just pass it the active form's handle...

Now,  I am going to see about your last comment and getting the browser control to respond to the default printer settings.   I am already accessing the PageSetup keys for the browser's margins,  so your idea about swapping the printer name in and out may work fine.   I'll let you know shortly.

This is the closest I have come to an ideal solution in a long time [week or so] of fighting with the whole concept.   When we are done I will try to wrap up an outline of the successful outcome for others seeking the same level of control.

 Danny


 
0
 
LVL 13

Accepted Solution

by:
softplus earned 2000 total points
ID: 13912675
The hwnd is only in case you are displaying a dialog (which you aren't) - you can probably safely set this to "0" if you don't want to pass the hwnd of a form you are using (which would be preferred).

One thing to keep in mind with all these "hacks" is that IE can change (and has changed), meaning the things you figure out that function now might not work in the next larger release of IE. This is a major pain - as you never know when your users are going to upgrade (and you can't force the WebBrowser control to continue working with the old version of IE). Keeping this in mind, you might still want to look for an alternative output method in the mid-term future.

One possibility would be to use a PDF-Control and send the generated PDF-files directly to the printer (i.e. retrieve the contents of "MakePdf.aspx?blabla" into a temp PDF-file and print that using whatever settings you want... oops same fight with the settings, just in Acrobat now... :o - but I think the Acrobat SDK is more long-term regarding printing :)).
John
0
 
LVL 13

Expert Comment

by:softplus
ID: 13912946
Thanks :) let us know if you run into anything new, it's always interesting!
John
0
 

Author Comment

by:DKNY-2005
ID: 13913015
John,

  In reply to your last post,  I am fine for now.   I have a captive audience,  my client's sales staff,  and if and when a new IE version comes around they will certainly pay me to update the controls in this module and any code changes.   So for now if it works for me it will work on the client's sales staff systems,  which is all I care about.

  I am going to stay away from the PDF's for now,  just another learning curve to master and I have no desire to do that.  I steered the client away from Acrobat because I was confident we could it all in HTML and 99% of the data is duplicated on their website in HTML, so why fight with another format.   The two big problems with the web data were personalizing forms, business cards, brochures etc for each sales rep from cookies,  and precise printer control,  and the exe now does both much better than possible from within a browser.

  So the way it stands now execWB responds to all settings to the default printer, including Orientation, PrintQuality and Copies.    I am setting and changing margins per user values on my forms by writing directly to the IE/Pagesettings registry keys.   All that works fine.

  My last detail is the execWB OLECMDID_PRINTPREVIEW does not respond to any orientation changes AFTER the control has been loaded,  although the Printer Settings dialog from within OLECMDID_PRINT does,  which is strange.   Curiously I do not have a "Printer" key in my registry under Internet Explorer/PrintSettings,   I may try to add one but I wonder why it's not there already.    You are certainly not obligated to continue unless this just interests you,  but I will keep trying to get the Preview dialog to read the Orientation settings.   By the way it reads the new margin settings in the Registry just fine... and again,  if I reload the form or restart the app then the execWB preview dialog is in synch with the default orientation setting,  so it definitely reads the value for the default printer,  I just don't see exactly how to refresh it.   I tried reloading the browser control's url and refreshing but that has no effect.  

  I am consider opening another form after any change to the orientation,  probably offscreen and loading the same url,  then doing my preview from that form and closing it afterward.   That way the execWB preview would always be on an instance of the browser created AFTER any orientation changes.   Kind of kludge but if it works I will go with it.   Maybe I will also do a new question specifically on that one issue and then there will be some fresh points for you and others.

  Thank you VERY much for your assistance,  it was invaluable.   You did a fine job.

        Danny
0
 

Author Comment

by:DKNY-2005
ID: 13913446
Last comment,  [I hope!]

  opening a new form with a browser control offscreen AFTER any orientation changes works fine.   I just pass control to a new modal form,  the load statement copies the current forms location to another browser control,  which is offscreen and therefore not visible.  I always use the status change rather than the navigatecomplet,  watch for the status to return the text "Done" and then I know the page is loaded,  we are off-line so it's very quick,  and then I run the execWB and unload the from,  all from the status Text change,   so you never see the form,  and it's always a new browser control reading the printer orientation prior to the execWB.

 A little crude maybe but it works every time.

 Anybody fighting with this stuff in VB can let me know and I will try to clarify any details.   DK
0
 
LVL 13

Expert Comment

by:softplus
ID: 13915552
Thanks DK. Sometimes you really have trick that stuff to make it work the way you really want, huh? I think I'll try it again as well :)
John
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question