summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2019-07-15 13:58:45 -0600
committerDan Allen <dan.j.allen@gmail.com>2019-07-16 00:16:01 -0600
commite71ae06f3888f9db5a298b34de21b398dba5b6d5 (patch)
tree3a61fb941a0235a73a002f4bb684cfa36f5e8d8a /scripts
parentcfec7bf39c01c9117faaf8d85298e0d76c8f0cc2 (diff)
add helper script to decode a PDF string (for debugging) [skip ci]
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/decode-pdf-string29
1 files changed, 29 insertions, 0 deletions
diff --git a/scripts/decode-pdf-string b/scripts/decode-pdf-string
new file mode 100755
index 00000000..f4198ddf
--- /dev/null
+++ b/scripts/decode-pdf-string
@@ -0,0 +1,29 @@
+#!/usr/bin/env ruby
+
+str = ARGV[0]
+
+def string_object_to_utf16 str
+ [str.force_encoding(::Encoding::US_ASCII)].pack('H*').force_encoding ::Encoding::UTF_16BE
+end
+
+def string_object_to_utf8 str
+ [str.force_encoding(::Encoding::US_ASCII)].pack('H*').force_encoding ::Encoding::UTF_8
+end
+
+def utf16_to_utf8 str
+ str.encode ::Encoding::UTF_8
+end
+
+def decode_hexified_utf16_string_object str
+ utf16_to_utf8 string_object_to_utf16 str
+end
+
+def decode_hexified_utf8_string_object str
+ string_object_to_utf8 str
+end
+
+if ARGV[1] == 'utf8'
+ puts decode_hexified_utf8_string_object ARGV[0].dup
+else
+ puts decode_hexified_utf16_string_object ARGV[0].dup
+end