C#怎么在WebBrowser中word只能打开一个文档PDF文档

C#写的Windows窗体程序中,如何更新webBrowser中html的内容显示? - 知乎3被浏览1947分享邀请回答0添加评论分享收藏感谢收起【求助】急!急!C#获取网页html源文件,再用WebBrowser显示【c#吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:111,311贴子:
【求助】急!急!C#获取网页html源文件,再用WebBrowser显示收藏
请问有谁比较熟悉Winform的WebBrowser吗?我现在把html代码获取回来后,然后再把html代码赋给WebBrowser.DocumentText后,网页的样式就没了,我现在想先获取html代码回来,然后自己稍微再处理下,然后再赋给DocumentText显示,请问该如何使得网页按原来样式显示呢?有人知道吗?System.IO.StreamReader sr = new System.IO.StreamReader(webBrowser1.DocumentStream, Encoding.GetEncoding(&utf-8&));string html = sr.ReadToEnd();//获取源文件sr.Close();//...对html代码进行处理,只改变文字部分webBrowser1.DocumentText =//处理完后重新显示
c#培训选择达内的理由1,企业级开发环境2,项目实战教学3,c#课程可选4,金牌讲师授课5,周末/业余班任选.c#培训首选达内--美国上市公司!
如果是WebBrowser从本地加载HTML,那么你从别的站点拿到HTML以后里面其他资源的URL可能是Relative的,WebBrowser从你的本地取不到这些资源否则应该从DOM上下手
把相对路径改为绝对路径
2楼说的对。
登录百度帐号推荐应用C# 生转换网页为pdf
字体:[ ] 类型:转载 时间:
最近工作中遇到一个将htm转换为pdf的任务,这是一个有很有用的功能块,然而很遗憾,网上没有现成可行(包括开源/免费、易用和可维护性的考虑)方案。既然没有现成的解决方案就自己着手解决吧。
从htm生成pdf大概可以分两步实现,第一步,解析htm,就是将htm源文件中那一对文本转换为浏览器最终呈现给我们那种图文并茂的结果。这是一个不可完成的任务,因为目前为止业界的软件巨头也没有谁把htm解析做得很好的。对比ie、firefox等浏览器的显示结果便可想而知。既然业界难题,我也就不去钻牛角尖做技术攻关了,先跳过这步,考虑下一步的事情。 第二步,绘制pdf,这个简单,网上有很多资料,有兴趣的朋友可以研究 pdf的文件格式,安装二进制组装pdf。我有兴趣,然而没有时间,我觉得软件从业者时刻都应该关注最有价值的事情。软件从业者要提高效率的第一法门便是重用,网上有一个叫itextsharp的东西是用来绘制pdf的,可以免费使用而且开源。 下载itextsharp,试着用itextsharp绘制htm看看效果,如您所料,绘制出的是htm的源代码。因为第一步的事情我们还没有解决,下面来解决第一步的事情。 记得很久以前见过一个.net写的网页snap工具,大概思路是利用webbrowser的DrawToBitmap方法将ie的显示结果输出到Sytem.Drawing.Bitmap对象。大概代码如下: //WebBrowser wb= System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(w, h); wb.DrawToBitmap(bmp, new System.Drawing.Rectangle(0,0, w, h)); ok,htm可以解析了,现在重组刚才的代码,思路如下: 使用webbrowser将htm解析并转换为图片,使用itextsharp将刚才的图片绘制成pdf。 有用是给公司开发的功能,暂时不便公开源码,提供我编译后的工具供下载使用,您也可以根据上面的思路定制: 使用方法, 1.将单个url转换为pdf:PageToPDF.exe "/" "google.jpg" 2.将多个url转换为pdf:pagetopdf.exe task.txt "C:\pdfdir\" task.txt是任务里表,里面提供多行url,每个url以#文件名为后缀,如:/#b表示将/转换为pdf文件名为b(扩展名系统自己会追加) 在asp.net环境下使用 将pagetopdf上传至网站中,设定好目录权限,示例代码:
代码如下: public static bool CreatePPDF(string url,string path) { try { if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(path))
Process p = new Process(); string str = System.Web.HttpContext.Current.Server.MapPath("~/afafafasf/PageToPDF.exe "); if (!System.IO.File.Exists(str))
p.StartInfo.FileName = p.StartInfo.Arguments = " \"" + url + "\" " + p.StartInfo.UseShellExecute = p.StartInfo.RedirectStandardInput = p.StartInfo.RedirectStandardOutput = p.StartInfo.RedirectStandardError = p.StartInfo.CreateNoWindow = p.Start(); System.Threading.Thread.Sleep(500);
} catch(Exception ex) { Sys.Log.error("Pdf create err.",ex); }
特性 在使用任务形式工作时,系统会启动多个进程,即任务管理器中会有多个pagetopdf.exe的进程,这是系统调度程序自己启动的,为了加个任务处理速度。进程数由调度程序自己控制,最多不会超过十个。
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具Asp.net实现直接在浏览器预览Word、Excel、PDF、Txt文件(附源码)
输入文件路径,在输出文件预览信息,经测试360极速(Chrome)、IE9/10、Firefox通过
分类文件及代码说明&
DemoFiles 存放可测试文件
Default.x &启动页
ExcelPreview.cs &Excel预览类
&public static void Priview(System.Web.UI.Page p, string inFilePath, string outDirPath = &&)
& & & & Microsoft.Office.Interop.Excel.Application excel =
& & & & Microsoft.Office.Interop.Excel.Workbook xls =
& & & & excel = new Microsoft.Office.Interop.Excel.Application();
& & & & object missing = Type.M
& & & & object trueObject =
& & & & excel.Visible =
& & & & excel.DisplayAlerts =
& & & & string randomName = DateTime.Now.Ticks.ToString(); &//output fileName
& & & & xls = excel.Workbooks.Open(inFilePath, missing, trueObject, missing,
& & & & & & & & & & & & & & & & & & missing, missing, missing, missing, missing, missing, missing, missing,
& & & & & & & & & & & & & & & & & & missing, missing, missing);
& & & & //Save Excel to Html
& & & & object format = Microsoft.Office.Interop.Excel.XlFileFormat.xlH
& & & & Workbook wsCurrent =//(Workbook)wsEnumerator.C
& & & & String outputFile = outDirPath + randomName + &.html&;
& & & & wsCurrent.SaveAs(outputFile, format, missing, missing, missing,
& & & & & & & & & & & & & missing, XlSaveAsAccessMode.xlNoChange, missing,
& & & & & & & & & & & & & missing, missing, missing, missing);
& & & & excel.Quit();
& & & & //Open generated Html
& & & & Process process = new Process();
& & & & process.StartInfo.UseShellExecute =
& & & & process.StartInfo.FileName = outputF
& & & & process.Start();
& & } & & & & &
PDfPreview.cs & Pdf预览类
public static void Priview(System.Web.UI.Page p, string inFilePath)
& & & & p.Response.ContentType = &Application/pdf&;
& & & & string fileName = inFilePath.Substring(inFilePath.LastIndexOf('\\') + 1);
& & & & p.Response.AddHeader(&content-disposition&, &filename=& + fileName);
& & & & p.Response.WriteFile(inFilePath);
& & & & p.Response.End();
TextFilePreview.cs &文本文件预览类
public static void Preview(System.Web.UI.Page p, string inFilePath)
& & & & string fileName = inFilePath.Substring(inFilePath.LastIndexOf('\\') + 1);
& & & & p.Response.ContentType = &text/plain&;
& & & & p.Response.ContentEncoding = System.Text.Encoding.UTF8; &//保持和文件的编码格式一致
& & & & p.Response.AddHeader(&content-disposition&, &filename=& + fileName);
& & & & p.Response.WriteFile(inFilePath);
& & & & p.Response.End();
WordPreview.cs &Word预览类

我要回帖

更多关于 网页中能打开word文档 的文章

 

随机推荐