【发布时间】:2013-10-06 02:36:48
【问题描述】:
我正在使用 c# 4.0 开发 Windows 服务,它可以转换图像中的不同文件(tif 和 jpeg)
我想在图像中转换 html 文件(通常是电子邮件)时遇到问题。
我使用浏览器
var browser = new WebBrowser();
browser.DocumentCompleted += this.BrowserDocumentCompleted;
browser.DocumentText = html;
和DrawToBitmap
var browser = sender as WebBrowser;
Rectangle body = new Rectangle(browser.Document.Body.ScrollRectangle.X * scaleFactor,
browser.Document.Body.ScrollRectangle.Y * scaleFactor,
browser.Document.Body.ScrollRectangle.Width * scaleFactor,
browser.Document.Body.ScrollRectangle.Height * scaleFactor);
browser.Height = body.Height;
Bitmap output = new Bitmap(body.Width, body.Height);
browser.DrawToBitmap(output, body);
它适用于中小型 html,但适用于长 html(如 22 000 像素或更高) 我在 DrawToBitmap 上有 GDI 例外:
参数无效
图像 GDI+ 无效
根据网上的说法,这种错误是因为图片太大而附加的。
我的问题:如何在 X 图像(分页)中转换 html 而不生成大图像并在之后裁剪,以及是否可以不使用库。
提前谢谢你。
编辑:我找到了一个棘手的解决方案:用 div 包围 html,女巫将设置页面和另一个用于偏移,例如:
<div style="height:3000px; overflow:hidden">
<div style="margin-top:-3000px">
但是这种解决方案可以在一行文本或图像中间进行裁剪...
【问题讨论】:
标签: c# pagination webbrowser-control gdi+