- // 所有要打印的网页地址
- string[] printUri = new string[] { "url..." };
- HttpWebRequest req = null;
- HttpWebResponse resp = null;
- Stream s = null;
- StreamReader sr = null;
- // 网页源代码
- string sourceHtml = string.Empty;
- for (int i = 0; i < printUri.Length; i++)
- {
- req = WebRequest.Create(printUri[i]) as HttpWebRequest;
- resp = req.GetResponse() as HttpWebResponse;
- s = resp.GetResponseStream();
- sr = new StreamReader(s, Encoding.Default);
- string subHtml = sr.ReadToEnd();
- // 利用正则提取Body
- // .....
- subHtml = subHtml.Replace("<body>", "<div>").Replace("</body>", "</div>");
- // 添加分页标记
- if (i < printUri.Length - 1)
- subHtml += "<div style=\"page-break-after:always;\"></div>";
- sourceHtml += subHtml;
- }
- // 处理特殊连接
- sourceHtml = sourceHtml.Replace("../", "http://website/dir/");
- resp.Close();
- sr.Close();
- s.Close();
- Response.Write(sourceHtml);
- Response.Write("<script type=\"text/javascript\">window.print();</script>");
- Response.End();
批量打印网页
最新推荐文章于 2025-03-19 10:28:40 发布