-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdf_compiler.rb
41 lines (38 loc) · 1.38 KB
/
pdf_compiler.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env ruby
require 'rmagick'
# def compile_pdfs
# puts 'Writing'
# title = `cat build/title.t`
# start_chapters = `cat build/start.t`.split(',').map(&:to_i)
# end_chapters = `cat build/end.t`.split(',').map(&:to_i)
# start_chapters.each_with_index do |start_chap, i|
# image_list = []
# (start_chap..end_chapters[i]).each do |chap|
# dir = "./build/Chapter_#{chap}"
# num_pages = Dir[File.join(dir, '**', '*')].count { |file| File.file?(file)}
# for num in 0..num_pages - 1
# image_list.push("build/Chapter_#{chap}/page_#{num}.jpg")
# end
# end
# img = Magick::ImageList.new(*image_list)
# img.write("out/#{title}_chap_#{start_chap}-#{end_chapters[i]}.pdf")
# puts "Done writing chapters #{start_chap}-#{end_chapters[i]}"
# end
# `rm -rf build`
# end
def compile_pdfs(start_chapter, end_chapter)
puts 'Writing'
title = `cat build/title.t`
image_list = []
(start_chapter..end_chapter).each do |chap|
dir = "./build/Chapter_#{chap}"
num_pages = Dir[File.join(dir, '**', '*')].count { |file| File.file?(file)}
for num in 0..num_pages - 1
image_list.push("build/Chapter_#{chap}/page_#{num}.jpg")
end
end
img = Magick::ImageList.new(*image_list)
img.write("out/#{title}_chap_#{start_chapter}-#{end_chapter}.pdf")
puts "Done writing chapters #{start_chapter}-#{end_chapter}"
`rm -rf build`
end