Description: | Tools for working with SVG files and JessyInk presentations. |
Latest Version: | 2023 |
Source Code: | src/ |
Architecture: |
|
Dependencies: |
|
Build Dependencies: |
|
Optional Dependencies: |
|
Arch Repositories: |
|
AUR Page: | svgtools |
Arch Forum Thread: | 217435 |
Tags: |
This is a collection of tools for working with SVG images. There isn’t much in it at the moment but it will likely grow over time. I’ll likely update svg2ggr when I have some time and add it to this package.
The normal procedure is as follows:
There are several issues with it:
These tools solve these issues. With them you can quickly and easily export the entire presentation or just one slide directly from the original SVG file on the command line. You could even script PDF generation. It is also possible to export the slides in any format that Inkscape supports from the command-line, not just PDF and PNG.
It exports the SVG for a slide directly from the original file. The exported SVG is exactly what was in the original file. It is much faster than exporting the slides from Firefox, and each slide is in a separate file.
This is just a wrapper around svg-img_mgr
,
inkscape
and pdfunite
to automate the pdf
generation. It uses Inkscape to render the image so you should always
get correct output, which may not be the case when other render engines
are used.
This is not the first script to use PhantomJS to export slides from a JessyInk presentation, but this one is different in that it uses Inkscape to render the output so you will always get the same output that you would get from manually exporting the slides with Inkscape. I have found that PhantomJS’s render function is unable to handle certain effects such as multi-layered transparency (even though Chromium, which also uses Webkit, can render it perfectly in the browser). Whichever application is failing to adhere to the standard, it makes sense to export the final output with the same program that you used to visually create it.
ji2pdf
uses svg-img_mgr
to export the
slides. svg-img_mgr
doesn’t run any javascript. It directly
inspects the elements in the SVG file and determines how to render the
slides. It is faster and it exports a working SVG file, but if JessyInk
changes then this script will need to be updated.
jessyink_to_slides
uses a javascript engine run the
embedded JessyInk script so it should always determine the correct
output, but the exported SVG file is quirky and requires further
manipulation to extract the presentation layer.
# Requires poppler
# Concatenates files. Fast! Output size is approximately the sum of the
# input size. No perceptible changes.
pdfunite *.pdf out.pdf
# Requires pdfjam (texlive-core)
# Concatenates files. Output size is approximately the sum of the input
# size. No perceptible changes.
pdfjoin -o out.pdf *.pdf
# Requires ghostscript
# "Prints" files. Output is smaller than the input size but some changes may
# be perceptible. Sometimes it completely mangles objects. Try different
# ghostscript options.
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=out.pdf *.pdf
# Requires imagemagick.
# Huge output files. Slow. Not sure how the files are joined.
convert *.pdf out.pdf
inkscape -C -i ...
. Mixed results.xdotool
, import
and convert
).
Mixed results. Getting the margins right was tedious.$ svg-img_mgr --help
usage: SvgImgMgr.py [-h] [-v] [--debug]
{list,ls,extract,ex,embed,em,rename,mv,dedupe,dd,scrub,sc,inkscape,ink,jessyink,ji}
...
Manage images within an SVG file.
positional arguments:
{list,ls,extract,ex,embed,em,rename,mv,dedupe,dd,scrub,sc,inkscape,ink,jessyink,ji}
sub-command help
list (ls) list svg data
extract (ex) Collect linked and/or embedded images.
embed (em) Embed linked data (usually images) with base64-encoded
data URIs.
rename (mv) rename linked data (usually images)
dedupe (dd) deduplicae linked and embedded images
scrub (sc) remove unnecessary elements
inkscape (ink) Inkscape commands
jessyink (ji) JessyInk commands
options:
-h, --help show this help message and exit
-v, --verbose Increase verbosity.
--debug Enable debugging messages.
$ svg-img_mgr list --help
usage: SvgImgMgr.py list [-h] [-i] [--ids] [--hidden] svg
positional arguments:
svg The SVG file.
options:
-h, --help show this help message and exit
-i, --images List images.
--ids List id attributes (sometimes useful for debugging).
--hidden List hidden elements.
$ svg-img_mgr extract --help
usage: SvgImgMgr.py extract [-h] [-u <path>] [-e] [-l] svg outdir
collect linked and/or embedded images
positional arguments:
svg The SVG file.
outdir Collect files in this directory.
options:
-h, --help show this help message and exit
-u <path>, --update <path>
Generate a new SVG image with updated links here.
-e, --embedded Extract embedded data.
-l, --linked Extract linked data.
$ svg-img_mgr embed --help
usage: SvgImgMgr.py embed [-h] svg outpath
embed linked data
positional arguments:
svg The SVG file.
outpath The path to the new SVG file.
options:
-h, --help show this help message and exit
$ svg-img_mgr rename --help
usage: SvgImgMgr.py rename [-h] [-p <oldpath> <newpath>] [-c <path>] svg
rename linked data
positional arguments:
svg The SVG file.
options:
-h, --help show this help message and exit
-p <oldpath> <newpath>, --pair <oldpath> <newpath>
Old and new path of file to rename.
-c <path>, --copy <path>
Copy files instead of moving them. The new SVG file
will be saved to <path>.
$ svg-img_mgr dedupe --help
usage: SvgImgMgr.py dedupe [-h] svg
deduplicate images
positional arguments:
svg The SVG file.
options:
-h, --help show this help message and exit
$ svg-img_mgr scrub --help
usage: SvgImgMgr.py scrub [-h] [-o <path>] [-l] [-a] [--sodipodi] [--defs] svg
remove unnecessary elements
positional arguments:
svg The SVG file.
options:
-h, --help show this help message and exit
-o <path>, --output <path>
Save the updated file here. Without this option, the
original will be overwritten.
-l, --list List changes that would be made.
-a, --all Remove all unnecessary elements.
--sodipodi Remove sodipodi:absref tags.
--defs Remove unused definitions.
$ svg-img_mgr jessyink --help
usage: SvgImgMgr.py jessyink [-h]
{list,ls,renumber,rn,autotext,at,export,ex,clear,cl}
...
JessyInk commands
positional arguments:
{list,ls,renumber,rn,autotext,at,export,ex,clear,cl}
sub-command help
list (ls) list JessyInk slides
renumber (rn) renumber JessyInk effects to fill numbering gaps
autotext (at) set and unset JessyInk autotexts
export (ex) export JessInk slides
clear (cl) clear JessyInk effects
options:
-h, --help show this help message and exit
$ svg-img_mgr jessyink list --help
usage: SvgImgMgr.py jessyink list [-h] [-c] [-t] svg
list JessyInk slides
positional arguments:
svg The SVG file.
options:
-h, --help show this help message and exit
-c, --count Count the number of effects per slide.
-t, --title Include the slide title in the output.
$ svg-img_mgr jessyink renumber --help
usage: SvgImgMgr.py jessyink renumber [-h] [-l] [-o <path>] svg
renumber JessyInk effects
positional arguments:
svg The SVG file.
options:
-h, --help show this help message and exit
-l, --list List changes that would be made.
-o <path>, --output <path>
Save the updated file here. Without this option, the
original will be overwritten.
$ svg-img_mgr jessyink autotext --help
usage: SvgImgMgr.py jessyink autotext [-h] [-l]
[-t {slideTitle,slideNumber,numberOfSlides}]
[--by {id,text}] [-r] [-o <path>]
svg [args ...]
set and unset JessyInk autotexts
positional arguments:
svg The SVG file.
args The elements to which to apply the changes.
options:
-h, --help show this help message and exit
-l, --list List autotexts.
-t {slideTitle,slideNumber,numberOfSlides}, --type {slideTitle,slideNumber,numberOfSlides}
Select the type of autotext to set. If this option is
not given, autotext will be unset on the selected
targets, or all if no targets are given.
--by {id,text} Criterion for setting autotexts. id: element id
attribute, text: content of text element Default: text
-r, --remove Remove autotexts on the selected elements, or all if
no arguments are given.
-o <path>, --output <path>
Save the updated file here. Without this option, the
original will be overwritten.
$ svg-img_mgr jessyink export --help
usage: SvgImgMgr.py jessyink export [-h] [-s SLIDES [SLIDES ...]] [--simplify]
svg outdir
export JessyInk slides
positional arguments:
svg The SVG file.
outdir The output directory.
options:
-h, --help show this help message and exit
-s SLIDES [SLIDES ...], --slides SLIDES [SLIDES ...]
Select slides to export, For example export the first
5 slides with all effects with "-s 1 2 3 4 5", or in
Bash use "-s {1..5}". To select a slide and an effect,
use "/". For example, the first 3 effects of the 8th
slide: "-s 8/0 8/1 8/2" or "-s 8/{0..2}" (effects are
numbered from 0). Negative numbers will be counted
from the end. To export just the final effect of each
slide, use "-s /-1".'
--simplify Remove unnecessary elements from each slide to reduce
its size.
$ svg-img_mgr jessyink clear --help
usage: SvgImgMgr.py jessyink clear [-h] [--layers <number> [<number> ...]]
[--nested] [-o <path>]
svg
clear JessyInk effects
positional arguments:
svg The SVG file.
options:
-h, --help show this help message and exit
--layers <number> [<number> ...]
The layers on which to clear effects.
--nested Only clear nested effects.
-o <path>, --output <path>
Save the updated file here. Without this option, the
original will be overwritten.
$ svg-img_mgr inkscape --help
usage: SvgImgMgr.py inkscape [-h] {dedupemarkers,dm} ...
Inkscape commands
positional arguments:
{dedupemarkers,dm} sub-command help
dedupemarkers (dm)
deduplicate Inkscape stock markers
options:
-h, --help show this help message and exit
$ svg-img_mgr inkscape dedupemarkers --help
usage: SvgImgMgr.py inkscape dedupemarkers [-h] [-o <path>] [-l] [-d] svg
deduplicate Inkscape stock markers
positional arguments:
svg The SVG file.
options:
-h, --help show this help message and exit
-o <path>, --output <path>
Save the updated file here. Without this option, the
original will be overwritten.
-l, --list List changes that would be made.
-d, --delete Delete unused markers.
$ jessyink_to_slides -h
NOTE
This script should probably be replaced by ji2pdf. The only advantage of this
script is that it uses the embedded JessyInk javascript so it will render
correctly even if JessyInk changes, but ji2pdf will be updated in that case.
USAGE
jessyink_to_slides [-h] [-r <range>] [-o <path>] <svg file>
DESCRIPTION
Use PhantomJS and Inkscape to export slides from a JessyInk SVG file directly
from the command line.
HOW IT WORKS
1. Collect the SVG file and all linked and embedded images in a temporary
directory using svg-img_mgr. This ensures that all relative paths work
in the intermediate files and it also deduplicates data.
2. Use phantomjs and custom javascript to select a slide and export the
modified DOM as an SVG image.
3. Extract the exported slide with inkscape and save it in the chosen format.
4. Goto 2 until the full range has been exported.
OPTIONS
-h
Show this message and exit.
-r <range>
Select the slides to export as a range, e.g "-r 4-10" will extract slides 4
to 10, inclusive. If the start slide is omitted, e.g. "-10", it will default
to 1. The end slide is required because this script does not autodetect the
number of slides. If a single number is given then it will be interpretted
as the end slide. Obviously the start must be equal to or less than the end.
-o <path>
The output path template. The extension will be stripped of an used to set
the output format. Valid extensions are pdf, png, svg, eps, ps, emw, and
wmf. Inkscape will be used to export the slide. The slide number will be
inserted before the extension in <path> and the output will be saved there.
Default: "jessyink/slide_.pdf"
--simplify
option to the JessyInk slide
exporter. This will detect unnecessary elements and remove them from
each exported slide to reduce the total output size.scrub
subcommand. This subcommand now includes options to independently remove
sodipodi:absref
attributes.dedupemarkers
method to new Inkscape
subcommand.dedupemarkers
should now preserve arrow colors
(previous version cast them all to stock black).