Implémentation de epdf info
This commit is contained in:
parent
8b927a63e8
commit
27d57c3005
152
aliases/qpdf.elv
152
aliases/qpdf.elv
|
@ -1,3 +1,5 @@
|
|||
use math
|
||||
use path
|
||||
use re
|
||||
use str
|
||||
|
||||
|
@ -240,7 +242,36 @@ fn zip {|@args|
|
|||
}
|
||||
|
||||
fn unzip {|@args|
|
||||
echo '<en construction…>'
|
||||
var l = (- (count $args) 1)
|
||||
if (< $l 2) {
|
||||
fail 'unzip doit contenir au moins 3 paramètres'
|
||||
}
|
||||
var mod = $args[0]
|
||||
var out = $args[$l]
|
||||
-must-not-exist $out
|
||||
|
||||
var sel tmp = [] []
|
||||
try {
|
||||
set sel tmp = (-parse-all $args[1..$l])
|
||||
var t = (-make-tmp)
|
||||
-merge $sel $t
|
||||
set @tmp = $@tmp $t
|
||||
var @sels = (range $mod | put [])
|
||||
var end = ($cmd --show-npages $t)
|
||||
range $end | each {|i|
|
||||
var m = (% $i $mod)
|
||||
set sel[$m] = (+ $i 1)
|
||||
}
|
||||
mkdir $out
|
||||
range $mod | each {|i|
|
||||
var @pr = (str:join ',' $@sels[$i])
|
||||
$cmd --empty --pages $t $@pr -- $out'/'(+ $i 1)'.pdf'
|
||||
}
|
||||
} finally {
|
||||
if (> (count $tmp) 0) {
|
||||
rm -f $@tmp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn decrypt {|@args|
|
||||
|
@ -272,8 +303,125 @@ fn help {|@args|
|
|||
cat $E:HOME/.config/elvish/aliases/qpdf.help
|
||||
}
|
||||
|
||||
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 tz @_ = (str:split "'" $raw[16..])
|
||||
var date = (printf ^
|
||||
'%s-%s-%sT%s:%s:%s%s' ^
|
||||
$y $m $d ^
|
||||
$h $n $s ^
|
||||
$tz)
|
||||
date --date $date
|
||||
}
|
||||
|
||||
fn -pts2cm {|v|
|
||||
/ (math:round (* $v 3.52778)) 100
|
||||
}
|
||||
|
||||
fn -size {|size|
|
||||
var u = 0
|
||||
var m = [
|
||||
&10=Kio
|
||||
&20=Mio
|
||||
&30=Gio
|
||||
]
|
||||
while (< $u 30) {
|
||||
var p = (math:pow 2 (+ $u 10))
|
||||
if (< $size $p) {
|
||||
break
|
||||
}
|
||||
set u = (to-string (+ $u 10))
|
||||
}
|
||||
if (== $u 0) {
|
||||
put $size
|
||||
} else {
|
||||
var p = (math:pow 2 (+ $u 10))
|
||||
var e = (/ $size $p)
|
||||
printf '%.1f%s' $e $m[$u]
|
||||
}
|
||||
}
|
||||
|
||||
fn -b2str {|b|
|
||||
if $b {
|
||||
put 'Oui'
|
||||
} else {
|
||||
put 'Non'
|
||||
}
|
||||
}
|
||||
|
||||
fn -props {|input json|
|
||||
var objects = $json[objects]
|
||||
var trailer = $objects[trailer]
|
||||
var iid = $trailer[/Info]
|
||||
var rid = $trailer[/Root]
|
||||
var info = $objects[$iid]
|
||||
var root = $objects[$rid]
|
||||
var pages = $objects[$root[/Pages]]
|
||||
var p1 = $objects[$pages[/Kids][0]][/MediaBox]
|
||||
|
||||
var w = (-pts2cm $p1[2])
|
||||
var h = (-pts2cm $p1[3])
|
||||
var layout = 'Portrait'
|
||||
if (> $w $h) {
|
||||
set layout = 'Paysage'
|
||||
}
|
||||
|
||||
var props = [
|
||||
&path=(path:abs $input)
|
||||
&fsize=(-size (stat -c '%s' $input))
|
||||
&version=''
|
||||
&psize=(printf '%sx%s cm (%s)' $w $h $layout)
|
||||
&pages=$pages[/Count]
|
||||
&title=''
|
||||
&subject=''
|
||||
&author=''
|
||||
&producer=$info[/Producer]
|
||||
&creator=$info[/Creator]
|
||||
&cdate=(-date $info[/CreationDate])
|
||||
&mdate=''
|
||||
&acroform=(-b2str $json[acroform][hasacroform])
|
||||
&encrypted=(-b2str $json[encrypt][encrypted])
|
||||
]
|
||||
|
||||
#@TODO: version pdf
|
||||
if (has-key $info '/Title') {
|
||||
set props[title] = $info[/Title]
|
||||
}
|
||||
if (has-key $info '/Subject') {
|
||||
set props[subject] = $info[/Subject]
|
||||
}
|
||||
if (has-key $info '/Author') {
|
||||
set props[author] = $info[/Author]
|
||||
}
|
||||
if (has-key $info '/ModDate') {
|
||||
set props[mdate] = (-date $info[/ModDate])
|
||||
}
|
||||
|
||||
put $props
|
||||
}
|
||||
|
||||
fn info {|@args|
|
||||
echo '<en construction…>'
|
||||
var input = $args[0]
|
||||
var json = ($cmd --json $input | from-json)
|
||||
var props = (-props $input $json)
|
||||
|
||||
echo ' Chemin: '$props[path]
|
||||
echo ' Taille: '$props[fsize]
|
||||
echo ' Version PDF: '$props[version]
|
||||
echo ' Taille des pages: '$props[psize]
|
||||
echo ' Nombre de pages: '$props[pages]
|
||||
echo '............................................'
|
||||
echo ' Titre: '$props[title]
|
||||
echo ' Sujet: '$props[subject]
|
||||
echo ' Auteur: '$props[author]
|
||||
echo ' Créateur: '$props[creator]
|
||||
echo ' Producteur: '$props[producer]
|
||||
echo ' Date de création: '$props[cdate]
|
||||
echo ' Date de modification: '$props[mdate]
|
||||
echo '............................................'
|
||||
echo ' Chiffré: '$props[encrypted]
|
||||
echo ' Acroform: '$props[acroform]
|
||||
}
|
||||
|
||||
edit:add-var epdf~ {|action @args|
|
||||
|
|
Loading…
Reference in New Issue