使用 IE 控件打印到特定打印机而不更改默认打印机

发布于 2024-11-04 03:35:09 字数 1255 浏览 0 评论 0原文

有没有办法让我将 PrintDlg 结构(或类似的结构)传递给我的 WebBrowser (Internet Explorer / IWebBrowser2) 控件,以便它可以打印到 PrintDlg 中指定的打印机而不弹出打印对话框?我想在不更改默认打印机的情况下执行此操作。 IWebBrowser2::ExecWB 提供了一种跳过对话框弹出窗口的方法 (OLECMDEXECOPT_DONTPROMPTUSER),但没有提供指定打印机的方法。

仅更改默认打印机有两个问题:1) 速度慢,2) Internet Explorer 会缓存当前的打印机。当您打印到默认打印机时,它会缓存该打印机。如果您随后更改默认打印机并告诉它再次打印,IE 将不会使用新的默认打印机,它将使用其缓存的当前打印机。

在 IE 5.5 之后,当前打印机不再存储在 Windows 注册表中。

作为替代方案,我研究了 4 种不同的想法,用于从 IE 控件获取图像并自行打印,而不是让控件自行打印:

  1. 使用 IViewObject::Draw。我可以获取图像,但无法像为 IE 打印时那样缩放到纸张:

    RECTL 矩形;
    矩形.left = 0;
    矩形.top = 0;
    rect.right = GetDeviceCaps(printerhdc, PHYSICALWIDTH);
    rect.bottom = GetDeviceCaps(printerhdc, PHYSICALHEIGHT);

    StartDoc(printerhdc, &di);
    StartPage(printerhdc);
    HRESULT hr = pViewObj->Draw(DVASPECT_DOCPRINT, page, NULL, pTargetDevice, Printerhdc, Printerhdc, &rect, NULL, NULL, 0); //打印太小
    EndPage(printerhdc);
    EndDoc(printerhdc);

  2. 向 IE 控件发送 WM_PAINT。我对此没有做过多的工作,因为我在网上的一个帖子中读到这效果不太好。

  3. AxDHTMLEDLib。文档很少,我认为这仅适用于 .net

  4. Using IHTMLElement、IHTMLElementRender->SetDocumentPrinter、IHTMLElementRender->DrawToDc。 Microsoft 已取消对 IE9

如果您有任何想法,我们将不胜感激!提前致谢!

Is there a way for me to pass a PrintDlg structure (or something similar) to my WebBrowser (Internet Explorer / IWebBrowser2) control such that it will print to the printer specified in the PrintDlg without popping up a print dialog? I want to do this without changing the default printer. IWebBrowser2::ExecWB provides a way to skip the dialog pop-up (OLECMDEXECOPT_DONTPROMPTUSER), but not a way to specify a printer.

There are two problems with just changing the default printer: 1) it's slow, 2) Internet Explorer keeps its current printer cached. When you print to the default printer, it will cache that printer. If you then change the default printer and tell it to print again, IE will not use the new default printer, it will used its cached current printer.

After IE 5.5, the current printer is not stored in the Windows registry.

As an alternative, I researched 4 different ideas for getting the image from the IE control and printing myself rather than getting the control to print itself:

  1. Using IViewObject::Draw. I can get the image, but can't get it to scale to paper the same way that it does when printed for IE:

    RECTL rect;
    rect.left = 0;
    rect.top = 0;
    rect.right = GetDeviceCaps(printerhdc, PHYSICALWIDTH);
    rect.bottom = GetDeviceCaps(printerhdc, PHYSICALHEIGHT);

    StartDoc(printerhdc, &di);
    StartPage(printerhdc);
    HRESULT hr = pViewObj->Draw(DVASPECT_DOCPRINT, page, NULL, pTargetDevice, printerhdc, printerhdc, &rect, NULL, NULL, 0); //prints too small
    EndPage(printerhdc);
    EndDoc(printerhdc);

  2. Sending a WM_PAINT to the IE control. I haven't done much with this one, as I read in a thread online that this didn't work that well.

  3. AxDHTMLEDLib. Very little documentation, and I think this is just for .net

  4. Using IHTMLElement, IHTMLElementRender->SetDocumentPrinter, IHTMLElementRender->DrawToDc. Microsoft has withdrawn support with IE9

Any ideas you may have would be wildly appreciated! Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

两相知 2024-11-11 03:35:09

如果您可以灵活地使用默认打印机,这里还有另一个想法。不过这有点绕。

  • 将您的默认打印机设置为 PDF 编写器(例如 Amyuni PDF 或 Adob​​e Distiller)。这些打印机驱动程序将传入的作业转换为 PDF 文件,您可以将其设置为将文件保存在某个磁盘位置。

  • 使用 PowerShell 将此 PDF 文件打印到您需要的目标打印机。您可以使用 PrintUI DLL 接口或使用“打印”动词。 http://www .eggheadcafe.com/software/aspnet/30441939/how-to-suppress-printdialog-when-using-print-verb.aspx 提供了一个示例。通过执行此操作,您可以在此脚本中进行所有打印机队列自定义,并按原样保留默认打印机

If you have some flexibility of using a default printer, here is another idea. It is a bit round-a-about though.

  • make your default printer some PDF writer (like Amyuni PDF or Adobe Distiller). These printer drivers convert the incoming job into a PDF file and you can set it up to save the file in some disk location.

  • use a PowerShell to print this PDF file to your target printer you need. You can either use the PrintUI DLL interface or use and the "print" verb. http://www.eggheadcafe.com/software/aspnet/30441939/how-to-suppress-printdialog-when-using-print-verb.aspx provides an example. By doing this, you can do all your printer queue customization in this script and leave the default printer as-is

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文