-
Notifications
You must be signed in to change notification settings - Fork 3
/
makebook
736 lines (646 loc) · 21.2 KB
/
makebook
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
#!/bin/bash
# set -x # trace shell
reset
. ./book.config
####################################################################
#
# book.config sets :
# - sources
# - syncmaster
# - output
# - sourcespattern
# - images_parent_folder
# - pdf_bookmark_style
#
# possible values for sourcespattern
# 0 : no change to filename in sources + you MUST specify a value for "images_parent_folder in case you intend to use -noimages option
# example : output="PA72/PA72" + sourcespattern=0 + sources="p_32 PA72/PA72_1 n_8 PA72/PA72_2 n_6 PA72/PA72_3 n_8 p_54" + images_parent_folder="PA72"
# 1 : sources names stand for filename/filename(.sla)
# 2 : sources names stand for filename/PAO/filename(.sla)
# 3 (TODO ?) : all sources in PAO/. Sources names stand for PAO/filename(.sla)
# 4 (TODO ?) : smart detect 2 or 1 or 0
#
# now also managed inside book.config file (warning : illogic naming) :
# FontEmbedding=0 # PDF with embeded or subset fonts
# FontEmbedding=1 # vectorized fonts (no font embeded)
#
####################################################################
#
# Default options
#
# other user options
setopt=""
pdfwithimages=oui
pdfwithbleeds=oui
displaypdf=oui
pdfsuffix=""
# WIP
# '' : PDF goes in same folder as SLA
# 'PDF' : PDF goes to 'PDF' subfolder
pdfsubfolder='' # unused yet
checkpagenum='check'
# Rq : Nb d'éléments d'un array : ${#array[@]} ou ${#array[*]}
check='oui' # '' to not check (only merge chapter pdfs)
vconfig=''
vcheck=''
searched='' # searched string
xmlsearched='' # xml searched string
nbfound=0
displayfindresult="yes"
doreplace='' # used as a boolean
checkcolorall=''
pdfignore=''
getfonts=''
nofontcheck=''
nocomment=''
noimagelist=''
forcepdfopt=''
vectoopt=''
syncopt=''
####################################################################
. shellcolors
echo -e "${ESC_info}PATH=$PATH$ESC_normal"
while [ "$stopoptions" = "" ] && [ "$1" != "" ]
do
stopoptions=true
if [ "$1" = '-?' ] || [ "$1" = '-h' ] || [ "$1" = '--help' ]
then
echo "mak makes the global PDF"
echo "Depending on config, name of produced PDF is $output.pdf, $output-vecto.pdf or $output-noimages.pdf"
echo
echo "Options :"
echo "-? or -h : get this help"
echo "-set : set value to correct value"
echo "-addbookmarks or -ab : add bookmarks. Bookmarks have '$pdf_bookmark_style' style, as specified with 'pdf_bookmark_style' variable in local book.config file)"
echo "-nopagenum : dont check the first page number of each doc (default : check)"
echo "-nocheck : dont check anything, just merge all chapter\'s pdfs"
echo '-nofontcheck : dont check fonts'
echo '-checkcolorall : check for (bad) uses of "All" named color'
echo '-nocomment : dont display comments (user can set comments using AAA, XXX or PPP keywords in texts)'
echo '-noimagelist : dont create used image list'
echo '-noimages : dont include images in created PDF (-forcepdf is implied)'
echo '-nobleeds : create chapters and PDF having -nobleeds suffix, using documents bleeds & having no cropmarks.'
echo '-nodisplay : dont open produced PDF'
echo '-nopdf : dont create chapters PDFs nor merge them (only checks SLA)'
echo '-forcepdf : force all pdf (re)creation, even when it exists allready'
echo '-vconfig : verbose output about config files'
echo '-vcheck : very verbose output about check'
echo '-find "word1 or phrase1" : find occurences in all chapters text'
echo '-xmlfind "string1" : find occurences of string in all chapters SLA file (text + xml tags)'
echo '-replace "string2" : replace found occurences with specified string2. (with -xmlfind only. with -find still to do)'
echo '-nores : do not list search results details (used with -find or -xmlfind)'
echo '-getfonts : display embeded fonts'
echo '-vecto : output to vectorised $output-vecto.pdf - BETA - use twice in a row : mak -vecto -set;mak -vecto'
echo '-sync opt : sync sla-declared styles, masterpages OR colors (depending on opt) of all chapters with project-declared syncmaster. opt=-c : sync colors, -s:styles, -cs:character styles, -ps:paragraph styles, -m:masterpages'
echo
exit
fi
if [ "$1" = "-vconfig" ]
then
vconfig=$1
stopoptions=''
shift
break
fi
if [ "$1" = "-vcheck" ]
then
vcheck=$1
stopoptions=''
shift
break
fi
if [ "$1" = "-getfonts" ]
then
getfonts=$1
echo "will output embeded fonts for each .pdf"
stopoptions=''
shift
break
fi
if [ "$1" = "-nocheck" ]
then
shift
check=''
echo "Chapter PDFs will be merged. No check will happen"
stopoptions=''
continue
fi
if [ "$1" = "-nofontcheck" ]
then
shift
nofontcheck="-nofontcheck"
echo "No font embeding or subseting check will happen"
stopoptions=''
continue
fi
if [ "$1" = "-nocomment" ] || [ "$1" = "-nocomments" ]
then
shift
nocomment="-nocomment"
echo "Dont display comments"
stopoptions=''
continue
fi
if [ "$1" = "-noimagelist" ] || [ "$1" = "-noimagelists" ]
then
shift
nocomment="-noimagelist"
echo "Dont create image list .md"
stopoptions=''
continue
fi
if [ -f .found.tmp ]
then
rm .found.tmp
fi
if [ "$1" = "-find" ]
then
shift
if [ "$1" = "" ]
then
echo -e "${ESC_error}-find option must have additionnal parameter$ESC_normal"
exit
fi
searched="$1"
check=''
pdfignore='-pdfignore'
stopoptions=''
shift
continue
fi
if [ "$1" = "-xmlfind" ]
then
shift
if [ "$1" = "" ]
then
echo -e "${ESC_error}-xmlfind option must have additionnal parameter$ESC_normal"
exit
fi
xmlsearched="$1"
check=''
pdfignore='-pdfignore'
stopoptions=''
echo "xmlfind $xmlsearched"
shift
continue
fi
if [ "$1" = "-nores" ]
then
shift
displayfindresult=""
# echo "dont display find result details"
stopoptions=''
continue
fi
if [ "$1" = "-nobleeds" ] || [ "$1" = "-nobleed" ]
then
pdfsuffix=$1
shift
pdfwithbleeds='no'
forcepdfopt='-forcepdf'
stopoptions=''
continue
fi
if [ "$1" = '-checkcolorall' ]
then
checkcolorall='yes'
xmlsearched="COLOR=\"All\""
check=''
pdfignore='-pdfignore'
stopoptions=''
shift
continue
fi
if [ "$1" = "-replace" ]
then
if [ "$xmlsearched" = "" ] && [ "$searched" = "" ]
then
echo -e "${ESC_error}-replace option must follow some -xmlfind option. No such options found here.$ESC_normal"
exit
fi
shift
if [ -z ${1+x} ] # only verified when $1 is unset, not verified when $1 is empty string
then
echo -e "${ESC_error}-replace option must have additionnal parameter = replacement string$ESC_normal"
exit
fi
replaced="$1"
doreplace="doreplace"
shift
echo "Replace all found strings with '$replaced'"
stopoptions=''
continue
fi
if [ "$1" = "-set" ]
then
shift
setopt="-set"
stopoptions=''
pdfignore='-pdfignore'
continue
fi
if [ "$1" = "-addbookmarks" ] || [ "$1" = "-ab" ]
then
shift
setopt="-ab"
stopoptions=''
pdfignore='-pdfignore'
if [ "$pdf_bookmark_style" == "" ]
then
echo -e "${ESC_error}pdf_bookmark_style variable must be defined in config file so as to use -addbookmarks option$ESC_normal"
exit
fi
continue
fi
if [ "$1" = "-pdfignore" ] || [ "$1" = "-nopdf" ]
then
shift
pdfignore='-pdfignore'
stopoptions=''
continue
fi
if [ "$1" = "-forcepdf" ]
then
shift
pdfignore=''
forcepdfopt='-forcepdf'
stopoptions=''
continue
fi
if [ "$1" = "-vecto" ]
then
shift
vectoopt='-vecto' # pour slacheck et en suffixe de output
output="$output$vectoopt"
stopoptions=''
continue
fi
if [ "$1" = "-nopagenum" ]
then
shift
checkpagenum=''
stopoptions=''
continue
fi
if [ "$1" = "-noimages" ] || [ "$1" = "-noimage" ]
then
pdfsuffix=$1
shift
pdfwithimages='no'
forcepdfopt='-forcepdf'
stopoptions=''
continue
fi
if [ "$1" = "-nodisplay" ]
then
shift
displaypdf=''
stopoptions=''
continue
fi
if [ "$1" = "-sync" ]
then
shift
if [ "$1" = "" ]
then
echo -e "${ESC_error}-sync option must have additionnal parameter : -c, -s, -m, -ps or -cs to sync colors, styles, masterpages, paragraph styles or character styles $ESC_normal"
exit
fi
if [ "$syncmaster" == "" ] || [ ! -f "$syncmaster.sla" ]
then
echo -e "${ESC_error}syncmaster variable must be defined in config file and its value must be an existing sla file (without .sla ext)$ESC_normal"
exit
fi
syncopt="$1"
echo "sync ($syncopt) all chapters with '$syncmaster.sla'"
nocomment="-nocomment"
noimagelist="-noimagelist"
stopoptions=''
shift
fi
done
####################################################################"
verboseopt="$vconfig $vcheck"
listepdf=""
pagenumopt=''
num_page=1 # start page
if [ "$searched" = "" ] && [ "$xmlsearched" = "" ]
then
echo -ne "## $output chapters\n# Inline comments\n\n" > book_comments.md
echo -ne "## $output chapters\n# Bookmarks with '$pdf_bookmark_style' style\n\n" > book_bookmarks.md
echo -ne "## $output chapters\n# Used images\n\n" > book_imagelist.md
fi
for fic in $sources
# fic = scribus filename or page declaration
do
# Appears before filename in $sources :
# Start page of next chapter declaration - let's check
if [ "${fic#p_}" != "$fic" ] && [ $checkpagenum = 'check' ]
then
num_page_set=${fic#p_}
if [ "$num_page_set" != "$num_page" ]
then # page jump could be intended
echo -e "${ESC_warning} or error : After adding pages, page num should be $num_page, but is declared to be $num_page_set"
echo -e "Continuing.$ESC_normal"
fi
num_page=$num_page_set
pagenumopt="-pagenum $num_page"
if [ "$searched" = '' ] && [ "$xmlsearched" = '' ] && [ "$syncopt" = '' ]
then
echo "Declared start page $num_page"
fi
continue
fi
# Appears after filename in $sources :
# pagenum for last chapter declaration - let's check
if [ "${fic#n_}" != "$fic" ] && [ "$checkpagenum" = 'check' ]
then
if [ "$check" != '' ] # eg when -find
then
continue
elif [ "$pagecount" = "" ]
then
echo -e "$ESC_error Missing filename before pagecount in source variable - STOP $EXC_normal"
exit
elif [ "$pagecount" != ${fic#n_} ]
then
echo -e "$ESC_error $pagecount_fic has $pagecount pages but the book declares ${fic#n_} pages$ESC_normal"
fi
continue
fi
# fic is a filename, without .sla extension. Lets get its full path
short_fic="$fic" # for echo only
if [ "$sourcespattern" = 1 ]
then
# images_parent_folder : sla folder, without ending slash
images_parent_folder="$fic"
fic="$fic/$fic"
elif [ "$sourcespattern" = 2 ]
then
images_parent_folder="$fic/PAO"
fic="$fic/PAO/$fic"
elif [ "$images_parent_folder" = "" ]
then
images_parent_folder="."
fi
if [ ! -f "$fic.sla" ]
then
echo -e "$ESC-error Error : missing $fic.sla file $ESC_normal"
# NO exit for mult-mixed component file
exit
fi
# $fic.sla is an existing scribus file whose chapter name is $short_fic
echo "
"
let pagecount=`grep -c "\s<PAGE\s[^>]*PAGEXPOS\s*=\s*\"" "$fic.sla"`
pagecount_fic="$fic"
pagemsg="$short_fic : startpage=$num_page ; pagecount = $pagecount"
pagenumopt="-pagenum $num_page"
start_page=$num_page
num_page=$(( $num_page+$pagecount ))
if [ "$searched" != '' ] || [ "$xmlsearched" != '' ]
then
# Enlever d'abord les césures avant de chercher $searched, et même $xmlsearched
# césures conditionnelles = caractère Unicode U+00AD
# http://stackoverflow.com/questions/8562354/remove-unicode-characters-from-textfiles-sed-other-bash-shell-methods
# La commande `echo -ne '\u00AD' | xxd` donne c2ad qu'il faut utiliser avec \x dans `sed 's/...'` =
cleansla="$fic.clean.sla"
sed -e 's/\xc2\xad//g' "$fic.sla" > "$cleansla"
else
if [ "$syncopt" = '' ]
then
echo -e $pagemsg
fi
fi
if [ "$searched" != '' ]
then
count=`grep -i "<ITEXT[^>]*CH=" "$cleansla" | grep -c -o -i "\"[^\"]*$searched[^\"]*\""`
echo Search in $short_fic : $count results
if [ "$count" != "0" ] && [ "$displayfindresult" != "" ]
then
nbfound=$(( $nbfound+$count ))
echo -e $ESC_yellow
grep -ni "<ITEXT[^>]*CH=" "$cleansla" | grep -i "\"[^\"]*$searched[^\"]*\"" | sed -e 's/<ITEXT[^>]*CH="//' | sed -e 's/"\/>//'
echo -e $ESC_normal
# -n : line number
# /dev/null is added so grep believes there is more than one file and outputs the filename
grep -ni "<ITEXT[^>]*CH=\"[^\"]*$searched[^\"]*\"" "$cleansla" /dev/null | sed -e 's/<ITEXT[^>]*CH="//' | sed -e 's/"\/>//' >> .found.tmp
fi
rm $cleansla
continue
fi
if [ "$xmlsearched" != '' ]
then
count=`grep -c -o -i "$xmlsearched" "$cleansla"`
echo XmlSearch in $short_fic : $count results
# tests : != for string / ne for numerics
if [ "$count" != "0" ] && [ "$displayfindresult" != "" ]
then
nbfound=$(( $nbfound+$count ))
echo -e $ESC_yellow
grep -ni "$xmlsearched" "$cleansla"
echo -e $ESC_normal
# -n : line number
# /dev/null is added so grep believes there is more than one file and outputs the filename
grep -ni "$xmlsearched" "$cleansla" /dev/null >> .found.tmp
if [ -n $doreplace ]
then
echo "Après test pour '$short_fic' : doreplace='$doreplace' replaced='$replaced'" # DEBUG
if [ -f "$fic.before_replace.sla" ]
then
echo "$fic.before_replace.sla allready exists : moved as .bak"
mv "$fic.before_replace.sla" "$fic.before_replace.sla.bak"
fi
cp "$fic.sla" "$fic.before_replace.sla"
echo $fic.sla is saved into $fic.before_replace.sla
echo $xmlsearched is replaced with $replaced in $fic.sla
# avant : ça plantait
# avant : echo sed -i -- \""s/$xmlsearched/$replaced/g"\" "$fic.sla"
# avant : sed -i -- \""s/$xmlsearched/$replaced/g"\" "$fic.sla"
# -i = update file ! ("inplace")
# /gI = global (all occurences) + case insensitive
escapedsearch=$(LC_ALL=C sed 's/["/]/\\&/g' <<<"$xmlsearched")
escapedreplace=$(LC_ALL=C sed 's/["/]/\\&/g' <<<"$replaced")
echo sed -i "s/$escapedsearch/$escapedreplace/gI" "$fic.sla"
sed -i "s/$escapedsearch/$escapedreplace/gI" "$fic.sla" # / delimiter but any other is possible. Has to be escaped in searched and replaced strings
fi
fi
rm $cleansla
continue
fi
if [ "$syncopt" != '' ]
then
echo "slasync $syncopt $syncmaster $fic"
slasync $syncopt $syncmaster $fic
continue
fi
if [ "$pdfwithimages" = "no" ]
then
mv -b "$images_parent_folder/images" "$images_parent_folder/images.bak"
mv -b $fic.pdf "$fic"-withimages.pdf
ls $images_parent_folder
fi
#====================
# On n'appelle pas ". slacheck" sinon les arguments se mélangent / s'ajoutent - à creuser
# Du coup obligé de distinguer la config pour makebook et la config pour slacheck
if [ "$pdfwithbleeds" = "no" ]
then
# save withbleeds version
cp -p -f "$fic".sla "$fic"-withbleeds.sla # -p preserves timestamp
cp -p -f "$fic".pdf "$fic"-withbleeds.pdf
slacheck -nobleeds -set -pdfignore -nofontcheck $verboseopt $fic
fi
if [ "$check" = "oui" ]
then
echo "slacheck $vectoopt $setopt $pagenumopt $forcepdfopt $nofontcheck $nocomment $noimagelist $pdfignore $verboseopt $fic"
slacheck $vectoopt $setopt $pagenumopt $forcepdfopt $nofontcheck $nocomment $noimagelist $pdfignore $verboseopt $fic
echo "slacheck done"
fi
#====================
if [ "$pdfwithimages" = "no" ]
then
# on restaure le dossier image
mv -b "$images_parent_folder/images.bak" "$images_parent_folder/images"
# on sav le nouveau pdf sans image
mv -b "$fic".pdf "$fic$pdfsuffix".pdf
# on restaure le pdf normal
mv -b "$fic"-withimages.pdf "$fic".pdf
fi
if [ "$pdfwithbleeds" = "no" ]
then
# save sla without bleeds and restore sla with bleeds
mv -b "$fic".sla "$fic"-nobleeds.sla
cp -p -f "$fic"-withbleeds.sla "$fic".sla # -p preserves timestamp
rm -f "$fic"-withbleeds.sla
# save pdf without bleeds and restore pdf with bleeds
mv -b "$fic".pdf "$fic"$pdfsuffix.pdf
cp -p -f "$fic"-withbleeds.pdf "$fic".pdf
fi
if [ "$getfonts" != '' ]
then
# alternative : `strings yourPDFfilepath.pdf | grep FontName`
echo "pdffonts $fic.pdf"
pdffonts "$fic.pdf"
fi
if [ "$pdf_bookmark_style" != "" ]
then
chapter_summary="$start_page. "
chapter_summary="${chapter_summary:0:5} $fic " # many spaces for right strpad
echo -ne "${chapter_summary:0:50}" >> book_bookmarks.md
# echo -ne "- p.$start_page $fic " >> book_bookmarks.md
# xmlstarlet : http://xmlstar.sourceforge.net/doc/UG/xmlstarlet-ug.html
# el -a pour lister tous les xpath contenus
# sel -t -v pour récupérer la valeur du contenu de la balise ciblée
# sel -t -c pour récupérer le tag entier <tag>contenu</tag>
# ed -i pour insérer avant : '-t attr' un attribut / '-t elem' un élément=tag / de nom -n et de valeur -v
# Rq : pour un élément, le nom est le contenu du tag, sans < ni />, avec les attributs,
# et si on en veut un, -v est le contenu du tag avant une balise fermant
# ed -s pour créer un sous-noeud
# bookmark style : either as para or as trail paragraph
bookmarklabel=`xmlstarlet sel -t -v "SCRIBUSUTF8NEW/DOCUMENT/PAGEOBJECT/StoryText [para/@PARENT='$pdf_bookmark_style']/ITEXT[1]/@CH" "$fic.sla"`
if [ "$bookmarklabel" != "" ]
then
bookmarktag='para '
else
bookmarklabel=`xmlstarlet sel -t -v "SCRIBUSUTF8NEW/DOCUMENT/PAGEOBJECT/StoryText [trail/@PARENT='$pdf_bookmark_style']/ITEXT[1]/@CH" "$fic.sla"`
bookmarktag='trail'
fi
# clean bookmark
bookmarklabel=`echo $bookmarklabel | tr -d ""` # conditionnal hyphen glyph in ""
bookmarklabel=${bookmarklabel#\s*}
if [ "$bookmarklabel" != "" ]
then # ${fic#p_}
# TODO strpad
# echo len=${#bookmarklabel}
# perl -e '$str="123";$pad="#";$len=3;print (($pad x $len) . $str)'
echo -ne "$bookmarklabel\n" >> book_bookmarks.md
echo -ne "Bookmark found as $bookmarktag : $bookmarklabel\n"
if [ "$setopt" == '-ab' ]
then
dejabookmark=`xmlstarlet sel -t -v "SCRIBUSUTF8NEW/DOCUMENT/PAGEOBJECT[StoryText/$bookmarktag[@PARENT='$pdf_bookmark_style']]/@BOOKMARK" "$fic.sla"`
if [ "$dejabookmark" == '' ]
then
# Add BOOKMARK="1" on PAGEOBJECT
xmlstarlet ed -i "SCRIBUSUTF8NEW/DOCUMENT/PAGEOBJECT[StoryText/$bookmarktag[@PARENT='$pdf_bookmark_style']]" -t attr -n BOOKMARK -v "1" "$fic.sla" > "$fic.tmp_with_bookmark_1.sla"
# Insert a <Bookmark ... /> element in the <DOCUMENT>.
# eg : <Bookmark Title="A title" Text="A Title" Aktion="" ItemNr="1" Element="1491231114" First="0" Last="0" Prev="0" Next="0" Parent="0"/>
# Should be first, OK when last + OK without ItemNr, First, Last, Prev and Next
bookmark_itemid=`xmlstarlet sel -t -v "SCRIBUSUTF8NEW/DOCUMENT/PAGEOBJECT[StoryText/$bookmarktag[@PARENT='$pdf_bookmark_style']]/@ItemID" "$fic.tmp_with_bookmark_1.sla"`
xmlstarlet ed -s "SCRIBUSUTF8NEW/DOCUMENT" -t elem -n "Bookmark Title=\"$bookmarklabel\" Text=\"$bookmarklabel\" Aktion=\"\" Element=\"$bookmark_itemid\" Parent=\"0\"" "$fic.tmp_with_bookmark_1.sla" > "$fic.tmp_with_bookmark_2.sla"
# wc "$fic.sla" "$fic.tmp_with_bookmark_1.sla" "$fic.tmp_with_bookmark_2.sla"
mv "$fic.sla" "$fic.no_bookmark.sla"
mv "$fic.tmp_with_bookmark_2.sla" "$fic.sla"
echo -ne "$ESC_info New bookmark set : $bookmarklabel"
else
echo -ne "$ESC_info Allready a bookmark : '$bookmarklabel'"
fi
fi
else
echo -ne "$ESC_warning Paragraph with '$pdf_bookmark_style' style not found"
echo -ne "\n" >> book_bookmarks.md
fi
echo -ne "\n$ESC_normal"
# echo "=== ça donne ==="
# xmlstarlet sel -t -c "SCRIBUSUTF8NEW/DOCUMENT/PAGEOBJECT[StoryText/$bookmarktag[@PARENT='$pdf_bookmark_style']]" "$fic.sla"
else
echo "bookmarks : pdf_bookmark_style is not defined"
exit
fi
listepdf="$listepdf $fic$pdfsuffix.pdf"
done
if [ "$pdfignore" = "-pdfignore" ] || [ "$pdfignore" = "pdfignore" ] || [ "$searched" != '' ] || [ "$xmlsearched" != '' ] || [ "$syncopt" != '' ]
then
echo "Done"
exit
fi
if [ "$pdfignore" = "" ]
then
if [ -f $output$pdfsuffix.pdf ]
then
mv $output$pdfsuffix.pdf $output$pdfsuffix.pdf.bak
fi
# add some special file as a last page cover
# listepdf="$listepdf separettes/p68-HR.pdf"
echo "Merged PDFs : $listepdf"
echo "Avec /usr/bin/pdftk"
# sur ubuntu 18.04 pdftk n'est plus dispo et déclanchait une erreur en snap
# la commande suivante a réparé cela
# sudo ln -s /snap/pdftk/current/usr/bin/pdftk /usr/bin/pdftk
# à condition qu'on l'appelle en absolu :
/usr/bin/pdftk $listepdf cat output $output$pdfsuffix.pdf
# sinon on peut le faire avec sejda
# echo "Avec sejda-console (http://sejda.org/)"
# sejda-console merge -f $listepdf -o $output$pdfsuffix.pdf
if [ -f $output$pdfsuffix.pdf ]
then
ls -ltr $output$pdfsuffix.pdf
echo $output$pdfsuffix.pdf created OK
if [ "$displaypdf" != '' ]
then
evince $output$pdfsuffix.pdf &
fi
fi
fi
# création d'une version sans marge (marges enlevées à l'arrache pour l'instant) :
# un peu utile pour impression un peu plus grand en pleine page
# pdfcrop --margins '-25 -25 -25 -25' $output.pdf normargin_$output.pdf
# [ -f normargin_$output.pdf ] && evince normargin_$output.pdf & ls -ltr normargin_$output.pdf ; echo normargin_$output.pdf created OK
if [ "$searched$xmlsearched" != '' ]
then
echo Done
echo
echo ${ESC_yellow}Searching \'$searched$xmlsearched\' : total $nbfound results found in whole book$ESC_normal
if [ $nbfound != 0 ]
then
if [ "$checkcolorall" != '' ]
then
echo -e "${ESC_error}Some (bad) uses of COLOR=\"All\" have been found !$ESC_normal"
fi
cat .found.tmp
fi
fi
if [ "$getfonts" != '' ]
then
pdffonts $output$pdfsuffix.pdf
fi
cat book_bookmarks.md