Web浏览器控件打印 [英] WebBrowser Control Printing

查看:85
本文介绍了Web浏览器控件打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候,


(.NET 2.0,WinXP Pro / Server 2003,带有最新服务包的IE6)。


我''我们决定利用HTML

文档的布局特性来简化我的打印任务,但当然它会抛出一大堆新问题。 ..


我正在从我的应用程序生成HTML中的多页可打印文档,并且

在WebBrowser控件中显示它。我已经考虑使用一些CSS

命令来控制分页,但到目前为止似乎没有任何东西符合要求。


我需要包含一个自定义页眉/页脚(从另一个HTML文件导入)

在每个打印的页面上。我还需要在每个

页面周围画一个边框。我最接近边界的是将我的所有打印内容

放在HTML表格中,这看起来很难看,因为它并没有关闭

英尺每个页面 - 它只在最后的水平线上绘制

文件。


我尝试从WebBrowser继承并覆盖OnPrint事件,但

这似乎永远不会被称为?我在MSDN网站上找到了一个例子,但

它全部用C ++编写,似乎是围绕MFC设计的。


如何挂起关于HTML的时髦内置格式化功能,但

仍然可以控制打印输出和放大器分页?帮助!


提前致谢,

Alex Clark


解决方案

Alex,


我建议您查看打印模板:

http://msdn.microsoft.com/library/de。 ..intpreview.asp

http://msdn.microsoft.com/library/de...asp?frame=true
< br $> b $ b -

科林·奈勒
http://www.colinneller.com/blog

" Alex Clark" <豪******* @ newsgroups.nospam>在消息中写道

新闻:%2 **************** @ tk2msftngp13.phx.gbl ...

问候,

(.NET 2.0,WinXP Pro / Server 2003,带有最新服务包的IE6)。

我决定利用HTML的布局特征/>文件来简化我的打印任务,但当然它会引发一系列新问题...

我正在生成一个多页可打印文档来自我的应用程序的HTML,并将其显示在WebBrowser控件中。我已经考虑使用一些CSS
命令来控制分页,但到目前为止似乎没有什么符合要求。

我需要包含一个自定义页眉/页脚(从另一个HTML导入)文件)
在每个打印的页面上。我还需要在每个页面周围画一个边框。我最接近边界的是将我的所有打印内容放在HTML表格中,这看起来很难看,因为它并没有在每页的页面上关闭 - 它只是绘制了它最后的水平线在文档的最后端。

我尝试从WebBrowser继承并覆盖OnPrint事件,但
这似乎永远不会被调用?我在MSDN网站上找到了一个例子,
但是它全部都是用C ++编写的,似乎是围绕MFC设计的。

我怎样才能坚持时髦的内置格式HTML的功能,但
仍然可以控制打印输出和&分页?帮助!

提前致谢,
Alex Clark



您好Colin,


这些看起来非常有用,但文章似乎暗示在使用C ++时这只是

。我知道它是很久以前写的(之前是

..NET)但它似乎并不像VB.NET友好的那样:-(

谢谢,

Alex


" Colin Neller"< cn ***** @ gmail.com>写在留言中

新闻:e6 ************** @ tk2msftngp13.phx.gbl ...

Alex,
我建议您查看打印模板:

http://msdn.microsoft.com/library/de...intpreview.asp

http://msdn.microsoft.com/library/de...asp?frame=true

-
科林·奈勒
http://www.colinneller.com/blog

Alex Clark <豪******* @ newsgroups.nospam>在消息中写道
新闻:%2 **************** @ tk2msftngp13.phx.gbl ...

问候,

(.NET 2.0,WinXP Pro / Server 2003,带有最新服务包的IE6)。

我决定利用HTML
文档的布局特性来简化我的打印任务,但当然它会引发一系列新问题...

我正在从我的应用程序生成HTML多页面可打印文档,并将其显示在WebBrowser控件中。我已经考虑使用一些CSS
命令来控制分页,但到目前为止似乎没有什么符合要求。

我需要包含一个自定义页眉/页脚(从另一个HTML导入)
文件)在每个打印的页面上。我还需要在每个页面周围画一个边框。我最接近边界的是将我所有的
打印内容放在一个HTML表格中,这看起来很难看,因为它并没有在每页的底部关闭 - 它只是绘制了它文档最后的最后一行。

我尝试从WebBrowser继承并覆盖OnPrint事件,但
这似乎永远不会被调用?我在MSDN网站上找到了一个例子,
但是它全部都是用C ++编写的,似乎是围绕MFC设计的。

我怎样才能坚持时髦的内置格式HTML的功能,但
仍然可以控制打印输出和&分页?帮助!

提前致谢,
Alex Clark




Alex,


