Module: AnyStyle::PDFUtils
- Included in:
- Document
- Defined in:
- lib/anystyle/utils.rb
Class Method Summary collapse
- .pdf_info(path, pdfinfo: 'pdfinfo', **opts) ⇒ Object
- .pdf_page_size(path) ⇒ Object
- .pdf_to_text(path, pdftotext: 'pdftotext', **opts) ⇒ Object
Class Method Details
.pdf_info(path, pdfinfo: 'pdfinfo', **opts) ⇒ Object
71 72 73 74 75 |
# File 'lib/anystyle/utils.rb', line 71 def pdf_info(path, pdfinfo: 'pdfinfo', **opts) Hash[%x{#{pdfinfo} "#{path}"}.split("\n").map { |ln| ln.split(/:\s+/, 2) }] end |
.pdf_page_size(path) ⇒ Object
81 82 83 |
# File 'lib/anystyle/utils.rb', line 81 def pdf_page_size(path) pdf_info(path)['Page size'].scan(/\d+/)[0, 2].map(&:to_i) end |
.pdf_to_text(path, pdftotext: 'pdftotext', **opts) ⇒ Object
65 66 67 68 69 |
# File 'lib/anystyle/utils.rb', line 65 def pdf_to_text(path, pdftotext: 'pdftotext', **opts) text = %x{#{pdftotext} #{pdf_opts(path, **opts).join(' ')} "#{path}" -} raise "pdftotext failed with error code #{$?.exitstatus}" unless $?.success? text.force_encoding(opts[:encoding] || 'UTF-8') end |