Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
takahashim committed Apr 24, 2024
1 parent 91fd8f5 commit d09804b
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions lib/decidim/exporters/pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,9 @@ def export
locals: locals
)

Dir.mktmpdir do |dir|
html_path = File.join(dir, "tmp.html")
File.write(html_path, html)
url = URI::File.build([nil, html_path])

browser = Ferrum::Browser.new
browser.go_to(url)
document = browser.pdf(path: nil,
encoding: :binary,
landscape: orientation != "Portrait",
printBackground: true,
scale: 0.8,
format: :A4)
document = pdf_from_string(html, orientation:)

ExportData.new(document, "pdf")
end
ExportData.new(document, "pdf")
end

# may be overwritten if needed
Expand Down Expand Up @@ -62,6 +49,27 @@ def locals
def controller
raise NotImplementedError
end

private

def pdf_from_string(html, orientation:)
Dir.mktmpdir do |dir|
html_path = File.join(dir, "tmp.html")
File.write(html_path, html)
url = URI::File.build([nil, html_path])

browser = Ferrum::Browser.new
browser.go_to(url)
document = browser.pdf(path: nil,
encoding: :binary,
landscape: orientation != "Portrait",
printBackground: true,
scale: 0.8,
format: :A4)
end

document
end
end
end
end

0 comments on commit d09804b

Please sign in to comment.