打印模板当然不重要,但它们不需要C ++。我给出的示例代码的

键代码是:


pCmdTarg-> Exec(& CGID_MSHTML,

IDM_PRINT,

OLECMDEXECOPT_PROMPTUSER,

& vTemplatePath,

NULL);


基本上,是什么你会在.NET中将你的IWebBrowser2对象转换为

IOleCommandTarget并调用Exec方法(如上所述)将路径传递给

你的打印模板(vTemplatePath in上面的例子。)绝大多数

的打印模板代码将用JavaScript编写。


老实说,我认为你最好投资一个报告书写工具

(例如ActiveReports)你带WB的路径不是一个简单的路径。


-

Colin Neller
http:// www。 colinneller.com/blog

" Alex Clark" <豪******* @ newsgroups.nospam>写在消息

新闻:%2 **************** @ TK2MSFTNGP11.phx.gbl ...

嗨科林,

这些看起来非常有用,但文章似乎暗示只有在使用C ++时才有可能。我知道它是很久以前写的(在.NET之前)但它看起来似乎不是VB.NET友好的:-(

谢谢,
Alex

Colin Neller< cn ***** @ gmail.com>在留言中写道
新闻:e6 *********** *** @ tk2msftngp13.phx.gbl ...

Alex,

我建议您查看打印模板:

http:// msdn .microsoft.com / library / de ... intpreview.asp
http://msdn.microsoft.com/library/de...asp?frame=true

- 科林·奈勒
http://www.colinneller.com/blog

" Alex Clark" l吨;豪******* @ newsgroups.nospam>在消息中写道
新闻:%2 **************** @ tk2msftngp13.phx.gbl ...

问候,

(.NET 2.0,WinXP Pro / Server 2003,带有最新服务包的IE6)。

我决定利用HTML
文档的布局特性来简化我的打印任务,但当然它会引发一系列新问题...

我正在从我的应用程序生成HTML多页面可打印文档,并将其显示在WebBrowser控件中。我已经考虑使用一些CSS
命令来控制分页,但似乎没有什么比这更好了。

我需要包含一个自定义页眉/页脚(在每个打印的页面上从另一个HTML
文件导入。我还需要在每个页面周围画一个边框。我最接近边界的是将我所有的
打印内容放在一个HTML表格中,这看起来很难看,因为它并没有在每页的底部关闭 - 它只是绘制了它文档最后的最后一行。

我尝试从WebBrowser继承并覆盖OnPrint事件,但
这似乎永远不会被调用?我在MSDN网站上找到了一个例子,
但是它全部都是用C ++编写的,似乎是围绕MFC设计的。

我怎样才能坚持时髦的内置格式HTML,
的功能,但仍然可以控制打印输出和&分页?帮助!

提前致谢,
Alex Clark





Greetings,

(.NET 2.0, WinXP Pro/Server 2003, IE6 with latest service packs).

I''ve decided to take advantage of the layout characteristics of HTML
documents to simplify my printing tasks, but of course it''s thrown up a
whole host of new issues...

I''m generating a multi page printable document in HTML from my app, and
displaying it in a WebBrowser control. I''ve looked into using some CSS
commands to control pagination, but nothing seems to fit the bill so far.

I need to include a custom header/footer (imported from another HTML file)
on every page that''s printed. I also need to draw a border around each
page. The closest I can get to the border is putting all my print-content
inside an HTML table, which looks ugly because it doesn''t close off at the
foot of each page - it only draws its final horizontal line at the very end
of the document.

I tried inheriting from WebBrowser and overriding the OnPrint event, but
this never seems to get called? I''ve found an example on the MSDN site, but
it''s all in C++ and seems designed around MFC.

How can I hang on to the snazzy built-in formatting features of HTML, but
still have control over the printed output & pagination? Help!

Thanks in advance,
Alex Clark


解决方案

Alex,

I suggest you look into Print Templates:

http://msdn.microsoft.com/library/de...intpreview.asp

http://msdn.microsoft.com/library/de...asp?frame=true

--
Colin Neller
http://www.colinneller.com/blog
"Alex Clark" <ho*******@newsgroups.nospam> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...

Greetings,

(.NET 2.0, WinXP Pro/Server 2003, IE6 with latest service packs).

I''ve decided to take advantage of the layout characteristics of HTML
documents to simplify my printing tasks, but of course it''s thrown up a
whole host of new issues...

I''m generating a multi page printable document in HTML from my app, and
displaying it in a WebBrowser control. I''ve looked into using some CSS
commands to control pagination, but nothing seems to fit the bill so far.

I need to include a custom header/footer (imported from another HTML file)
on every page that''s printed. I also need to draw a border around each
page. The closest I can get to the border is putting all my print-content
inside an HTML table, which looks ugly because it doesn''t close off at the
foot of each page - it only draws its final horizontal line at the very
end of the document.

I tried inheriting from WebBrowser and overriding the OnPrint event, but
this never seems to get called? I''ve found an example on the MSDN site,
but it''s all in C++ and seems designed around MFC.

How can I hang on to the snazzy built-in formatting features of HTML, but
still have control over the printed output & pagination? Help!

Thanks in advance,
Alex Clark



Hi Colin,

These look really useful but the article seems to imply that this is only
possible when using C++. I know it was written a long time ago (before
..NET) but it doesn''t seem as though it could be very VB.NET friendly :-(

Thanks,
Alex

"Colin Neller" <cn*****@gmail.com> wrote in message
news:e6**************@tk2msftngp13.phx.gbl...

Alex,

I suggest you look into Print Templates:

http://msdn.microsoft.com/library/de...intpreview.asp

http://msdn.microsoft.com/library/de...asp?frame=true

--
Colin Neller
http://www.colinneller.com/blog
"Alex Clark" <ho*******@newsgroups.nospam> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...

Greetings,

(.NET 2.0, WinXP Pro/Server 2003, IE6 with latest service packs).

I''ve decided to take advantage of the layout characteristics of HTML
documents to simplify my printing tasks, but of course it''s thrown up a
whole host of new issues...

I''m generating a multi page printable document in HTML from my app, and
displaying it in a WebBrowser control. I''ve looked into using some CSS
commands to control pagination, but nothing seems to fit the bill so far.

I need to include a custom header/footer (imported from another HTML
file) on every page that''s printed. I also need to draw a border around
each page. The closest I can get to the border is putting all my
print-content inside an HTML table, which looks ugly because it doesn''t
close off at the foot of each page - it only draws its final horizontal
line at the very end of the document.

I tried inheriting from WebBrowser and overriding the OnPrint event, but
this never seems to get called? I''ve found an example on the MSDN site,
but it''s all in C++ and seems designed around MFC.

How can I hang on to the snazzy built-in formatting features of HTML, but
still have control over the printed output & pagination? Help!

Thanks in advance,
Alex Clark




Alex,

Print Templates are certainly non-trivial, but they do not require C++. The
key line of code from the example I gave is:

pCmdTarg->Exec(&CGID_MSHTML,
IDM_PRINT,
OLECMDEXECOPT_PROMPTUSER,
&vTemplatePath,
NULL);

Basically, what you would do in .NET is cast your IWebBrowser2 object to an
IOleCommandTarget and call the Exec method (as above) passing in the path to
your print template (vTemplatePath in the above example.) The vast majority
of the Print Template code will be written in JavaScript.

Honestly, I think you would be better investing in a report writing tool
(e.g. ActiveReports) The path you are headed down with the WB is not an
easy one.

--
Colin Neller
http://www.colinneller.com/blog
"Alex Clark" <ho*******@newsgroups.nospam> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...

Hi Colin,

These look really useful but the article seems to imply that this is only
possible when using C++. I know it was written a long time ago (before
.NET) but it doesn''t seem as though it could be very VB.NET friendly :-(

Thanks,
Alex

"Colin Neller" <cn*****@gmail.com> wrote in message
news:e6**************@tk2msftngp13.phx.gbl...

Alex,

I suggest you look into Print Templates:

http://msdn.microsoft.com/library/de...intpreview.asp

http://msdn.microsoft.com/library/de...asp?frame=true

--
Colin Neller
http://www.colinneller.com/blog
"Alex Clark" <ho*******@newsgroups.nospam> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...

Greetings,

(.NET 2.0, WinXP Pro/Server 2003, IE6 with latest service packs).

I''ve decided to take advantage of the layout characteristics of HTML
documents to simplify my printing tasks, but of course it''s thrown up a
whole host of new issues...

I''m generating a multi page printable document in HTML from my app, and
displaying it in a WebBrowser control. I''ve looked into using some CSS
commands to control pagination, but nothing seems to fit the bill so
far.

I need to include a custom header/footer (imported from another HTML
file) on every page that''s printed. I also need to draw a border around
each page. The closest I can get to the border is putting all my
print-content inside an HTML table, which looks ugly because it doesn''t
close off at the foot of each page - it only draws its final horizontal
line at the very end of the document.

I tried inheriting from WebBrowser and overriding the OnPrint event, but
this never seems to get called? I''ve found an example on the MSDN site,
but it''s all in C++ and seems designed around MFC.

How can I hang on to the snazzy built-in formatting features of HTML,
but still have control over the printed output & pagination? Help!

Thanks in advance,
Alex Clark





这篇关于Web浏览器控件打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