implémentation de la sous-commande info
This commit is contained in:
parent
4c91add277
commit
40c07d15d8
117
aliases/pdf.elv
117
aliases/pdf.elv
|
@ -1,5 +1,7 @@
|
|||
use moi/util/format
|
||||
use moi/util/pdf
|
||||
use math
|
||||
use path
|
||||
use re
|
||||
use str
|
||||
|
||||
|
@ -228,6 +230,119 @@ fn unzip {|@args|
|
|||
}
|
||||
}
|
||||
|
||||
fn -pts2cm {|v|
|
||||
/ (math:round (* $v 3.52778)) 100
|
||||
}
|
||||
|
||||
fn -date {|raw|
|
||||
var y m d = $raw[2..6] $raw[6..8] $raw[8..10]
|
||||
var h n s = $raw[10..12] $raw[12..14] $raw[14..16]
|
||||
var rest = []
|
||||
if (> (count $raw[16..]) 0) {
|
||||
set @rest = (str:split "'" $raw[16..])
|
||||
}
|
||||
var tz = '+00:00'
|
||||
if (> (count $rest) 0) {
|
||||
var tz = $rest[0]
|
||||
if (eq $tz[0] 'Z') {
|
||||
set tz = $tz[1..]
|
||||
}
|
||||
if (eq $tz '') {
|
||||
set tz = '00'
|
||||
}
|
||||
if (and (not-eq $tz[0] '+') (not-eq $tz[0] '-')) {
|
||||
set tz = (printf '+%s' $tz)
|
||||
}
|
||||
var mm = '00'
|
||||
if (and (> (count $rest) 1) (pdf:is-number $rest[1])) {
|
||||
set mm = $rest[1]
|
||||
}
|
||||
set tz = (printf '%s:%s' $tz $mm)
|
||||
}
|
||||
var date = (printf ^
|
||||
'%s-%s-%sT%s:%s:%sZ%s' ^
|
||||
$y $m $d ^
|
||||
$h $n $s ^
|
||||
$tz)
|
||||
date --date $date
|
||||
}
|
||||
|
||||
fn info {|@args|
|
||||
if (!= (count $args) 1) {
|
||||
fail 'info doit contenir un paramètre'
|
||||
}
|
||||
var in @_ = $@args
|
||||
-must-pdf-exist $in
|
||||
var json = (pdf:json $in)
|
||||
var objects = $json[objects]
|
||||
var trailer = $objects[trailer]
|
||||
var infos = $objects[$trailer[/Info]]
|
||||
var pages = $json[pages]
|
||||
var p1 = $objects[$pages[0][object]]
|
||||
var w h = (all $p1[/MediaBox][2..] | each $-pts2cm~)
|
||||
var layout = 'Portrait'
|
||||
var title = ''
|
||||
var subject = ''
|
||||
var author = ''
|
||||
var creator = ''
|
||||
var producer = ''
|
||||
var mdate = ''
|
||||
var crypted = 'Non'
|
||||
var hasform = 'Non'
|
||||
if (> $w $h) {
|
||||
set layout = 'Paysage'
|
||||
}
|
||||
if (has-key $infos '/Title') {
|
||||
set title = $infos[/Title]
|
||||
}
|
||||
if (has-key $infos '/Subject') {
|
||||
set subject = $infos[/Subject]
|
||||
}
|
||||
if (has-key $infos '/Author') {
|
||||
set author = $infos[/Author]
|
||||
}
|
||||
if (has-key $infos '/Creator') {
|
||||
set creator = $infos[/Creator]
|
||||
}
|
||||
if (has-key $infos '/Producer') {
|
||||
set producer = $infos[/Producer]
|
||||
}
|
||||
if (has-key $infos '/ModDate') {
|
||||
set mdate = (-date $infos[/ModDate])
|
||||
}
|
||||
if (pdf:encryption $in)[encrypted] {
|
||||
set crypted = 'Oui'
|
||||
}
|
||||
if (pdf:form $in)[hasacroform] {
|
||||
set hasform = 'Oui'
|
||||
}
|
||||
var data = [
|
||||
[&k='Chemin' &v=(path:abs $in)]
|
||||
[&k='Taille' &v=(format:size (stat -c '%s' $in))]
|
||||
[&k='Version PDF' &v=(pdf:version $in)]
|
||||
[&k='Nombre de pages' &v=(count $pages)]
|
||||
[&k='Format des pages' &v=(printf '%sx%s cm (%s)' $w $h $layout)]
|
||||
[&k='Titre' &v=$title]
|
||||
[&k='Subjet' &v=$subject]
|
||||
[&k='Auteur' &v=$author]
|
||||
[&k='Créateur' &v=$creator]
|
||||
[&k='producteur' &v=$producer]
|
||||
[&k='Date de création' &v=(-date $infos[/CreationDate])]
|
||||
[&k='Date de modification' &v=$mdate]
|
||||
[&k='Chiffré' &v=$crypted]
|
||||
[&k='Acroform' &v=$hasform]
|
||||
]
|
||||
var label = (format:repeat 21 ' ')
|
||||
var @props = (format:column &align=right k $label) (format:column v $label)
|
||||
set props = (format:update-props $props $data)
|
||||
var sep = (format:repeat (+ $props[0][size] $props[1][size] 3) '.')
|
||||
var @part = $data[..5] $data[5..12] $data[12..]
|
||||
each {|d|
|
||||
format:list &with-header=$false &csep=' : ' &recompute=$false $props $d
|
||||
echo $sep
|
||||
} $part
|
||||
}
|
||||
|
||||
edit:add-var pdf~ {|action @args|
|
||||
var actions = [
|
||||
&help=$help~
|
||||
|
@ -242,7 +357,7 @@ edit:add-var pdf~ {|action @args|
|
|||
&cut=$split-at~
|
||||
&zip=$zip~
|
||||
&unzip=$unzip~
|
||||
#&info=$info~
|
||||
&info=$info~
|
||||
#&list=$list~
|
||||
#&extract=$extract~
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue