我希望在没有任何第三方实用程序的情况下将 html 文件转换为 pdf。我对 cupsfilter 的输出不感兴趣,也不想编写浏览器脚本。此 AppleScript / Ruby 脚本使用 PDFKit 重新保存 pdf(以解决 InDesign 问题)。有没有办法修改它以接受 html 文件作为输入?也欢迎任何其他解决方案!
on pdf_resave(infile, outfile)
set rb to "require 'osx/cocoa'
OSX.require_framework 'PDFKit'
include OSX
raise ArgumentError, %Q[Usage: $0 <input pdf> <output pdf>] unless ARGV.length == 2
infile, outfile = ARGV
url = NSURL.fileURLWithPath(infile)
pdf = PDFDocument.alloc.initWithURL(url)
pdf.writeToFile(outfile)"
do shell script "/usr/bin/ruby -e " & rb's quoted form & " " & infile's quoted form & " " & outfile's quoted form
end pdf_resave