Print Preview will not appear and no exception is thrown

Lpatz-4663 20 Reputation points
2024-05-08T12:39:26.9366667+00:00

Hello,

We have an application that is using a winforms webbrowser control to display an html document.

To show a print preview, we are using: SHDocVw.IWebBrowser2.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINTPREVIEW...)

command where we are passing in a path to an IE Print Template File. The template file uses a slightly modified version of the TemplatePrinter example provided in this link: Link

The only modification was adding a print button in the print preview, which calls the "DoPrint" javascript function when button is pressed.

Here is the problem:

When a user prints the html document through the template file, the SHDocVw.IWebBrowser2.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINTPREVIEW...) cannot be called again. This results in the print preview window to not appear again when user selects that option. No exception is thrown when this happens.

We would like to use the SHDocVw.IWebBrowser2.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINTPREVIEW...) command without passing in a template file. Is there a way to do this? We also need to set the margins, header, footer, and the zoom. Programmatically.

Any suggestions or advice is greatly appreciated!

Thanks

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,459 questions
{count} votes