origami 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/README +1 -1
  2. data/bin/gui/hexview.rb +1 -1
  3. data/bin/gui/menu.rb +4 -4
  4. data/bin/gui/textview.rb +6 -4
  5. data/bin/gui/treeview.rb +4 -4
  6. data/bin/gui/walker.rb +1 -1
  7. data/bin/pdf2graph +1 -1
  8. data/bin/pdf2pdfa +1 -1
  9. data/bin/pdf2ruby +1 -1
  10. data/bin/pdfcocoon +1 -1
  11. data/bin/pdfcop +1 -1
  12. data/bin/pdfdecompress +1 -1
  13. data/bin/pdfdecrypt +1 -1
  14. data/bin/pdfencrypt +1 -1
  15. data/bin/pdfextract +75 -14
  16. data/bin/pdfmetadata +1 -1
  17. data/bin/shell/.irbrc +1 -1
  18. data/{origami.rb → lib/origami.rb} +3 -3
  19. data/{origami → lib/origami}/3d.rb +0 -0
  20. data/{origami → lib/origami}/acroform.rb +2 -2
  21. data/{origami → lib/origami}/actions.rb +0 -0
  22. data/{origami → lib/origami}/annotations.rb +0 -0
  23. data/{origami → lib/origami}/array.rb +0 -0
  24. data/{origami → lib/origami}/boolean.rb +0 -0
  25. data/{origami → lib/origami}/catalog.rb +0 -0
  26. data/{origami → lib/origami}/destinations.rb +0 -0
  27. data/{origami → lib/origami}/dictionary.rb +0 -0
  28. data/{origami → lib/origami}/docmdp.rb +0 -0
  29. data/{origami → lib/origami}/encryption.rb +9 -7
  30. data/{origami → lib/origami}/export.rb +0 -0
  31. data/lib/origami/extensions/fdf.rb +257 -0
  32. data/{origami/adobe → lib/origami/extensions}/ppklite.rb +3 -1
  33. data/{origami → lib/origami}/file.rb +0 -0
  34. data/{origami → lib/origami}/filters.rb +0 -0
  35. data/{origami → lib/origami}/filters/ascii.rb +0 -0
  36. data/{origami → lib/origami}/filters/ccitt.rb +0 -1
  37. data/{origami → lib/origami}/filters/crypt.rb +0 -0
  38. data/{origami → lib/origami}/filters/dct.rb +0 -0
  39. data/{origami → lib/origami}/filters/flate.rb +0 -0
  40. data/{origami → lib/origami}/filters/jbig2.rb +0 -0
  41. data/{origami → lib/origami}/filters/jpx.rb +0 -0
  42. data/{origami → lib/origami}/filters/lzw.rb +0 -0
  43. data/{origami → lib/origami}/filters/predictors.rb +0 -0
  44. data/{origami → lib/origami}/filters/runlength.rb +0 -0
  45. data/{origami → lib/origami}/font.rb +0 -0
  46. data/{origami → lib/origami}/functions.rb +0 -0
  47. data/{origami → lib/origami}/graphics.rb +0 -0
  48. data/{origami → lib/origami}/graphics/colors.rb +45 -23
  49. data/{origami → lib/origami}/graphics/instruction.rb +0 -0
  50. data/{origami → lib/origami}/graphics/path.rb +0 -0
  51. data/{origami → lib/origami}/graphics/patterns.rb +0 -0
  52. data/{origami → lib/origami}/graphics/render.rb +0 -0
  53. data/{origami → lib/origami}/graphics/state.rb +2 -2
  54. data/{origami → lib/origami}/graphics/text.rb +0 -0
  55. data/{origami → lib/origami}/graphics/xobject.rb +219 -0
  56. data/{origami → lib/origami}/header.rb +0 -0
  57. data/{origami → lib/origami}/javascript.rb +0 -0
  58. data/{origami → lib/origami}/linearization.rb +0 -0
  59. data/{origami → lib/origami}/metadata.rb +0 -0
  60. data/{origami → lib/origami}/name.rb +0 -0
  61. data/{origami → lib/origami}/null.rb +0 -0
  62. data/{origami → lib/origami}/numeric.rb +0 -0
  63. data/{origami → lib/origami}/obfuscation.rb +0 -0
  64. data/{origami → lib/origami}/object.rb +7 -2
  65. data/{origami → lib/origami}/outline.rb +0 -0
  66. data/{origami → lib/origami}/outputintents.rb +0 -0
  67. data/{origami → lib/origami}/page.rb +0 -0
  68. data/{origami → lib/origami}/parser.rb +76 -51
  69. data/{origami → lib/origami}/parsers/fdf.rb +9 -6
  70. data/{origami/parsers/pdf/linear.rb → lib/origami/parsers/pdf.rb} +31 -39
  71. data/lib/origami/parsers/pdf/linear.rb +84 -0
  72. data/lib/origami/parsers/ppklite.rb +93 -0
  73. data/{origami → lib/origami}/pdf.rb +6 -3
  74. data/{origami → lib/origami}/reference.rb +0 -0
  75. data/{origami → lib/origami}/signature.rb +170 -19
  76. data/{origami → lib/origami}/stream.rb +9 -0
  77. data/{origami → lib/origami}/string.rb +0 -0
  78. data/{origami → lib/origami}/trailer.rb +0 -0
  79. data/{origami → lib/origami}/webcapture.rb +0 -0
  80. data/{origami → lib/origami}/xfa.rb +0 -0
  81. data/{origami → lib/origami}/xreftable.rb +3 -7
  82. data/samples/README.txt +45 -0
  83. data/samples/actions/launch/calc.rb +87 -0
  84. data/samples/actions/launch/winparams.rb +22 -0
  85. data/samples/actions/loop/loopgoto.rb +24 -0
  86. data/samples/actions/loop/loopnamed.rb +21 -0
  87. data/samples/actions/named/named.rb +31 -0
  88. data/samples/actions/samba/smbrelay.rb +26 -0
  89. data/samples/actions/triggerevents/trigger.rb +75 -0
  90. data/samples/actions/webbug/submitform.js +26 -0
  91. data/samples/actions/webbug/webbug-browser.rb +68 -0
  92. data/samples/actions/webbug/webbug-js.rb +67 -0
  93. data/samples/actions/webbug/webbug-reader.rb +90 -0
  94. data/samples/attachments/attach.rb +40 -0
  95. data/samples/attachments/attached.txt +1 -0
  96. data/samples/crypto/crypto.rb +28 -0
  97. data/samples/digsig/signed.rb +46 -0
  98. data/samples/exploits/cve-2008-2992-utilprintf.rb +87 -0
  99. data/samples/exploits/cve-2009-0927-geticon.rb +65 -0
  100. data/samples/exploits/exploit_customdictopen.rb +55 -0
  101. data/samples/exploits/getannots.rb +69 -0
  102. data/samples/flash/flash.rb +31 -0
  103. data/samples/flash/helloworld.swf +0 -0
  104. data/samples/javascript/attached.txt +1 -0
  105. data/samples/javascript/js.rb +52 -0
  106. data/{tests → test}/ts_pdf.rb +1 -1
  107. metadata +109 -95
  108. data/origami/adobe/fdf.rb +0 -259
  109. data/origami/parsers/pdf.rb +0 -27
  110. data/origami/parsers/ppklite.rb +0 -86
  111. data/tests/dataset/test.dummycrt +0 -28
  112. data/tests/dataset/test.dummykey +0 -27
  113. data/tests/tc_actions.rb +0 -32
  114. data/tests/tc_annotations.rb +0 -85
  115. data/tests/tc_pages.rb +0 -37
  116. data/tests/tc_pdfattach.rb +0 -24
  117. data/tests/tc_pdfencrypt.rb +0 -110
  118. data/tests/tc_pdfnew.rb +0 -32
  119. data/tests/tc_pdfparse.rb +0 -98
  120. data/tests/tc_pdfsig.rb +0 -37
  121. data/tests/tc_streams.rb +0 -129
