Skip to content

Commit 770ec68

Browse files
author
Simeon Willbanks
committed
Inspect file mime-type to determine if GraphicsMagick can convert file to PDF
1 parent 2d03ce9 commit 770ec68

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

lib/docsplit.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module Docsplit
1515

1616
METADATA_KEYS = [:author, :date, :creator, :keywords, :producer, :subject, :title, :length]
1717

18-
GM_FORMATS = [:png, :gif, :jpg, :jpeg, :tif, :tiff, :bmp, :pnm, :ppm, :svg, :eps]
18+
GM_FORMATS = ["image/gif", "image/jpeg", "image/png", "image/x-ms-bmp", "image/svg+xml", "image/tiff", "image/x-portable-bitmap", "application/postscript", "image/x-portable-pixmap"]
1919

2020
DEPENDENCIES = {:java => false, :gm => false, :pdftotext => false, :pdftk => false, :tesseract => false}
2121

@@ -66,7 +66,7 @@ def self.extract_pdf(docs, opts={})
6666
basename = File.basename(doc, ext)
6767
escaped_doc, escaped_out, escaped_basename = [doc, out, basename].map(&ESCAPE)
6868

69-
if ext.length > 0 && GM_FORMATS.include?(ext.sub(/^\./, '').downcase.to_sym)
69+
if GM_FORMATS.include?(`file -b --mime-type #{doc}`.strip)
7070
`gm convert #{escaped_doc} #{escaped_out}/#{escaped_basename}.pdf`
7171
else
7272
options = "-jar #{ROOT}/vendor/jodconverter/jodconverter-core-3.0-beta-3.jar -r #{ROOT}/vendor/conf/document-formats.js"

0 commit comments

Comments
 (0)