html转pdf 格式不变

来源:互联网 发布:41478 网络电视直播 编辑:程序博客网 时间:2024/05/16 15:48


需要现在服务器安装 abcpdf

下载地址


先 using WebSupergoo.ABCpdf7;

 string fileToSave = System.Web.HttpContext.Current.Server.MapPath("pdf保存路径");        Doc theDoc = new Doc();        XSettings.License = "XXX";//许可号 应该可以不填        theDoc.Font = theDoc.AddFont("宋体");        /*         theDoc.MediaBox.String = "0 0 590 840";        double w = theDoc.MediaBox.Width;        double h = theDoc.MediaBox.Height;        double l = theDoc.MediaBox.Left;        double b = theDoc.MediaBox.Bottom;        //要是横着打印就注解下面代码      //  theDoc.Transform.Rotate(90, 1, b);     //   theDoc.Transform.Translate(w, 0);        // rotate our rectangle        theDoc.Rect.Width = h;        theDoc.Rect.Height = w;        */        // add some text        theDoc.Rect.Inset(15, 0);        string pageBreak = "<div style=\"page-break-before:always\"> </div> ";        string content = Literal1.Text.ToString();                   content += pageBreak ;             int theID = theDoc.AddImageHtml(content);        while (true)        {            if (!theDoc.Chainable(theID))                break;            theDoc.Page = theDoc.AddPage();            theID = theDoc.AddImageToChain(theID);        }        theDoc.SetInfo(theID, "/Rotate", "90");        theDoc.Save(fileToSave);        theDoc.Dispose();        //---------------------------------------------------                Response.ContentType = "Application/pdf";       // string FilePath = pdfFile;        Response.WriteFile(fileToSave);        Response.End();        HttpContext.Current.ApplicationInstance.CompleteRequest();


原创粉丝点击