phantomjs html to PDF
来源:互联网 发布:银行家算法的基本思想 编辑:程序博客网 时间:2024/06/05 05:56
*.cs
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Configuration;using System.IO;/// <summary>///PDFCommon 的摘要说明/// </summary>public class PDFCommon{public PDFCommon(){} public static string CreatePDF(string url) { string fileNameWithOutExtention = Guid.NewGuid().ToString(); string path = System.Web.HttpContext.Current.Server.MapPath(@"~\bin\phantomjs\"); //string paths = System.Web.HttpContext.Current.Server.MapPath(@"~\chartPdfFile"); string savePath = Path.Combine(@"D:/", string.Format("{0}.pdf", Guid.NewGuid())); string filePath = Path.Combine(path, "phantomjs.exe"); string jsPath = Path.Combine(path, "generate_pdf.js"); string argument = string.Format(" --ignore-ssl-errors=yes {0} \"{1}\" {2}", jsPath, url, savePath); using (System.Diagnostics.Process exep = new System.Diagnostics.Process()) { System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.FileName = filePath; startInfo.Arguments = argument; startInfo.CreateNoWindow = true; startInfo.UseShellExecute = false; startInfo.RedirectStandardInput = true; startInfo.RedirectStandardOutput = true; startInfo.RedirectStandardError = true; exep.StartInfo = startInfo; exep.Start(); exep.WaitForExit(); } return savePath; }}
*.js
// This file is NOT a browser-run javascript but PhantonJS scriptvar system = require('system');var address = system.args[1];var output = system.args[2];var page = require('webpage').create();page.paperSize = { format: 'A4', orientation: 'landscape', border: '1cm'};page.open(address, function (status) { if (status !== 'success') { console.log('Unable to load the address!'); phantom.exit(); } else { window.setTimeout(function () { // Remove all low-opacity paths. see PhantomJS issue #364 page.evaluate(function () { var paths = document.getElementsByTagName("path"); for (var i = paths.length - 1; i >= 0; i--) { var path = paths[i]; var strokeOpacity = path.getAttribute('stroke-opacity'); if (strokeOpacity != null && strokeOpacity < 0.2) path.parentNode.removeChild(path); } }); page.render(output); phantom.exit(); }, 5000); }});
- phantomjs html to PDF
- phantomjs实现html生成pdf
- atom markdown转换PDF 解决AssertionError: html-pdf: Failed to load PhantomJS module
- atom markdown转换PDF 解决AssertionError: html-pdf: Failed to load PhantomJS module
- phantomjs 将html 转换为图片或者pdf
- html to pdf
- Convert HTML to PDF
- itext html to pdf
- HTML to PDF
- phantomjs生成pdf
- wkhtmltopdf.exe >>html to PDF
- flying-sauser html to pdf
- Selenium+PhantomJS 实现非html(pdf、图片、apk等)文件下载
- php使用phantomjs生成pdf
- Howto Convert PDF files to HTML files
- Convert Html to pdf in iOS
- linux command to open pdf ,dir, html
- How to convert docx/odt to pdf/html with Java?
- Remove all the EventHandlers of the object by reflection
- c++ 如何获取系统时间
- Android TextWatcher监控EditText中的输入内容并限制其输入字符个数
- 数据库设计5步骤
- AssetBundle 【unity3d教程】
- phantomjs html to PDF
- 高斯日记
- C 语言和C++语言的 struct对比 & struct和typedef struct
- 算法学习与实践之插入排序
- 交叉编译 hostapd
- 【新手教程】如何向App Store提交应用
- 钢的琴,男人为尊严而战
- 删除链表中重复项
- Java枚举赋值字符类型