LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Printer Setup for HTML reports (Landscape)

I'm trying to print an HTML report in Landscape, the Report Orientation VI only works with Standard Reports, and I can't find anything that will let me modify the "Printer Setup"

Anyone done this?
0 Kudos
Message 1 of 10
(6,521 Views)
Jeff,

Unforunately, LabVIEW does not currently offer any VIs to handle printing HTML reports -- neither the actual printing nor the print orientation. Of course the easiest solution is to simply use a standard report, but if an HTML report is a must, your only option would be to attempt to make calls to the Windows SDK or to use ActiveX. There is a past discussion forum that touches on this subject, and I've linked it here. Another option, albeit non-ideal, would be to set your printer default to landscape.

Regards,
E. Sulzer
Applications Engineer
National Instruments
0 Kudos
Message 2 of 10
(6,501 Views)
Jeff,

To print an HTML report it first has to be rendered. To render HTML, you need a browser. For example, you can render HTML in either Internet Explorer or Firefox or Opera, and all three might render the same data slightly differently. To simplify the situation let's say that you're using IE. Once IE renders the HTML, you then have to get it to send the rendered output to the printer. So you can see why it isn't time or cost-effective for NI to try and necessarily support these functions. For the end user however, I'd guess that quite a few people have had this problem.

I have had to do a lot of digging around to get HTML reports to print right. My solution has been to use an ActiveX container with an IWebBrowser2 object (Internet Explorer). This will let you load and print HTML reports programatically however (glancing back over some old code) I don't see immediately how you can print a report in Landscape. With an ActiveX container however you can call the IE print preview function which will let you (the user) modify the report printing to Landscape. It's not a programmatic solution since you have to interact with the GUI but it works. Also, once you set the setting to Landscape, everything printed afterwards using your ActiveX container will also print in Landscape.

Something else which may not apply to you (but maybe--I'll at least mention it) is printing a landscape single image... that's usually why I needed to print landscape... to print out a full page screenshot of a graph or something. I do this in portrait mode by just attaching the control image but rotating it first and adding the HTML code to make it 100% of the vertical page.

Last but not least, if you are 100% set on using a programmatic implementation to print a landscaped report (no user interaction), the best thing to do would be to build on an ActiveX implementation so that your report is being loaded and printed from an embedded IWebBrowser2 object. With the IWebBrowser2 object there is an option for using a pre-defined print template. This option is NOT for the faint of heart and requires you basically to re-program the whole IE print-preview functionality. However, it's not impossible either, it just takes the time of learning basically how the IE print preview interface works and then adapting it to your application (in this case, landscaped printouts). This is also the ONLY way to change HTML report headers and footers. The print preview interface in IE is written entirely in javascript--you can get details on msdn (search for "print preview templates"). However, there isn't really enough info there to do things with any ease. So....

If you get to the point where you get an ActiveX container working and want to fool with the IE print preview javascript templates, let me know. I have extracted the entire template and associated images from the windows DLL it is stored in so I could adapt it and change the headers and footers for my reports and things of that nature.

Now that I mention it, I believe that is the only way also to actually set landscape or portrait--by programmatically changing the printing margins (so it prints 11x8.5 instead of vice versa).

Anyway, hope that helps...
Message 3 of 10
(6,498 Views)
Hi Jeff,

One other option is to render the file in MS Word. Starting in Word 97, you can directly open, edit and save an html document. Also, setting the page orientation in Word avoids the problem of manipulating the printer in Windows because it sets the printer properties automatically for you.

To do this in ActiveX requires only about 6 Property and method nodes after the application is opened. They are prop Application.Documents, meth Documents.Open, prop Document.PageSetup, prop PageSetup.Orientation, meth Document.Printout, and meth Application.Quit. See the attached image.
Michael Munroe, CLD, CTD, MCP
Automate 1M+ VI Search, Sort and Edit operations with Property Inspector 5.1, now with a new Interactive Window Manager!
Now supports full project automation using one-click custom macros or CLI.
0 Kudos
Message 4 of 10
(6,436 Views)
Hi,

I'm interested in example VIs on how to control the activeX controlls for Printer Settings.
I'm allready using the IWebBrowser2 object (also slightly modiefied the original NI Print VIs to enable Preview and such). However I still couldn't find a way to modify Printersetting for IWebBrowser2.

Cheers, Rainer
0 Kudos
Message 5 of 10
(6,357 Views)
Dear m3nth,

That is exactly what I'm doing. I love IE's print preview functionality and I've been reading MSDN documentation and downloaded their sample templates exe. It doesn't work for me :(. I created a string with the path to an example template.htm, flattened it to binary string, converted that to a variant and fed it to pvaIn of IWebBrowser2::ExecWB:PrintPreview command. From their C++ code I can see that that's probably not the whole thing I have to do since there are IWebBrowser events and I must catch the IDM_PRINTPREVIEW. I'm not sure how to do that. You said that you got it to work, could you please post an example?

Another question is, is it possible to use pvaOut to save the changes of what the user specified for header/footer & page layout for example back into the .htm template you pass that function?

Message Edited by romulus on 03-22-2007 11:46 AM

0 Kudos
Message 6 of 10
(5,974 Views)
So you have a template but can't get it to load correctly?  You should only have the path in a string... you don't need it to flatten and convert to a variant, you should be able to wire the string control directly to pvaIn of the IWebBrowser2 method.  I have no idea if you could gain information from pvaOut (wouldn't that be convenient). 

For the other two arguments I used:

OLECMDID_PRINTPREVIEW
OLECMDEXECOPT_PROMPTUSER

For my templates I just took the default IE template instead of trying to make one from scratch--that was a lot easier.  Below are my notes.  I cannot attach code at the moment, which I used for parts of the process, such as testing, compiling to an .mht archive, and stripping comments.  Basically once I pulled out all the default IE files though I modified the template to look like I wanted, then compiled everything into an .mht file (using my own LabVIEW code) which served as a single-file print template which could be passed to pvaIn

------------

To make a print template:
- Copy IE Default.html to a working copy

    Using the Shell Document Object and Control Library (SHDOCLC.DLL)...
    - From IE, retrieve the print-preview dialog:
        res://shdoclc.dll/preview.dlg
    - When the dialog loads, go to Menu > View > Source
    - Save the source code to a directory.
    - Extract the necessary images needed using the syntax:
        res://shdoclc.dll/image.gif

- Make edits
- Run labview activex code to see if it works
- Once it works, compile to .mht
   - Don't delete originals
   - Strip comments ... mhtml converter doesn't work quite right like IE does so the comments can mess it up
- Make sure to include Optional Content of all "*.gif" files
- Run report tester with new .mht file and make sure to include "mhtml:" before "C:\blah blah blah\whatever.mht"
  (ie, "mhtml:C:\blah blah...)
 
Remember when testing .mht files that IE will cache the decompressed files and may not update them.
Changing the name will make it reload a fresh file.  Cache is cleared (I think) when LabVIEW is restarted.

0 Kudos
Message 7 of 10
(5,965 Views)
Awesome. Wish this was documented somewhere. Thanks a lot, can't wait to try it out.
0 Kudos
Message 8 of 10
(5,959 Views)
I tried shdocl.dll and that seems like the IE 6.x dll. I'm using IE 7 & love it's print preview template which is a lot better and does a lot more now. I was wondering if you know the dll for IE 7 to probe. If not i'll google it. Thanks again!
0 Kudos
Message 9 of 10
(5,955 Views)
I can't check it right now but try looking here:

res://ieframe.dll/preview.dlg



You may need to insert the absolute path for ieframe.dll.
0 Kudos
Message 10 of 10
(5,951 Views)