国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
html生成pdf
using System;
using System.Data;
using System.Web;
using iTextSharp.text.pdf;
using iTextSharp.text;
using System.IO;
using System.Windows.Forms;
using System.Threading;
public partial class HTML2PDF : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        CreatPdf();
    }
    private System.Drawing.Bitmap bitmap;
    private string url;
    private int w = 760, h = 900;
    public void setBitmap()
    {
        using (WebBrowser wb = new WebBrowser())
        {
            wb.Width = w;
            wb.Height = h;
            wb.ScrollBarsEnabled = false;
            wb.Navigate(url);
            //確保頁面被解析完全
            while (wb.ReadyState != WebBrowserReadyState.Complete)
            {
                System.Windows.Forms.Application.DoEvents();
            }
            bitmap = new System.Drawing.Bitmap(w, h);
            wb.DrawToBitmap(bitmap, new System.Drawing.Rectangle(0, 0, w, h));
            wb.Dispose();
        }
    }
    private void CreatPdf()
    {
        Document doc = new Document(PageSize.A4, 9, 18, 36, 36);//左右上下
        MemoryStream ms = new MemoryStream();
        try
        {
            PdfWriter writer = PdfWriter.GetInstance(doc, ms);
            writer.CloseStream = false;
            doc.Open();
            url = Server.MapPath("s.html");
            Thread thread = new Thread(new ThreadStart(setBitmap));
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            while (thread.IsAlive)
                Thread.Sleep(100);
            bitmap.Save(Server.MapPath("t.bmp"));
            
            iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(bitmap, System.Drawing.Imaging.ImageFormat.Bmp);
            img.ScalePercent(75);//560 630
            doc.Add(img);
        }
        catch (Exception err)
        {
            throw new Exception(err.Message);
        }
        finally
        {
            doc.Close();
            using (FileStream fs = new FileStream(Server.MapPath("out.pdf"), FileMode.Create))
            {
                ms.Position = 0;
                byte[] bit = new byte[ms.Length];
                ms.Read(bit, 0, (int)ms.Length);
                fs.Write(bit, 0, bit.Length);
            }
            ViewPdf(ms);
        }
    }
 
    private void ViewPdf(Stream fs)
    {
        Response.Clear();
        //中文名的話
        //Response.AppendHeader("Content-Disposition", "attachment;filename=" +
        //             HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8) + ";charset=GB2312");
        Response.AddHeader("Content-Disposition", "attachment;FileName=out.pdf");
        Response.AddHeader("Content-Length", fs.Length.ToString());
        Response.ContentType = "application/pdf";
        long fileLength = fs.Length;
        int size = 10240;//10K一--分塊下載,10K為1塊
        byte[] readData = new byte[size];
        if (size > fileLength)
            size = Convert.ToInt32(fileLength);
        long fPos = 0;
        bool isEnd = false;
        while (!isEnd)
        {
            if ((fPos + size) >= fileLength)
            {
                size = Convert.ToInt32(fileLength - fPos);
                isEnd = true;
            }
            readData = new byte[size];
            fs.Position = fPos;
            fs.Read(readData, 0, size);
            Response.BinaryWrite(readData);
            Response.OutputStream.Flush();
            fPos += size;
        }
        fs.Close();
        Response.OutputStream.Close();
        Response.End();
        Response.Close();
    }
本站僅提供存儲服務,所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
編程小總結(jié)
ASP.NET上傳和下載文件的代碼(轉(zhuǎn)載)
Java 下載支持斷點續(xù)傳服務端
【AHK】關(guān)于PDF的操作
博客園 - WDDAVID‘s BLOG - 《ASP.NET辦公自動化系統(tǒng)開發(fā)實例導航》筆記三 人事管理模塊
Java 下載支持斷點續(xù)傳
更多類似文章 >>
生活服務
分享 收藏 導長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服