gdelugre / origami

Origami is a pure Ruby library to parse, modify and generate PDF documents.
GNU Lesser General Public License v3.0
326 stars 110 forks source link

Failures with pdf2ruby #45

Closed zenspider closed 5 years ago

zenspider commented 6 years ago

I found a couple errors in the code itself but also an error in the generated code that I haven't tracked down. This is just a quick note in case you can nail these down and I can't (I've only just started looking at your code):

diff --git a/bin/pdf2ruby b/bin/pdf2ruby
index 0b56b26..09903d1 100755
--- a/bin/pdf2ruby
+++ b/bin/pdf2ruby
@@ -297,8 +297,8 @@ catalog = target.Catalog
 puts "[*] ".red + "Processing the object hierarchy..."
 @current_idx = 0
 while @current_idx != @obj_route.size
-    var_name = @obj_route[@current_idx]
-    obj = target[@var_hash.key(var_name)]
+    varname = @obj_route[@current_idx]
+    obj = target[@var_hash.key(varname)]

     @code_hash[varname] ||= {}
     @code_hash[varname][:body] = objectToRuby(obj, 0, varname, true)

The generation error results in code that has a missing class name so .new is a syntax error:

obj_218 =
.new(
  :Names => 
    ["subsection.1.2.2", obj_29, "subsection.1.2.3", obj_33, "subsection.1.3.1", obj_41, "subsection.1.3.2", obj_45, "subsection.1.3.3", obj_49, "subsection.1.3.4", obj_53], 
  :Limits => 
    ["subsection.1.2.2", "subsection.1.3.4"]
).to_o
zenspider commented 6 years ago

I don't read PDF/PS (yet?), but it looks like the source comes from:

218 0 obj <<
/Names [(subsection.1.2.2) 29 0 R (subsection.1.2.3) 33 0 R (subsection.1.3.1) 41 0 R (subsection.1.3.2) 45 0 R (subsection.1.3.3) 49 0 R (subsection.1.3.4) 53 0 R]
/Limits [(subsection.1.2.2) (subsection.1.3.4)]
>> endobj
gdelugre commented 5 years ago

Thank you, that was apparently something that was committed by mistake.