[NTG-context] Re: cannot sign document

2026-03-04 Thread Pablo Rodriguez via ntg-context
On 3/4/26 22:05, Hans Hagen via ntg-context wrote:
> On 3/4/2026 7:52 PM, Pablo Rodriguez via ntg-context wrote:
>> mtxrun --script pdf --sign --certificate just-testing.pfx
>> sign-test.pdf
> 
> This one too? If so, I need a complete test example.

Many thanks for your fast reply, Hans.

Your `mtx-pdf.lua` fixed the issue for me.

Many thanks for your help,

Pablo
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : [email protected] / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___


[NTG-context] Re: cannot sign document

2026-03-04 Thread Hans Hagen via ntg-context

On 3/4/2026 7:52 PM, Pablo Rodriguez via ntg-context wrote:

mtxrun --script pdf --sign --certificate just-testing.pfx
sign-test.pdf


This one too? If so, I need a complete test example.

Hans


-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
   tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-if not modules then modules = { } end modules ['mtx-pdf'] = {
version   = 1.001,
comment   = "companion to mtxrun.lua",
author= "Hans Hagen, PRAGMA-ADE, Hasselt NL",
copyright = "PRAGMA ADE / ConTeXt Development Team",
license   = "see context related readme files"
}

local tonumber = tonumber
local format, gmatch, gsub, match, find = string.format, string.gmatch, 
string.gsub, string.match, string.find
local utfchar = utf.char
local formatters = string.formatters
local concat, insert, swapped = table.concat, table.insert, table.swapped
local setmetatableindex, sortedhash, sortedkeys = table.setmetatableindex, 
table.sortedhash, table.sortedkeys

local helpinfo = [[


 
  mtx-pdf
  ConTeXt PDF Helpers
  0.20
 
 
  
   
show some info about the given file
show metadata xml blob
show formdata
replace newlines in metadata
show used fonts ()
show object
show links
show highlights
show comments
sign document (assumes signature 
template)
verify document
validate document (calls 
verapdf)
print detail to the console
print userdata to the console
check the (context specific) structure of the 
content
   
   
mtxrun --script pdf --info foo.pdf
mtxrun --script pdf --metadata foo.pdf
mtxrun --script pdf --metadata --pretty 
foo.pdf
mtxrun --script pdf --stream=4 foo.pdf
mtxrun --script pdf --sign --certificate=somesign.pem 
--password=test --uselibrary somefile
mtxrun --script pdf --verify --certificate=somesign.pem 
--password=test --uselibrary somefile
mtxrun --script pdf --detail=nofpages 
somefile
mtxrun --script pdf --userdata=keylist 
[--format=lua|json|lines] somefile
mtxrun --script pdf --validate --structure --details 
--save somefile
   
  
 

]]

local application = logs.application {
name = "mtx-pdf",
banner   = "ConTeXt PDF Helpers 0.20",
helpinfo = helpinfo,
}

local report   = application.report
local findfile = resolvers.findfile

if not pdfe then
dofile(findfile("lpdf-epd.lua","tex"))
elseif CONTEXTLMTXMODE then
local fullname
dofile(findfile("util-dim.lua","tex"))
dofile(findfile("lpdf-ini.lmt","tex"))
dofile(findfile("lpdf-pde.lmt","tex"))
dofile(findfile("lpdf-sig.lmt","tex"))
fullname = findfile("lpdf-crp.lmt","tex") if fullname and fullname ~= "" 
then dofile(fullname) end
else
dofile(findfile("lpdf-pde.lua","tex"))
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")
end
filename = file.addsuffix(filename,"pdf")
if not lfs.isfile(filename) then
report("unknown file %a",filename)
else
local ownerpassword = environment.arguments.ownerpassword
local userpassword  = environment.arguments.userpassword
if not ownerpassword then
ownerpassword = userpassword
end
if not userpassword then
userpassword = ownerpassword
end
local pdffile = lpdf.epdf.load(filename,userpassword,ownerpassword)
if pdffile then
return pdffile
else
report("no valid pdf file %a",filename)
end
end
end

-- Looks like we can get (even from programs using the adobe library):
--
-- 1 0 obj << /Metadata 3 0 R >> endobj
-- 3 0 obj << /Subtype /XML /Type /Metadata /Length 9104 >> stream ...
-- 2 0 obj << /Metadata 4 0 R /Subtype /XML /Type /Metadata >> endobj
-- 4 0 obj << /Length 9104 >> stream ...

do

-- This is a goodie. Checking came up in the ctx chat (HHR) in relation
-- to conversion and newer (lossless jpeg) file formats (not in pdf) but
-- that could be dealt with later (at least get the size and resolution
-- info).

-- todo : svg
-- todo : pdf (similar table)
-- todo : jbig jbig2 jb2 (if needed)

local graphics = nil

function scripts.pdf.identify(filename)
if graphics == nil then
graphics = require("grph-img.lua") or false
end
if graphics then
local info = graphics.identify(filename)
if info and info.length then
report("filename: %s",filename)
report("filetype: %s",info.filetype)
report("filesize: %s",info.length)