setting date in \setupinteraction
Dear list, I have the following sample: \setupinteraction[state=start, date={02.02.2022}] \starttext This document is from 02.02.2020 at 12:00:21. \stoptext Which is the right way to get PDF dates working with \setupinteraction? Many thanks for your help, Pablo -- http://www.ousia.tk
On Tue Oct 19, 2021 at 5:47 PM CEST, Pablo Rodriguez via ntg-context wrote:
Dear list,
I have the following sample:
\setupinteraction[state=start, date={02.02.2022}] \starttext This document is from 02.02.2020 at 12:00:21. \stoptext
Which is the right way to get PDF dates working with \setupinteraction?
According to lpdf-mis.lmt about the "date" parameter: -- users should enter the date in 2010-01-19T23:27:50+01:00 format -- and if not provided that way we use the creation time instead I can get this format also with `date --iso-8601=seconds` or the shorter `date -Iseconds`. So this works: \setupinteraction[state=start, date={2022-02-02T12:00:21+02:00}] \starttext This document is from 02.02.2020 at 12:00:21. \stoptext This parameter sets the "ModDate" is that what you are after? Seems that "CreationDate" could be set by the SOURCE_DATE_EPOCH environment variable, but I am not succesfull with it right now. Michal
On 10/19/21 6:23 PM, Michal Vlasák via ntg-context wrote:
On Tue Oct 19, 2021 at 5:47 PM CEST, Pablo Rodriguez via ntg-context wrote: [...] So this works:
\setupinteraction[state=start, date={2022-02-02T12:00:21+02:00}] \starttext This document is from 02.02.2020 at 12:00:21. \stoptext
This parameter sets the "ModDate" is that what you are after?
Hi Michal, many thanks for your fast reply. I would like to import both metadata values (CreationDate and ModDate) from another file (such as https://pdf.ousia.tk/metadata.pdf). Besides from the fact that LMTX doesn’t work with this (only MkIV does [already reported]), isn’t no simpler way to get ISO 8601 formatting from doc.Info.ModDate than the following one? \starttext \startluacode function document.transfer_metadata(name) local main_doc = lpdf.epdf.load(name) context.setupinteraction{ title = main_doc.Info.Title } context.setupinteraction{ date = main_doc.Info.ModDate:sub(3,6) .. "-" .. main_doc.Info.ModDate:sub(7,8) .. "-" .. main_doc.Info.ModDate:sub(9,10) .. "T" .. main_doc.Info.ModDate:sub(11,12) .. ":" .. main_doc.Info.ModDate:sub(13,14) .. ":" .. main_doc.Info.ModDate:sub(15,22):gsub("'", ":") } context(main_doc.Info.Title .. "\\par") lpdf.epdf.unload(name) end \stopluacode \unexpanded\def\TransferMetadata#1% {\ctxlua{document.transfer_metadata("#1")}} \startTEXpage[offset=1em, align=center] \TransferMetadata{metadata.pdf} \stopTEXpage \stoptext
Seems that "CreationDate" could be set by the SOURCE_DATE_EPOCH environment variable, but I am not succesfull with it right now.
It would be fine to ble able to set CreationDate. Otherwise, having a ModDate prior to CreationDate gives a weird impression. Many thanks for your help, Pablo -- http://www.ousia.tk
On Tue Oct 19, 2021 at 8:51 PM CEST, Pablo Rodriguez via ntg-context wrote:
On 10/19/21 6:23 PM, Michal Vlasák via ntg-context wrote:
On Tue Oct 19, 2021 at 5:47 PM CEST, Pablo Rodriguez via ntg-context wrote: [...] So this works:
\setupinteraction[state=start, date={2022-02-02T12:00:21+02:00}] \starttext This document is from 02.02.2020 at 12:00:21. \stoptext
This parameter sets the "ModDate" is that what you are after?
Hi Michal,
many thanks for your fast reply.
I would like to import both metadata values (CreationDate and ModDate) from another file (such as https://pdf.ousia.tk/metadata.pdf).
Besides from the fact that LMTX doesn’t work with this (only MkIV does [already reported]), isn’t no simpler way to get ISO 8601 formatting from doc.Info.ModDate than the following one?
\starttext \startluacode function document.transfer_metadata(name) local main_doc = lpdf.epdf.load(name) context.setupinteraction{ title = main_doc.Info.Title } context.setupinteraction{ date = main_doc.Info.ModDate:sub(3,6) .. "-" .. main_doc.Info.ModDate:sub(7,8) .. "-" .. main_doc.Info.ModDate:sub(9,10) .. "T" .. main_doc.Info.ModDate:sub(11,12) .. ":" .. main_doc.Info.ModDate:sub(13,14) .. ":" .. main_doc.Info.ModDate:sub(15,22):gsub("'", ":") } context(main_doc.Info.Title .. "\\par") lpdf.epdf.unload(name) end \stopluacode \unexpanded\def\TransferMetadata#1% {\ctxlua{document.transfer_metadata("#1")}} \startTEXpage[offset=1em, align=center] \TransferMetadata{metadata.pdf} \stopTEXpage \stoptext
Seems that "CreationDate" could be set by the SOURCE_DATE_EPOCH environment variable, but I am not succesfull with it right now.
It would be fine to ble able to set CreationDate. Otherwise, having a ModDate prior to CreationDate gives a weird impression.
I don't know how official these interfaces are. But you can try adapting the following to your use case. \setupinteraction[state=start] %\luacode{lpdf.settime("2020-02-02 12:00")} %\luacode{lpdf.settime(1580641221)} \startluacode local Y, M, D, h, m, s, Zs, Zh, Zm = string.match("D:20200202120021+02'00'", "^D:(%d%d%d%d)(%d%d)(%d%d)(%d%d)(%d%d)(%d%d)([%+%-])(%d%d)%'(%d%d)%'$") local time = os.time{year=Y,month=M,day=D,hour=h,min=m,sec=s} lpdf.settime(time) \stopluacode \starttext This document is from 02.02.2020 at 12:00:21. \stoptext The pattern doesn't catch all the PDF spec cases, but should match what ConTeXt emits. The timezone info gets overwritten by current timezone though. Requires the below patch. Michal --- a/tex/context/base/mkiv/core-con.lua +++ b/tex/context/base/mkiv/core-con.lua @@ -1991,7 +1991,7 @@ function converters.totime(s) end local n = tonumber(s) if n and n >= 0 then - return date("*t",n) + return osdate("*t",n) end end diff --git a/tex/context/base/mkxl/lpdf-ini.lmt b/tex/context/base/mkxl/lpdf-ini.lmt index 7979b80..9703ac0 100644 --- a/tex/context/base/mkxl/lpdf-ini.lmt +++ b/tex/context/base/mkxl/lpdf-ini.lmt @@ -1123,7 +1123,7 @@ do n = converters.totime(n) if n then converters.settime(n) - timestamp = osdate("%Y-%m-%dT%X") .. ostimezone(true) -- probably not ok + timestamp = osdate("%Y-%m-%dT%X", ostime(n)) .. ostimezone(true) -- probably not ok end end if metadata then
On 10/19/2021 10:38 PM, Michal Vlasák via ntg-context wrote:
I don't know how official these interfaces are. But you can try adapting the following to your use case.
\setupinteraction[state=start]
%\luacode{lpdf.settime("2020-02-02 12:00")} %\luacode{lpdf.settime(1580641221)}
\startluacode
local Y, M, D, h, m, s, Zs, Zh, Zm = string.match("D:20200202120021+02'00'", "^D:(%d%d%d%d)(%d%d)(%d%d)(%d%d)(%d%d)(%d%d)([%+%-])(%d%d)%'(%d%d)%'$")
local time = os.time{year=Y,month=M,day=D,hour=h,min=m,sec=s} lpdf.settime(time) \stopluacode
\starttext This document is from 02.02.2020 at 12:00:21. \stoptext
The pattern doesn't catch all the PDF spec cases, but should match what ConTeXt emits. The timezone info gets overwritten by current timezone though.
Requires the below patch.
Michal
--- a/tex/context/base/mkiv/core-con.lua +++ b/tex/context/base/mkiv/core-con.lua @@ -1991,7 +1991,7 @@ function converters.totime(s) end local n = tonumber(s) if n and n >= 0 then - return date("*t",n) + return osdate("*t",n) end end
diff --git a/tex/context/base/mkxl/lpdf-ini.lmt b/tex/context/base/mkxl/lpdf-ini.lmt index 7979b80..9703ac0 100644 --- a/tex/context/base/mkxl/lpdf-ini.lmt +++ b/tex/context/base/mkxl/lpdf-ini.lmt @@ -1123,7 +1123,7 @@ do n = converters.totime(n) if n then converters.settime(n) - timestamp = osdate("%Y-%m-%dT%X") .. ostimezone(true) -- probably not ok + timestamp = osdate("%Y-%m-%dT%X", ostime(n)) .. ostimezone(true) -- probably not ok end end if metadata then i'll fix it but also clean up the existing code a bit
(much has to do with omitting date and is for comparison reasons) 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 -----------------------------------------------------------------
On 10/20/21 4:02 PM, Hans Hagen via ntg-context wrote:
On 10/19/2021 10:38 PM, Michal Vlasák via ntg-context wrote:
[...] The pattern doesn't catch all the PDF spec cases, but should match what ConTeXt emits. The timezone info gets overwritten by current timezone though.
Requires the below patch. [...] i'll fix it but also clean up the existing code a bit
(much has to do with omitting date and is for comparison reasons)
Many thanks for the fix. It would be great that current timezone doesn’t overwrite the specified one. Pablo -- http://www.ousia.tk
participants (3)
-
Hans Hagen
-
Michal Vlasák
-
Pablo Rodriguez