Module: Quby::PdfRenderer
- Defined in:
- lib/quby/pdf_renderer.rb
Defined Under Namespace
Classes: EmptyResponse
Class Method Summary collapse
Class Method Details
.render_pdf(html_str) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/quby/pdf_renderer.rb', line 7 def self.render_pdf(html_str) if ENV['GOTENBERG_URL'].present? RestClient.post(ENV['GOTENBERG_URL'], upload: { file: string_to_fileupload(html_str) }).body.tap do |response| raise EmptyResponse if response.empty? end else # deprecated fallback while testing. RestClient.post(ENV['HTML_TO_PDF_URL'], html_str).body.tap do |response| raise EmptyResponse if response.empty? end end end |
.string_to_fileupload(string) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/quby/pdf_renderer.rb', line 22 def self.string_to_fileupload(string) StringIO.new(string).tap do |file| def file.path "index.html" end end end |