--- lpdf-wid.lua.org 2011-02-08 22:41:44.000000000 +0300 +++ lpdf-wid.lua 2011-02-23 12:27:53.000000000 +0300 @@ -160,14 +160,14 @@ -- -local nofattachments, attachments, filestreams = 0, { }, { } +local nofattachments, attachments, filestreams, globfilestreams = 0, { }, { }, { } -- todo: hash and embed once local function flushembeddedfiles() - if next(filestreams) then + if next(globfilestreams) then local e = pdfarray() - for name, reference in next, filestreams do + for name, reference in next, globfilestreams do if reference then e[#e+1] = pdfstring(name) e[#e+1] = reference -- already a reference @@ -181,7 +181,7 @@ lpdf.registerdocumentfinalizer(flushembeddedfiles,"embeddedfiles") -function codeinjections.embedfile(filename) +function codeinjections.embedfile(filename,newname,description) local r = filestreams[filename] if r == false then return nil @@ -201,12 +201,28 @@ UF = pdfstring(newname or basename), EF = pdfdictionary { F = pdfreference(f) }, } + if description then + d["Desc"] = pdfstring(description) + end local r = pdfreference(pdfflushobject(d)) filestreams[filename] = r return r end end +function codeinjections.globattachfile(specification) + local filename = specification.filename + if not filename or filename == "" then + -- todo: message + return + end + local description = specification.description or "" + local newname = specification.newname or "" + if description == "" then description = nil end + if newname == "" then newname = nil end + globfilestreams[filename] = codeinjections.embedfile(filename,newname,description) +end + function codeinjections.attachfile(specification) local attachment = interactions.attachments.attachment(specification.label) if not attachment then @@ -239,6 +255,7 @@ AP = appearance, OC = analyzelayer(specification.layer), C = pdfcolorspec(specification.colormodel,specification.colorvalue), + T = pdfstring(label), } -- as soon as we can ask for the dimensions of an xform we can -- use them here