Sha256: 23d4ce07de75383538ddbd0c2a13c0825edf23ebabefae86145a92f102833024

Contents?: true

Size: 1.3 KB

Versions: 5

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

require 'pdf-reader'

module PWN
  module Plugins
    # This plugin is used for parsing and interacting with PDF files
    module PDFParse
      # Supported Method Parameters::
      # PWN::Plugins::PDFParse.read_text(
      #   pdf_path: 'optional path to dir defaults to .'
      # )

      public_class_method def self.read_text(opts = {})
        pdf_path = opts[:pdf_path].to_s.scrub if File.exist?(opts[:pdf_path].to_s.scrub)
        raise "PWN Error: Invalid Directory #{pdf_path}" if pdf_path.nil?

        pdf_pages_hash = {}
        page_no = 1
        reader = PDF::Reader.new(pdf_path)
        reader.pages.each do |page|
          print '.'
          pdf_pages_hash[page_no] = page.text
          page_no += 1
        end
        print "\n"
        pdf_pages_hash
      rescue StandardError => e
        raise e
      end

      # Author(s):: Jacob Hoopes <jake.hoopes@gmail.com>

      public_class_method def self.authors
        "AUTHOR(S):
          Jacob Hoopes <jake.hoopes@gmail.com>
        "
      end

      # Display Usage for this Module

      public_class_method def self.help
        puts "USAGE:
          pdf_pages_hash = #{self}.read_text(
            pdf_path: 'required path to pdf file'
          )

          #{self}.authors
        "
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pwn-0.4.340 lib/pwn/plugins/pdf_parse.rb
pwn-0.4.339 lib/pwn/plugins/pdf_parse.rb
pwn-0.4.338 lib/pwn/plugins/pdf_parse.rb
pwn-0.4.336 lib/pwn/plugins/pdf_parse.rb
pwn-0.4.333 lib/pwn/plugins/pdf_parse.rb