Closed archonic closed 10 years ago
In order to convert to PDF, pandoc uses pdflatex by default and requires specifying an output file:
http://johnmacfarlane.net/pandoc/demo/example19/Creating-a-PDF.html
So, for example, a command like echo "# Some Markdown" | pandoc -o example.pdf
could be called via PandocRuby using PandocRuby.convert("# Some Markdown", :o => "example.pdf")
, since you can just pass pandoc options as a hash to PandocRuby. Similarly, you could rewrite the example you posted using something like PandocRuby.convert(html, :from => :html, :o => "/tmp/somefilename.pdf")
.
One thing to note is that there is no error handling or feedback at all about whether the command succeeds.
Also, in case it helps, there are several other options for generating PDF files in Rails:
filename = 'somefilename.pdf'
html = "<html><body>Hello <span style='background: yellow; color: red'>world</span></body></html>"
PandocRuby.convert(html, from: :html, o: "#{Rails.root}/tmp/#{filename}")
File.open "#{Rails.root}/tmp/#{filename}", 'rb' do |f|
send_data f.read, filename: filename, type: 'application/pdf', disposition: :inline
end
I'm trying to serve a converted file with Rails and I'm not sure what the syntax should be. I've run the command line and everything is installed correctly.
It looks like the convert method returns nothing - the resulting pdf is totally empty (as in not even file headers). Changing to
converter = PandocRuby.new(html, {:from => :html, :to => :pdf}, :standalone)
gives a broken pipe error. Any help is greatly appreciated!