利用WkHtmlToPdf,把H5 轉成PDF


工具下載地址:

鏈接:https://pan.baidu.com/s/1TSq2WWZcvPwuIfPRHST-FA
提取碼:wkx8

 原理:

通過IIS訪問頁面,利用WkHtmlToPdf.exe,把H5 轉成PDF,方法如下

            
 1 string fileNameWithOutExtention = "test111";
 2             string AbsolutePath = Server.MapPath("~/Tools/wkhtmltopdf.exe");
 3             //執行wkhtmltopdf.exe
 4             //Process p = System.Diagnostics.Process.Start(@"D:\wkhtmltopdf\wkhtmltopdf.exe", @"http://localhost/JDBPMPDF/HtmlPage1.html D:\" + fileNameWithOutExtention + ".pdf");
 5             Process p = System.Diagnostics.Process.Start(AbsolutePath, @"http://localhost/JDBPMPDF/HtmlPage1.html D:\" + fileNameWithOutExtention + ".pdf");
 6             //若不加這一行,程序就會馬上執行下一句而抓不到文件發生意外:System.IO.FileNotFoundException: 找不到文件 ''。
 7             p.WaitForExit();
 8             //把文件讀進文件流
 9             FileStream fs = new FileStream(@"D:\" + fileNameWithOutExtention + ".pdf", FileMode.Open);
10             byte[] file = new byte[fs.Length];
11             fs.Read(file, 0, file.Length);
12             fs.Close();

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM