Module: Html2Pdf::Utils
- Defined in:
- lib/html2pdf/utils.rb
Class Method Summary collapse
-
.softwares_installed? ⇒ Boolean
Check and verify that the proper softwares are available.
-
.to_pdf(filename) ⇒ Object
Convert ‘*.xhtml’ or ‘*.html’ to pdf.
-
.to_pdfs(files) ⇒ Object
Batch convert to pdf using ‘wkhtmltopdf` tool.
Class Method Details
.softwares_installed? ⇒ Boolean
Check and verify that the proper softwares are available.
46 47 48 |
# File 'lib/html2pdf/utils.rb', line 46 def softwares_installed? AgileUtils::Helper.which('wkhtmltopdf') && AgileUtils::Helper.which('gs') end |
.to_pdf(filename) ⇒ Object
Convert ‘*.xhtml’ or ‘*.html’ to pdf
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/html2pdf/utils.rb', line 22 def to_pdf(filename) fail "Invalid input file #{filename}" unless File.exist?(filename) command = [ 'wkhtmltopdf', '--margin-top 4', '--margin-bottom 4', '--margin-left 4', '--margin-right 4', '--header-center "[webpage] :: [page]/[topage]"', '--header-spacing 1', '--header-font-size 8', '--header-line', '--footer-spacing 1', '--footer-font-size 8', '--footer-line', "#{filename}", "#{filename}.pdf", '> /dev/null'] _stdin, _stderr, status = Open3.capture3(command.join(' ')) fail "Problem processing #{filename}" unless status.success? end |
.to_pdfs(files) ⇒ Object
Batch convert to pdf using ‘wkhtmltopdf` tool
12 13 14 15 16 17 |
# File 'lib/html2pdf/utils.rb', line 12 def to_pdfs(files) files.each_with_index do |file, index| puts "Convert file #{index + 1} of #{files.size} : #{file}" to_pdf(file) end end |