summaryrefslogtreecommitdiff
path: root/scripts/context/lua/mtx-pdf.lua
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/context/lua/mtx-pdf.lua')
-rw-r--r--scripts/context/lua/mtx-pdf.lua150
1 files changed, 115 insertions, 35 deletions
diff --git a/scripts/context/lua/mtx-pdf.lua b/scripts/context/lua/mtx-pdf.lua
index ad115637b..2e73fa841 100644
--- a/scripts/context/lua/mtx-pdf.lua
+++ b/scripts/context/lua/mtx-pdf.lua
@@ -55,6 +55,8 @@ end
scripts = scripts or { }
scripts.pdf = scripts.pdf or { }
+local details = environment.argument("detail") or environment.argument("details")
+
local function loadpdffile(filename)
if not filename or filename == "" then
report("no filename given")
@@ -73,35 +75,87 @@ end
function scripts.pdf.info(filename)
local pdffile = loadpdffile(filename)
if pdffile then
- local catalog = pdffile.Catalog
- local info = pdffile.Info
- local pages = pdffile.pages
- local nofpages = pdffile.nofpages
+ local catalog = pdffile.Catalog
+ local info = pdffile.Info
+ local pages = pdffile.pages
+ local nofpages = pdffile.nofpages
- report("filename > %s",filename)
- report("pdf version > %s",catalog.Version)
- report("major version > %s",pdffile.majorversion or "?")
- report("minor version > %s",pdffile.minorversion or "?")
- report("number of pages > %s",nofpages)
- report("title > %s",info.Title)
- report("creator > %s",info.Creator)
- report("producer > %s",info.Producer)
- report("creation date > %s",info.CreationDate)
- report("modification date > %s",info.ModDate)
+ local unset = "<unset>"
- local width, height, start
- for i=1, nofpages do
- local page = pages[i]
- local bbox = page.CropBox or page.MediaBox or { 0, 0, 0, 0 }
- local w, h = bbox[4]-bbox[2],bbox[3]-bbox[1]
- if w ~= width or h ~= height then
- if start then
- report("cropbox > pages: %s-%s, width: %s, height: %s",start,i-1,width,height)
+ report("%-17s > %s","filename", filename)
+ report("%-17s > %s","pdf version", catalog.Version or unset)
+ report("%-17s > %s","major version", pdffile.majorversion or unset)
+ report("%-17s > %s","minor version", pdffile.minorversion or unset)
+ report("%-17s > %s","number of pages", nofpages or 0)
+ report("%-17s > %s","title", info.Title or unset)
+ report("%-17s > %s","creator", info.Creator or unset)
+ report("%-17s > %s","producer", info.Producer or unset)
+ report("%-17s > %s","creation date", info.CreationDate or unset)
+ report("%-17s > %s","modification date", info.ModDate or unset)
+
+ local function somebox(what)
+ local box = string.lower(what)
+ local width, height, start
+ for i=1, nofpages do
+ local page = pages[i]
+ local bbox = page[what] or page.MediaBox or { 0, 0, 0, 0 }
+ local w, h = bbox[4]-bbox[2],bbox[3]-bbox[1]
+ if w ~= width or h ~= height then
+ if start then
+ report("%-17s > pages: %s-%s, width: %s, height: %s",box,start,i-1,width,height)
+ end
+ width, height, start = w, h, i
end
- width, height, start = w, h, i
end
+ report("%-17s > pages: %s-%s, width: %s, height: %s",box,start,nofpages,width,height)
+ end
+
+ if details then
+ somebox("MediaBox")
+ somebox("ArtBox")
+ somebox("BleedBox")
+ somebox("CropBox")
+ somebox("TrimBox")
+ else
+ somebox("CropBox")
end
- report("cropbox > pages: %s-%s, width: %s, height: %s",start,nofpages,width,height)
+
+ -- if details then
+ local annotations = 0
+ for i=1, nofpages do
+ local page = pages[i]
+ local a = page.Annots
+ if a then
+ annotations = annotations + #a
+ end
+ end
+ if annotations > 0 then
+ report("%-17s > %s", "annotations",annotations)
+ end
+ -- end
+
+ -- if details then
+ local d = pdffile.destinations
+ local k = d and sortedkeys(d)
+ if k and #k > 0 then
+ report("%-17s > %s", "destinations",#k)
+ end
+ local d = pdffile.javascripts
+ local k = d and sortedkeys(d)
+ if k and #k > 0 then
+ report("%-17s > %s", "javascripts",#k)
+ end
+ local d = pdffile.widgets
+ if d and #d > 0 then
+ report("%-17s > %s", "widgets",#d)
+ end
+ local d = pdffile.embeddedfiles
+ local k = d and sortedkeys(d)
+ if k and #k > 0 then
+ report("%-17s > %s", "embeddedfiles",#k)
+ end
+ -- end
+
end
end
@@ -206,13 +260,18 @@ function scripts.pdf.fonts(filename)
local codes = { }
local chars = { }
local freqs = { }
+ local names = { }
if counts then
codes = sortedkeys(counts)
for i=1,#codes do
local k = codes[i]
- local c = utfchar(k)
- chars[i] = c
- freqs[i] = format("U+%05X %s %s",k,counts[k] > 1 and "+" or " ", c)
+ if k > 32 then
+ local c = utfchar(k)
+ chars[i] = c
+ freqs[i] = format("U+%05X %s %s",k,counts[k] > 1 and "+" or " ", c)
+ else
+ freqs[i] = format("U+%05X %s --",k,counts[k] > 1 and "+" or " ")
+ end
end
if basefont and unicode then
local b = gsub(basefont,"^.*%+","")
@@ -225,26 +284,40 @@ function scripts.pdf.fonts(filename)
codes[i] = format("U+%05X",codes[i])
end
end
+ local d = encoding and encoding.Differences
+ if d then
+ for i=1,#d do
+ local di = d[i]
+ if type(di) == "string" then
+ names[#names+1] = di
+ end
+ end
+ end
found[k] = {
basefont = basefont or "no basefont",
- encoding = encoding or "no encoding",
+ encoding = (d and "custom n=" .. #d) or "no encoding",
subtype = subtype or "no subtype",
- unicode = tounicode and "unicode" or "no unicode",
+ unicode = tounicode and "unicode" or "no vector",
chars = chars,
codes = codes,
freqs = freqs,
+ names = names,
}
end
- if environment.argument("detail") or environment.argument("details") then
+ if details then
for k, v in sortedhash(found) do
report("id : %s", k)
report("basefont : %s", v.basefont)
- report("encoding : %s", v.encoding)
+ report("encoding : % t", v.names)
report("subtype : %s", v.subtype)
report("unicode : %s", v.unicode)
- report("characters : % t", v.chars)
- report("codepoints : % t", v.codes)
+ if #v.chars > 0 then
+ report("characters : % t", v.chars)
+ end
+ if #v.codes > 0 then
+ report("codepoints : % t", v.codes)
+ end
report("")
end
for k, v in sortedhash(common) do
@@ -253,9 +326,16 @@ function scripts.pdf.fonts(filename)
report("")
end
else
- local results = { { "id", "basefont", "encoding", "subtype", "unicode", "characters" } }
+ local haschar = false
+ for k, v in sortedhash(found) do
+ if #v.chars > 0 then
+ haschar = true
+ break
+ end
+ end
+ local results = { { "id", "basefont", "encoding", "subtype", "unicode", haschar and "characters" or nil } }
for k, v in sortedhash(found) do
- results[#results+1] = { k, v.basefont, v.encoding, v.subtype, v.unicode, concat(v.chars," ") }
+ results[#results+1] = { k, v.basefont, v.encoding, v.subtype, v.unicode, haschar and concat(v.chars," ") or nil }
end
utilities.formatters.formatcolumns(results)
report(results[1])