Class: F2h::Img2Pdf
- Inherits:
-
Object
- Object
- F2h::Img2Pdf
- Defined in:
- lib/pdf2img.rb
Instance Method Summary collapse
- #do_the_pdf(pdfs_to_html) ⇒ Object
-
#initialize ⇒ Img2Pdf
constructor
A new instance of Img2Pdf.
Constructor Details
#initialize ⇒ Img2Pdf
Returns a new instance of Img2Pdf.
3 4 5 |
# File 'lib/pdf2img.rb', line 3 def initialize @bp = Boilerplate.new end |
Instance Method Details
#do_the_pdf(pdfs_to_html) ⇒ Object
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 |
# File 'lib/pdf2img.rb', line 7 def do_the_pdf(pdfs_to_html) p pdfs_to_html html_pdf_imgs = [] pdfs_to_html.each do |file| if file.include? " " File.rename(file, file.gsub(" ","_")) file = file.gsub(" ","_") end pdf_folder_name = File.basename(file, ".*") Dir.mkdir(pdf_folder_name) p file imgs_from_pdf = Magick::Image.read(file) { self.density = 300 } imgs_from_pdf.each_with_index do |img,idx| img_tag = ['<img src="', '" alt="">'] img_tag.insert(1,"#{pdf_folder_name}/#{pdf_folder_name}_#{idx}.png") html_pdf_imgs << img_tag.join img.write(pdf_folder_name+"/#{pdf_folder_name}_#{idx}.png") { self.quality = 100} end temp = @bp.pdf_html temp = temp.split(/(<body>)/) temp.insert(2,html_pdf_imgs.join("\n")) temp = temp.join puts temp File.open(pdf_folder_name+".html", "w+") do |f| f.write(temp) end end end |