---
title: "用webBrowser进行iframe打印"
author: "shen211"
date: "2010-04-21T14:36:33Z"
tags: []
categories: ["Web前端"]
slug: "webbrowser-iframe"
draft: false
lastmod: "2010-04-21T14:37:16Z"
id: 649409
url: "https://shen211.iteye.com/blog/649409"
---

printFrame1为存放打印页面的iframe，其width和height均为0
在printFrame1的页面代码中加入以下JS代码进行打印。
top.printFrame1.focus();		
//top.printFrame1.wb.ExecWB(6,6);
document.execCommand("print");

如果使用ExecWB(6,6)会将在打印时将iframe内容进行缩放。如果用弹出页面打印形式则是正常。

解决IE直接打印时的缩放问题，貌似只有直接在调用打印命令进行打印，如上最后一句代码即可。

推荐采用ActiveObject方式进行打印，这应该是最好的打印方式。