Jonathan Sauer wrote:
function convertPDFstring(s) -- UTF-16 BOM sprint(char(0x110000 + 254)) sprint(char(0x110000 + 255))
-- The string for c in string.utfvalues(s) do if c < 0x10000 then sprint(char(0x110000 + c / 256)) sprint(char(0x110000 + c % 256)) else c = c - 0x10000 local c1 = c / 1024 + 0xD800 local c2 = c % 1024 + 0xDC00 sprint(char(0x110000 + c1 / 256)) sprint(char(0x110000 + c1 % 256)) sprint(char(0x110000 + c2 / 256)) sprint(char(0x110000 + c2 % 256)) end end end
slightly more efficient ... (char and byte accept multiple arguments) and you can use write which is faster too) local char = unicode.utf8.char local write = tex.write function convertPDFstring(s) write(char(0x110000+254,0x110000+255)) for c in string.utfvalues(s) do if c < 0x10000 then write(char(0x110000+c/256,0x110000+c%256)) else c = c - 0x10000 local c1 = c / 1024 + 0xD800 local c2 = c % 1024 + 0xDC00 write(char(0x110000+c1/256,0x110000+c1%256,0x110000+c2/256,0x110000+c2%256)) end end end
\pdfinfo{/Title(\directlua0{convertPDFstring('my title')})}
in context i use something quick and dirty (no > 0x10000 checking but from your function i can deduce the magic umbers -) function pdf.hexify(str) texwrite("feff") for b in str:utfvalues() do texwrite(("%04x"):format(b)) end end \pdfinfo{/Title(\directlua0{pdf.hexify<'my title'>})} so <> instead of () as string delimiter ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------