Class: PdfParadise::ToPdf

Inherits:
Base
  • Object
show all
Defined in:
lib/pdf_paradise/utility_scripts/to_pdf.rb

Overview

PdfParadise::ToPdf

Constant Summary

Constants inherited from Base

Base::NAMESPACE

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#basename, #be_verbose?, #change_directory, #commandline_arguments?, #copy_file, #delete_file, #e, #ecomment, #esystem, #first_argument?, #gold, #infer_the_namespace, #input_without_leading_hyphens?, #internal_hash?, #is_an_image_file?, #is_on_roebe?, #lightsteelblue, #log_dir?, #mkdir, #mv, #n_pages?, #namespace?, #no_file_at, #opne, #opnn, #orange, #reset_the_internal_hash, #return_commandline_arguments_starting_with_hyphens, #return_files_from_the_commandline_arguments, #return_pwd, #rev, #set_be_quiet, #set_commandline_arguments, #steelblue, #try_to_ensure_that_this_directory_exists, #write_what_into

Constructor Details

#initialize(commandline_arguments = nil, run_already = true) ⇒ ToPdf

#

initialize

#


23
24
25
26
27
28
29
30
31
32
# File 'lib/pdf_paradise/utility_scripts/to_pdf.rb', line 23

def initialize(
    commandline_arguments = nil,
    run_already           = true
  )
  reset
  set_commandline_arguments(
    commandline_arguments
  )
  run if run_already
end

Class Method Details

.[](i = ARGV) ⇒ Object

#

PdfParadise::ToPdf[]

#


94
95
96
# File 'lib/pdf_paradise/utility_scripts/to_pdf.rb', line 94

def self.[](i = ARGV)
  new(i)
end

Instance Method Details

#convert_this_docx_file(i) ⇒ Object

#

convert_this_docx_file

#


60
61
62
63
64
# File 'lib/pdf_paradise/utility_scripts/to_pdf.rb', line 60

def convert_this_docx_file(i)
  _ = "soffice --headless --invisible --convert-to pdf #{i}"
  e _
  system _
end

#handle_this_directory(i) ⇒ Object

#

handle_this_directory

#


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/pdf_paradise/utility_scripts/to_pdf.rb', line 69

def handle_this_directory(i)
  require 'image_paradise/toplevel_methods/misc.rb'
  require 'pdf_paradise/merge_pdf/merge_pdf.rb'
  i = i.dup
  i << '/' unless i.end_with?('/')
  e "#{rev}First, we will obtain all image files "\
    "of the directory #{sdir(i)}:"
  all_image_files = Dir["#{i}*"].select {|entry|
    is_an_image_file?(entry)
  }
  result = all_image_files.map {|this_image_file|
    this_image_file = ::ImageParadise.img2pdf(this_image_file)
    this_image_file
  }
  e 'Next merging these generated files into a new .pdf file:'
  merge_pdf = PdfParadise::MergePdf.new(result)
  _ = merge_pdf.where_it_is_stored? # Call it manually.
  opnn; e 'If everything worked well then the resulting '\
          '.pdf file can'
  opnn; e 'be found at: '+sfile(_)
end

#resetObject

#

reset (reset tag)

#


37
38
39
40
# File 'lib/pdf_paradise/utility_scripts/to_pdf.rb', line 37

def reset
  super()
  infer_the_namespace
end

#runObject

#

run (run tag)

#


45
46
47
48
49
50
51
52
53
54
55
# File 'lib/pdf_paradise/utility_scripts/to_pdf.rb', line 45

def run
  commandline_arguments?.each {|entry|
    if entry.end_with?('.docx','.pptx')
      convert_this_docx_file(entry)
    elsif File.directory?(entry)
      handle_this_directory(File.absolute_path(entry))
    else
      opnn; e "Unsure what to do with #{steelblue(entry)}."
    end
  }
end