Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/docsplit/command_line.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ def parse_options
opts.on('-r', '--rolling', 'generate images from each previous image') do |r|
@options[:rolling] = true
end
opts.on('--delimiter [DELIMITER]', 'set page number delimiter (eg: _, -, -Page-...)') do |d|
@options[:delimiter] = d.tr('^','')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to have your delimiter start with a dash, you need to escape it with the '^' character. So, we need to strip the '^' before passing it to @options.

end
opts.on_tail('-v', '--version', 'display docsplit version') do
puts "Docsplit version #{Docsplit::VERSION}"
exit
Expand Down
4 changes: 3 additions & 1 deletion lib/docsplit/image_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class ImageExtractor
MEMORY_ARGS = "-limit memory 256MiB -limit map 512MiB"
DEFAULT_FORMAT = :png
DEFAULT_DENSITY = '150'
DEFAULT_PAGE_DELIMITER = "_"

# Extract a list of PDFs as rasterized page images, according to the
# configuration in options.
Expand Down Expand Up @@ -41,7 +42,7 @@ def convert(pdf, size, format, previous=nil)
raise ExtractionFailed, result if $? != 0
else
page_list(pages).each do |page|
out_file = ESCAPE[File.join(directory, "#{basename}_#{page}.#{format}")]
out_file = ESCAPE[File.join(directory, "#{basename}#{@delimiter}#{page}.#{format}")]
cmd = "MAGICK_TMPDIR=#{tempdir} OMP_NUM_THREADS=2 gm convert +adjoin -define pdf:use-cropbox=true #{common} #{escaped_pdf}[#{page - 1}] #{out_file} 2>&1".chomp
result = `#{cmd}`.chomp
raise ExtractionFailed, result if $? != 0
Expand All @@ -63,6 +64,7 @@ def extract_options(options)
@sizes = [options[:size]].flatten.compact
@sizes = [nil] if @sizes.empty?
@rolling = !!options[:rolling]
@delimiter = options[:delimiter] || DEFAULT_PAGE_DELIMITER
end

# If there's only one size requested, generate the images directly into
Expand Down