class PDFWalker::Walker
Attributes
explore_history[R]
opened[R]
Public Instance Methods
about()
click to toggle source
# File lib/pdfwalker/about.rb, line 25 def about AboutDialog.show(self, name: "PDF Walker", program_name: "PDF Walker", version: "#{PDFWalker::VERSION}", copyright: "Copyright © 2017\nGuillaume Delugré", comments: "A PDF file explorer, based on Origami", license: File.read(File.join(__dir__, "../..", "COPYING")), wrap_license: true, ) end
close()
click to toggle source
# File lib/pdfwalker/file.rb, line 29 def close @opened = nil @filename = '' @explorer_history.clear @treeview.clear @objectview.clear @hexview.clear # disable all menus. [ @file_menu_close, @file_menu_saveas, @file_menu_refresh, @document_menu_search, @document_menu_gotocatalog, @document_menu_gotodocinfo, @document_menu_gotometadata, @document_menu_gotopage, @document_menu_gotofield, @document_menu_gotorev, @document_menu_gotoobj, @document_menu_properties, @document_menu_sign, @document_menu_ur ].each do |menu| menu.sensitive = false end @statusbar.pop(@main_context) GC.start end
display_file_properties()
click to toggle source
# File lib/pdfwalker/properties.rb, line 27 def display_file_properties Properties.new(self, @opened) if @opened end
display_signing_wizard()
click to toggle source
# File lib/pdfwalker/signing.rb, line 25 def display_signing_wizard SignWizard.new(self, @opened) if @opened end
display_usage_rights_wizard()
click to toggle source
# File lib/pdfwalker/signing.rb, line 29 def display_usage_rights_wizard UsageRightsWizard.new(self, @opened) if @opened end
open(filename = nil)
click to toggle source
# File lib/pdfwalker/file.rb, line 54 def open(filename = nil) dialog = Gtk::FileChooserDialog.new("Open PDF File", self, FileChooser::ACTION_OPEN, nil, [Stock::CANCEL, Dialog::RESPONSE_CANCEL], [Stock::OPEN, Dialog::RESPONSE_ACCEPT]) last_file = @config.recent_files.first unless last_file.nil? last_folder = File.dirname(last_file) dialog.set_current_folder(last_folder) if File.directory?(last_folder) end dialog.filter = FileFilter.new.add_pattern("*.acrodata").add_pattern("*.pdf").add_pattern("*.fdf") if filename.nil? and dialog.run != Gtk::Dialog::RESPONSE_ACCEPT dialog.destroy return end create_progressbar filename ||= dialog.filename dialog.destroy begin document = start_profiling do parse_file(filename) end set_active_document(filename, document) rescue error("Error while parsing file.\n#{$!} (#{$!.class})\n" + $!.backtrace.join("\n")) ensure close_progressbar self.activate_focus end end
save()
click to toggle source
# File lib/pdfwalker/file.rb, line 119 def save dialog = Gtk::FileChooserDialog.new("Save PDF file", self, Gtk::FileChooser::ACTION_SAVE, nil, [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL], [Gtk::Stock::SAVE, Gtk::Dialog::RESPONSE_ACCEPT] ) dialog.filter = FileFilter.new.add_pattern("*.acrodata").add_pattern("*.pdf").add_pattern("*.fdf") folder = File.dirname(@filename) dialog.set_current_folder(folder) if dialog.run == Gtk::Dialog::RESPONSE_ACCEPT begin @opened.save(dialog.filename) rescue error("#{$!.class}: #{$!.message}\n#{$!.backtrace.join($/)}") end end dialog.destroy end
save_data(caption, data, filename = "")
click to toggle source
# File lib/pdfwalker/file.rb, line 95 def save_data(caption, data, filename = "") dialog = Gtk::FileChooserDialog.new(caption, self, Gtk::FileChooser::ACTION_SAVE, nil, [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL], [Gtk::Stock::SAVE, Gtk::Dialog::RESPONSE_ACCEPT] ) dialog.do_overwrite_confirmation = true dialog.current_name = File.basename(filename) dialog.filter = FileFilter.new.add_pattern("*.*") if dialog.run == Gtk::Dialog::RESPONSE_ACCEPT begin File.binwrite(dialog.filename, data) rescue error("Error: #{$!.message}") end end dialog.destroy end
show_xrefs(target)
click to toggle source
# File lib/pdfwalker/xrefs.rb, line 24 def show_xrefs(target) XrefsDialog.new(self, target) end
Private Instance Methods
close_progressbar()
click to toggle source
# File lib/pdfwalker/file.rb, line 316 def close_progressbar @progresswin.close end
create_hexview()
click to toggle source
# File lib/pdfwalker/hexview.rb, line 28 def create_hexview @hexview = DumpView.new(self) end
create_objectview()
click to toggle source
# File lib/pdfwalker/textview.rb, line 27 def create_objectview @objectview = ObjectView.new(self) end
create_progressbar()
click to toggle source
# File lib/pdfwalker/file.rb, line 310 def create_progressbar @progresswin = Dialog.new("Parsing file...", self, Dialog::MODAL) @progresswin.vbox.add(@progressbar = ProgressBar.new.set_pulse_step(0.05)) @progresswin.show_all end
create_treeview()
click to toggle source
# File lib/pdfwalker/treeview.rb, line 27 def create_treeview @treeview = PDFTree.new(self).set_headers_visible(false) colcontent = Gtk::TreeViewColumn.new("Names", Gtk::CellRendererText.new.set_foreground_set(true).set_background_set(true), text: PDFTree::TEXTCOL, weight: PDFTree::WEIGHTCOL, style: PDFTree::STYLECOL, foreground: PDFTree::FGCOL, background: PDFTree::BGCOL ) @treeview.append_column(colcontent) end
detect_file_type(path)
click to toggle source
# File lib/pdfwalker/file.rb, line 296 def detect_file_type(path) supported_types = [ Origami::PDF, Origami::FDF, Origami::PPKLite ] File.open(path, 'rb') do |file| data = file.read(128) supported_types.each do |type| return type if data.match(type::Header::MAGIC) end end nil end
parse_file(path)
click to toggle source
# File lib/pdfwalker/file.rb, line 238 def parse_file(path) # # Try to detect the file type of the document. # Fallback to PDF if none is found. # file_type = detect_file_type(path) if file_type.nil? file_type = Origami::PDF force_mode = true else force_mode = false end file_type.read(path, verbosity: Origami::Parser::VERBOSE_TRACE, ignore_errors: false, callback: method(:update_progressbar), prompt_password: method(:prompt_password), force: force_mode ) end
prompt_password()
click to toggle source
# File lib/pdfwalker/file.rb, line 265 def prompt_password passwd = "" dialog = Gtk::Dialog.new( "This document is encrypted", nil, Gtk::Dialog::MODAL, [ Gtk::Stock::OK, Gtk::Dialog::RESPONSE_OK ], [ Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL ] ) dialog.set_default_response(Gtk::Dialog::RESPONSE_OK) label = Gtk::Label.new("Please enter password:") entry = Gtk::Entry.new entry.signal_connect('activate') { dialog.response(Gtk::Dialog::RESPONSE_OK) } dialog.vbox.add(label) dialog.vbox.add(entry) dialog.show_all dialog.run do |response| passwd = entry.text if response == Gtk::Dialog::RESPONSE_OK end dialog.destroy passwd end
set_active_document(filename, document)
click to toggle source
# File lib/pdfwalker/file.rb, line 146 def set_active_document(filename, document) close if @opened @opened = document @filename = filename @config.last_opened_file(filename) @config.save update_recent_menu @last_search_result = [] @last_search = { :expr => "", :regexp => false, :type => :body } self.reload # Enable basic file menus. [ @file_menu_close, @file_menu_refresh, ].each do |menu| menu.sensitive = true end @explorer_history.clear @statusbar.push(@main_context, "Viewing #{filename}") setup_pdf_interface if @opened.is_a?(Origami::PDF) end
setup_pdf_interface()
click to toggle source
# File lib/pdfwalker/file.rb, line 179 def setup_pdf_interface # Enable save and document menu. [ @file_menu_saveas, @document_menu_search, @document_menu_gotocatalog, @document_menu_gotopage, @document_menu_gotorev, @document_menu_gotoobj, @document_menu_properties, @document_menu_sign, @document_menu_ur ].each do |menu| menu.sensitive = true end @document_menu_gotodocinfo.sensitive = true if @opened.document_info? @document_menu_gotometadata.sensitive = true if @opened.metadata? @document_menu_gotofield.sensitive = true if @opened.form? setup_page_menu setup_field_menu setup_revision_menu goto_catalog end
update_progressbar(_obj)
click to toggle source
# File lib/pdfwalker/file.rb, line 260 def update_progressbar(_obj) @progressbar.pulse if @progressbar Gtk.main_iteration while Gtk.events_pending? end