func testXXX(){
var url = "https://wkhtmltopdf.org/usage/wkhtmltopdf.txt"
url = "https://mp.weixin.qq.com/s/lDjpPHwIteggP2yV08i7rQ"
url = "https://github.com/wkhtmltopdf/wkhtmltopdf/blob/master/examples/image_c_api.c"
url = "https://mp.weixin.qq.com/s/jJ-S0raM0uc5lah3H6hWcw"
gennerXPDF(from: url) { (stdout:Pipe) in
let data = stdout.fileHandleForReading.readDataToEndOfFile().makeBytes()
let fm = DataFile(workDir: "/Volumes/Documents/GitHub/wkhtmltopdf")
try! fm.write(data, to: "/Volumes/Documents/GitHub/wkhtmltopdf/\(url.components(separatedBy: "/").last!).pdf")
XCTAssert(data.count > 0)
}
}
public func gennerXPDF(from url: String, result:(Pipe)->Void)->Void{
let wk = Process()
let stdout = Pipe()
wk.launchPath = "/usr/local/bin/wkhtmltopdf"
wk.arguments = [ "--dump-outline","toc" ,url ]
wk.arguments?.append("-") // output to stdout
wk.standardOutput = stdout
wk.launch()
result(stdout)
}
可以根据此来生生成PDF发送给用户制作一个稍后阅读的需求
如:热门文章生成PDF发送到kindle 发送到邮箱等
网友评论