Fix wrong escape of metadata when using UTF-16 (#618)

This commit is contained in:
Fyodor 2017-05-30 07:10:01 +03:00 committed by Devon Govett
parent 55147c4412
commit ed07a06223

View File

@ -38,10 +38,7 @@ class PDFObject
# String objects are converted to PDF strings (UTF-16)
else if object instanceof String
# Escape characters as required by the spec
string = object.replace escapableRe, (c) ->
return escapable[c]
string = object
# Detect if this is a unicode string
isUnicode = false
for i in [0...string.length] by 1
@ -53,6 +50,10 @@ class PDFObject
if isUnicode
string = swapBytes(new Buffer('\ufeff' + string, 'utf16le')).toString('binary')
# Escape characters as required by the spec
string = string.replace escapableRe, (c) ->
return escapable[c]
'(' + string + ')'
# Buffers are converted to PDF hex strings