data/README CHANGED
@@ -27,7 +27,7 @@ INSTALL
27
27
 
28
28
  DIRECTORIES
29
29
 
30
- ``origami/``
30
+ ``lib/``
31
31
  Core scripts used to parse a PDF file. All objects and features are
32
32
  provided here.
33
33
 
data/bin/gui/hexview.rb CHANGED
@@ -49,7 +49,7 @@ module PDFWalker
49
49
 
50
50
  @valuebuffer.create_tag( "HexView",
51
51
  :weight => Pango::WEIGHT_BOLD,
52
- :foreground => "black",
52
+ #:foreground => "black",
53
53
  :family => "Courier",
54
54
  :scale => Pango::AttrScale::LARGE
55
55
  )
data/bin/gui/menu.rb CHANGED
@@ -152,14 +152,14 @@ module PDFWalker
152
152
  :Sensitive => true,
153
153
  :Callback => lambda { |widget, viewer, path|
154
154
  stm = viewer.model.get_value(viewer.model.get_iter(path), viewer.class::OBJCOL)
155
- w,h = stm[:Width], stm[:Height]
156
- bpp = stm[:BitsPerComponent] || 8
157
- bpr = (bpp >> 3) * 3 * w
155
+ w,h = stm.Width, stm.Height
156
+ bpc = stm.BitsPerComponent || 8
157
+ bpr = (bpc >> 3) * 3 * w
158
158
  data = stm.data
159
159
 
160
160
  begin
161
161
  imgview = ImgViewer.new
162
- if stm[:Filter] == :DCTDecode or (stm[:Filter].is_a?(Array) and stm[:Filter][0] == :DCTDecode)
162
+ if stm.Filter == :DCTDecode or (stm.Filter.is_a?(Array) and stm.Filter[0] == :DCTDecode)
163
163
  imgview.show_compressed_img data
164
164
  else
165
165
  imgview.show_raw_img data, w, h, bpp, bpr
data/bin/gui/textview.rb CHANGED
@@ -33,9 +33,7 @@ module PDFWalker
33
33
  private
34
34
 
35
35
  def create_objectview
36
-
37
36
  @objectview = ObjectView.new(self)
38
-
39
37
  end
40
38
 
41
39
  class ObjectView < Notebook
@@ -56,14 +54,18 @@ module PDFWalker
56
54
  @pdfpanel.add_with_viewport @pdfview
57
55
  append_page(@pdfpanel, Label.new("PDF Code"))
58
56
 
59
- @pdfbuffer.create_tag("Object", { :weight => Pango::WEIGHT_BOLD, :foreground => "darkblue", :family => "Courier", :scale => Pango::AttrScale::LARGE })
57
+ @pdfbuffer.create_tag("Object",
58
+ :weight => Pango::WEIGHT_BOLD,
59
+ :foreground => "darkblue",
60
+ :family => "Courier",
61
+ :scale => Pango::AttrScale::LARGE
62
+ )
60
63
 
61
64
  end
62
65
 
63
66
  def load(object)
64
67
 
65
68
  begin
66
-
67
69
  self.clear
68
70
 
69
71
  pdftag = "Object"
data/bin/gui/treeview.rb CHANGED
@@ -59,7 +59,7 @@ module PDFWalker
59
59
  FGCOL = 4
60
60
  BGCOL = 5
61
61
 
62
- @@appearance = Hash.new({ :Color => "black", :Weight => Pango::WEIGHT_NORMAL, :Style => Pango::STYLE_NORMAL })
62
+ @@appearance = Hash.new(:Weight => Pango::WEIGHT_NORMAL, :Style => Pango::STYLE_NORMAL)
63
63
 
64
64
  attr_reader :parent
65
65
 
@@ -368,7 +368,7 @@ module PDFWalker
368
368
 
369
369
  def reset_appearance
370
370
 
371
- @@appearance[:Filename] = {:Color => "black", :Weight => Pango::WEIGHT_BOLD, :Style => Pango::STYLE_NORMAL}
371
+ @@appearance[:Filename] = {:Weight => Pango::WEIGHT_BOLD, :Style => Pango::STYLE_NORMAL}
372
372
  @@appearance[:Header] = {:Color => "darkgreen", :Weight => Pango::WEIGHT_BOLD, :Style => Pango::STYLE_NORMAL}
373
373
  @@appearance[:Revision] = {:Color => "blue", :Weight => Pango::WEIGHT_BOLD, :Style => Pango::STYLE_NORMAL}
374
374
  @@appearance[:Body] = {:Color => "purple", :Weight => Pango::WEIGHT_BOLD, :Style => Pango::STYLE_NORMAL}
@@ -376,7 +376,7 @@ module PDFWalker
376
376
  @@appearance[:XRefSubSection] = {:Color => "brown", :Weight => Pango::WEIGHT_BOLD, :Style => Pango::STYLE_NORMAL}
377
377
  @@appearance[:XRef] = {:Color => "gray20", :Weight => Pango::WEIGHT_BOLD, :Style => Pango::STYLE_NORMAL}
378
378
  @@appearance[:Trailer] = {:Color => "purple", :Weight => Pango::WEIGHT_BOLD, :Style => Pango::STYLE_NORMAL}
379
- @@appearance[:StartXref] = {:Color => "black", :Weight => Pango::WEIGHT_BOLD, :Style => Pango::STYLE_NORMAL}
379
+ @@appearance[:StartXref] = {:Weight => Pango::WEIGHT_BOLD, :Style => Pango::STYLE_NORMAL}
380
380
  @@appearance[:String] = {:Color => "red", :Weight => Pango::WEIGHT_NORMAL, :Style => Pango::STYLE_ITALIC}
381
381
  @@appearance[:Name] = {:Color => "gray", :Weight => Pango::WEIGHT_NORMAL, :Style => Pango::STYLE_ITALIC}
382
382
  @@appearance[:Number] = {:Color => "orange", :Weight => Pango::WEIGHT_NORMAL, :Style => Pango::STYLE_NORMAL}
@@ -384,7 +384,7 @@ module PDFWalker
384
384
  @@appearance[:Stream] = {:Color => "darkcyan", :Weight => Pango::WEIGHT_BOLD, :Style => Pango::STYLE_NORMAL}
385
385
  @@appearance[:StreamData] = {:Color => "darkcyan", :Weight => Pango::WEIGHT_NORMAL, :Style => Pango::STYLE_OBLIQUE}
386
386
  @@appearance[:Array] = {:Color => "darkgreen", :Weight => Pango::WEIGHT_BOLD, :Style => Pango::STYLE_NORMAL}
387
- @@appearance[:Reference] = {:Color => "black", :Weight => Pango::WEIGHT_NORMAL, :Style => Pango::STYLE_OBLIQUE}
387
+ @@appearance[:Reference] = {:Weight => Pango::WEIGHT_NORMAL, :Style => Pango::STYLE_OBLIQUE}
388
388
  @@appearance[:Boolean] = {:Color => "deeppink", :Weight => Pango::WEIGHT_NORMAL, :Style => Pango::STYLE_NORMAL}
389
389
 
390
390
  end
data/bin/gui/walker.rb CHANGED
@@ -35,7 +35,7 @@ include Gtk
35
35
  begin
36
36
  require 'origami'
37
37
  rescue LoadError
38
- ORIGAMIDIR = "#{File.dirname(__FILE__)}/../.."
38
+ ORIGAMIDIR = "#{File.dirname(__FILE__)}/../../lib"
39
39
  $: << ORIGAMIDIR
40
40
  require 'origami'
41
41
  end
data/bin/pdf2graph CHANGED
@@ -27,7 +27,7 @@
27
27
  begin
28
28
  require 'origami'
29
29
  rescue LoadError
30
- ORIGAMIDIR = "#{File.dirname(__FILE__)}/.."
30
+ ORIGAMIDIR = "#{File.dirname(__FILE__)}/../lib"
31
31
  $: << ORIGAMIDIR
32
32
  require 'origami'
33
33
  end
data/bin/pdf2pdfa CHANGED
@@ -28,7 +28,7 @@
28
28
  begin
29
29
  require 'origami'
30
30
  rescue LoadError
31
- ORIGAMIDIR = "#{File.dirname(__FILE__)}/.."
31
+ ORIGAMIDIR = "#{File.dirname(__FILE__)}/../lib"
32
32
  $: << ORIGAMIDIR
33
33
  require 'origami'
34
34
  end
data/bin/pdf2ruby CHANGED
@@ -30,7 +30,7 @@ require 'ftools'
30
30
  begin
31
31
  require 'origami'
32
32
  rescue LoadError
33
- ORIGAMIDIR = "#{File.dirname(__FILE__)}/.."
33
+ ORIGAMIDIR = "#{File.dirname(__FILE__)}/../lib"
34
34
  $: << ORIGAMIDIR
35
35
  require 'origami'
36
36
  end
data/bin/pdfcocoon CHANGED
@@ -27,7 +27,7 @@
27
27
  begin
28
28
  require 'origami'
29
29
  rescue LoadError
30
- ORIGAMIDIR = "#{File.dirname(__FILE__)}/.."
30
+ ORIGAMIDIR = "#{File.dirname(__FILE__)}/../lib"
31
31
  $: << ORIGAMIDIR
32
32
  require 'origami'
33
33
  end
data/bin/pdfcop CHANGED
@@ -30,7 +30,7 @@
30
30
  begin
31
31
  require 'origami'
32
32
  rescue LoadError
33
- ORIGAMIDIR = "#{File.dirname(__FILE__)}/.."
33
+ ORIGAMIDIR = "#{File.dirname(__FILE__)}/../lib"
34
34
  $: << ORIGAMIDIR
35
35
  require 'origami'
36
36
  end
data/bin/pdfdecompress CHANGED
@@ -27,7 +27,7 @@
27
27
  begin
28
28
  require 'origami'
29
29
  rescue LoadError
30
- ORIGAMIDIR = "#{File.dirname(__FILE__)}/.."
30
+ ORIGAMIDIR = "#{File.dirname(__FILE__)}/../lib"
31
31
  $: << ORIGAMIDIR
32
32
  require 'origami'
33
33
  end
data/bin/pdfdecrypt CHANGED
@@ -27,7 +27,7 @@
27
27
  begin
28
28
  require 'origami'
29
29
  rescue LoadError
30
- ORIGAMIDIR = "#{File.dirname(__FILE__)}/.."
30
+ ORIGAMIDIR = "#{File.dirname(__FILE__)}/../lib"
31
31
  $: << ORIGAMIDIR
32
32
  require 'origami'
33
33
  end
data/bin/pdfencrypt CHANGED
@@ -27,7 +27,7 @@
27
27
  begin
28
28
  require 'origami'
29
29
  rescue LoadError
30
- ORIGAMIDIR = "#{File.dirname(__FILE__)}/.."
30
+ ORIGAMIDIR = "#{File.dirname(__FILE__)}/../lib"
31
31
  $: << ORIGAMIDIR
32
32
  require 'origami'
33
33
  end
data/bin/pdfextract CHANGED
@@ -30,7 +30,7 @@
30
30
  begin
31
31
  require 'origami'
32
32
  rescue LoadError
33
- ORIGAMIDIR = "#{File.dirname(__FILE__)}/.."
33
+ ORIGAMIDIR = "#{File.dirname(__FILE__)}/../lib"
34
34
  $: << ORIGAMIDIR
35
35
  require 'origami'
36
36
  end
@@ -42,7 +42,7 @@ require 'rexml/document'
42
42
  class OptParser
43
43
  BANNER = <<USAGE
44
44
  Usage: #{$0} <PDF-file> [-afjms] [-d <output-directory>]
45
- Extracts various data out of a document (streams, scripts, fonts, metadata, attachments).
45
+ Extracts various data out of a document (streams, scripts, images, fonts, metadata, attachments).
46
46
  Bug reports or feature requests at: http://origami-pdf.googlecode.com/
47
47
 
48
48
  Options:
@@ -76,6 +76,10 @@ USAGE
76
76
  options[:metadata] = true
77
77
  end
78
78
 
79
+ opts.on("-i", "--images", "Extracts embedded images") do
80
+ options[:images] = true
81
+ end
82
+
79
83
  opts.on_tail("-h", "--help", "Show this message") do
80
84
  puts opts
81
85
  exit
@@ -104,11 +108,12 @@ begin
104
108
  target = ARGV.shift
105
109
  end
106
110
 
107
- unless [:streams,:javascript,:attachments,:fonts,:metadata].any? {|opt| @options[opt]}
111
+ unless [:streams,:javascript,:attachments,:fonts,:metadata,:images].any? {|opt| @options[opt]}
108
112
  @options[:streams] =
109
113
  @options[:javascript] =
110
114
  @options[:fonts] =
111
- @options[:attachments] = true
115
+ @options[:attachments] =
116
+ @options[:images] = true
112
117
  end
113
118
 
114
119
  if @options[:output_dir].nil?
@@ -125,17 +130,26 @@ begin
125
130
  pdf = PDF.read(target, params)
126
131
 
127
132
  if @options[:streams]
133
+ nstreams = 0
134
+ Dir::mkdir("#{OUTPUT_DIR}/streams") unless File.directory?("#{OUTPUT_DIR}/streams")
135
+
128
136
  pdf.root_objects.find_all{|obj| obj.is_a?(Stream)}.each do |stream|
129
- stream_file = "#{OUTPUT_DIR}/stream_#{stream.reference.refno}.dmp"
137
+ stream_file = "#{OUTPUT_DIR}/streams/stream_#{stream.reference.refno}.dmp"
130
138
  File.open(stream_file, "w") do |fd|
131
139
  fd.write(stream.data)
132
140
  end
141
+ nstreams += 1
133
142
  end
143
+
144
+ puts "Extracted #{nstreams} PDF streams to '#{OUTPUT_DIR}/streams'."
134
145
  end
135
146
 
136
147
  if @options[:javascript]
148
+ nscripts = 0
149
+ Dir::mkdir("#{OUTPUT_DIR}/scripts") unless File.directory?("#{OUTPUT_DIR}/scripts")
150
+
137
151
  pdf.ls(/^JS$/).each do |script|
138
- script_file = "#{OUTPUT_DIR}/script_#{script.hash}.js"
152
+ script_file = "#{OUTPUT_DIR}/scripts/script_#{script.hash}.js"
139
153
  File.open(script_file, "w") do |fd|
140
154
  fd.write(
141
155
  case script
@@ -146,6 +160,7 @@ begin
146
160
  end
147
161
  )
148
162
  end
163
+ nscripts += 1
149
164
  end
150
165
 
151
166
  # Also checking for presence of JavaScript in XML forms.
@@ -175,42 +190,88 @@ begin
175
190
  File.open(script_file, 'w') do |fd|
176
191
  fd.write(script.text)
177
192
  end
193
+ nscripts += 1
178
194
  end
179
195
  end
196
+
197
+ puts "Extracted #{nscripts} scripts to '#{OUTPUT_DIR}/scripts'."
180
198
  end
181
199
 
182
200
  if @options[:attachments]
201
+ nattach = 0
202
+ Dir::mkdir("#{OUTPUT_DIR}/attachments") unless File.directory?("#{OUTPUT_DIR}/attachments")
203
+
183
204
  pdf.ls_names(Names::Root::EMBEDDEDFILES).each do |name, attachment|
184
- attached_file = "#{OUTPUT_DIR}/attached_#{File.basename(name)}"
205
+ attached_file = "#{OUTPUT_DIR}/attachments/attached_#{File.basename(name)}"
185
206
  spec = attachment.solve
186
- ef = spec[:EF].solve
187
- f = ef[:F].solve
188
-
189
- File.open(attached_file, "w") do |fd|
190
- fd.write(f.data)
207
+ if spec and spec.EF and f = spec.EF.F and f.is_a?(Stream)
208
+ File.open(attached_file, "w") do |fd|
209
+ fd.write(f.data)
210
+ end
211
+ nattach += 1
191
212
  end
192
213
  end
214
+
215
+ puts "Extracted #{nattach} attachments to '#{OUTPUT_DIR}/attachments'."
193
216
  end
194
217
 
195
218
  if @options[:fonts]
219
+ nfonts = 0
220
+ Dir::mkdir("#{OUTPUT_DIR}/fonts") unless File.directory?("#{OUTPUT_DIR}/fonts")
221
+
196
222
  pdf.root_objects.find_all{|obj| obj.is_a?(Stream)}.each do |stream|
197
223
  font = stream.xrefs.find{|obj| obj.is_a?(FontDescriptor)}
198
224
  if font
199
- font_file = "#{OUTPUT_DIR}/font_#{File.basename(font.FontName.value.to_s)}"
225
+ font_file = "#{OUTPUT_DIR}/fonts/font_#{File.basename(font.FontName.value.to_s)}"
200
226
  File.open(font_file, "w") do |fd|
201
227
  fd.write(stream.data)
202
228
  end
229
+ nfonts += 1
203
230
  end
204
231
  end
232
+
233
+ puts "Extracted #{nfonts} fonts to '#{OUTPUT_DIR}/fonts'."
205
234
  end
206
235
 
207
236
  if @options[:metadata]
237
+ nmeta = 0
238
+ Dir::mkdir("#{OUTPUT_DIR}/metadata") unless File.directory?("#{OUTPUT_DIR}/metadata")
239
+
208
240
  pdf.root_objects.find_all{|obj| obj.is_a?(MetadataStream)}.each do |stream|
209
- metadata_file = "#{OUTPUT_DIR}/metadata_#{stream.reference.refno}.xml"
241
+ metadata_file = "#{OUTPUT_DIR}/metadata/metadata_#{stream.reference.refno}.xml"
210
242
  File.open(metadata_file, "w") do |fd|
211
243
  fd.write(stream.data)
212
244
  end
245
+ nmeta += 1
246
+ end
247
+
248
+ puts "Extracted #{nmeta} metadata streams to '#{OUTPUT_DIR}/metadata'."
249
+ end
250
+
251
+ if @options[:images]
252
+ nimages = 0
253
+ Dir::mkdir("#{OUTPUT_DIR}/images") unless File.directory?("#{OUTPUT_DIR}/images")
254
+
255
+ pdf.root_objects.find_all{|obj| obj.is_a?(Graphics::ImageXObject)}.each do |stream|
256
+ begin
257
+ ext, image_data = stream.to_image_file
258
+ image_file = "#{OUTPUT_DIR}/images/image_#{stream.reference.refno}.#{ext}"
259
+
260
+ if ext != 'png' and stream.ColorSpace == Graphics::Color::Space::DEVICE_CMYK
261
+ STDERR.puts "Warning: file '#{image_file}' is intended to be viewed in CMYK color space."
262
+ end
263
+
264
+ File.open(image_file, "w") do |fd|
265
+ fd.write(image_data)
266
+ end
267
+ nimages += 1
268
+
269
+ rescue Exception => e
270
+ STDERR.puts "Unable to decode image (stream #{stream.reference.refno}). #{e.message}"
271
+ end
213
272
  end
273
+
274
+ puts "Extracted #{nimages} images to '#{OUTPUT_DIR}/images'."
214
275
  end
215
276
 
216
277
  rescue SystemExit
data/bin/pdfmetadata CHANGED
@@ -27,7 +27,7 @@
27
27
  begin
28
28
  require 'origami'
29
29
  rescue LoadError
30
- ORIGAMIDIR = "#{File.dirname(__FILE__)}/.."
30
+ ORIGAMIDIR = "#{File.dirname(__FILE__)}/../lib"
31
31
  $: << ORIGAMIDIR
32
32
  require 'origami'
33
33
  end
data/bin/shell/.irbrc CHANGED
@@ -1,7 +1,7 @@
1
1
  begin
2
2
  require 'origami'
3
3
  rescue LoadError
4
- ORIGAMIDIR = "#{File.dirname(__FILE__)}/../.."
4
+ ORIGAMIDIR = "#{File.dirname(__FILE__)}/../../lib"
5
5
  $: << ORIGAMIDIR
6
6
  require 'origami'
7
7
  end
@@ -30,7 +30,7 @@ if RUBY_VERSION < '1.9'
30
30
  end
31
31
  end
32
32
 
33
- require 'origami/parsers/pdf'
34
- require 'origami/parsers/fdf'
35
- require 'origami/parsers/ppklite'
33
+ require 'origami/pdf'
34
+ require 'origami/extensions/fdf'
35
+ require 'origami/extensions/ppklite'
36
36
 
File without changes
@@ -145,7 +145,7 @@ module Origami
145
145
  RIGHT = 2
146
146
  end
147
147
 
148
- def self.included(receiver)
148
+ def self.included(receiver) #:nodoc:
149
149
 
150
150
  receiver.field :FT, :Type => Name, :Default => Type::TEXT, :Required => true
151
151
  receiver.field :Parent, :Type => Dictionary
@@ -166,7 +166,7 @@ module Origami
166
166
 
167
167
  end
168
168
 
169
- def pre_build
169
+ def pre_build #:nodoc:
170
170
 
171
171
  if not self.T
172
172
  self.T = "undef#{::Array.new(5) {(0x30 + rand(10)).chr}.join}"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes