我正在尝试用 ruby 编写一个非常简单的类似降价的转换器,然后将输出传递给PrinceXML(这很棒)。Prince基本上将html转换为pdf。
这是我的代码:
#!/usr/bin/ruby
# USAGE: command source-file.txt target-file.pdf
# read argument 1 as input
text = File.read(ARGV[0])
# wrap paragraphs in paragraph tags
text = text.gsub(/^(.+)/, '<p>\1</p>')
# create a new temp file for processing
htmlFile = File.new('/tmp/sample.html', "w+")
# place the transformed text in the new file
htmlFile.puts text
# run prince
system 'prince /tmp/sample.html #{ARGV[1]}'
但这会将一个空文件转储到/tmp/sample.html
. 当我排除打电话给王子时,转换发生得很好。
我究竟做错了什么?