Last active
January 31, 2025 18:46
-
-
Save barbolo/27241038ed08666d0f4b to your computer and use it in GitHub Desktop.
Convert PDF to XML in Ruby using poppler-utils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install dependencies: | |
# | |
# posix-spawn (check all benefits at https://github.com/rtomayko/posix-spawn) | |
# gem install posix-spawn | |
# | |
# Poppler utils (http://poppler.freedesktop.org/) | |
# apt-get install poppler-utils | |
# | |
require 'posix/spawn' | |
def pdf_to_xml(pdf_path) | |
cmd = "pdftohtml -stdout -xml -i -fontfullname \"#{pdf_path}\" 2>&1" | |
POSIX::Spawn::Child.new(cmd).out | |
end | |
pdf_to_xml('sample.pdf') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment