Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Unicode on PDFObject.s for CJK metadata #89

Merged
merged 1 commit into from Nov 10, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/object.coffee
Expand Up @@ -42,6 +42,20 @@ class PDFObject
'' + object '' + object


@s: (string) -> @s: (string) ->

# Convert Big-endian UCS-2 to Little-endian to support most PDFRreaders
swapBytes = (buff) ->
l = buff.length
if l & 0x01
throw new Error("Buffer length must be even")
else
for i in [0...l - 1] by 2
a = buff[i]
buff[i] = buff[i+1]
buff[i+1] = a
buff
string = swapBytes(new Buffer('\ufeff' + string, 'ucs-2')).toString('binary')

string = string.replace(/\\/g, '\\\\\\\\') string = string.replace(/\\/g, '\\\\\\\\')
.replace(/\(/g, '\\(') .replace(/\(/g, '\\(')
.replace(/\)/g, '\\)') .replace(/\)/g, '\\)')
Expand Down