接上一篇
根据虚拟路径生成PDF
- public void CreatePDF(string name,string virtualPath)
- {
- Doc theDoc = new Doc();
- theDoc.TopDown = true;
- theDoc.Rect.String = "22 15 820 580";//控制显示的大小205 300 632 895
- theDoc.MediaBox.String = "0 0 842 595";//控制页面的大小
- string path = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + VirtualPathUtility.ToAbsolute(virtualPath);
- int theID = theDoc.AddImageUrl(path);
- while (true)
- {
- if (!theDoc.Chainable(theID))
- break;
- theDoctheDoc.Page = theDoc.AddPage();
- theID = theDoc.AddImageToChain(theID);
- }
- byte[] theData = theDoc.GetData();
- FileCreate(name, theData);
- if (File.Exists(HttpContext.Current.Server.MapPath(name + ".pdf")))
- {
- HttpContext.Current.Response.Write(string.Format("<a target='_blank' href='{0}'>下载</a>", name + ".pdf"));
- }
- }
调用方法:
CreatePDF("software", "~/硬件试产发布单/HPTrialRelease.aspx");