svgtools

2017-03-29 14:38 UTC
  • Xyne

Metadata

Description:

Tools for working with SVG files and JessyInk presentations.

Latest Version:

2017.3.20.1

Architecture:

  • any

Dependencies:

  • python3

Optional Dependencies:

  • inkscape: ji2pdf and jessy_to_slides support
  • phantomjs: jessy_to_slides support
  • poppler: ji2pdf support

Arch Repositories:

  • [xyne-any]
  • [xyne-i686]
  • [xyne-x86_64]

AUR Page:

svgtools

Arch Forum Thread:

217435

Tags:

About

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.

FAQ

Why not just use the normal export procedure?

The normal procedure is as follows:

  1. Open the SVG file with Firefox and press "e" to export a new SVG file.
  2. Open the intermediate SVG file in Inkscape and export the slides in a zip archive.
  3. Unzip the archive.

There are several issues with it:

  1. It requires manual intervention and is tedious.
  2. For large presentations, exporting from Firefox takes a long time.
  3. The intermediate SVG is sometimes so large and complicated that Inkscape freezes the system trying to load it into memory and render it. Discovering this when it's time to export a PDF to meet a deadline is a terrifying surprise.
  4. You cannot select a subset of slides to export from the original file.

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.

Why is this better than xyz?

svg-img_mgr jessyink export

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.

ji2pdf

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.

jessyink_to_slides

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.

What's the difference between ji2pdf and jessyink_to_slides

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.

How do I join the PDFs together to create the final document?

# 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

What else should I know?

  • In my experience Chromium/Chrome renders the slides as expected. If you have the opportunity, use it during the presentation.
  • Firefox renders most effects correctly but it mangles others. Superscripts are a notable example.
  • PhantomJS does not render transparency correctly in some cases. The transparent object is rendered in opaque white. Although it uses Webkit like Chrome, apparently the javascript engine is different, but I do not know if this is why it fails to render correctly.

What else did you try?

  • A script to export layers from the intermediate SVG file exported from Firefox with inkscape -C -i .... Mixed results.
  • A script to automatically click through and screenshot the browser presentation, then join the images together in a PDF (xdotool, import and convert). Mixed results. Getting the margins right was tedious.
  • Human sacrifice. The offer was refused.

Help Message (svg-img_mgr)

$ 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

optional arguments:
  -h, --help            show this help message and exit
  -v, --verbose         Increase verbosity.
  --debug               Enable debugging messages.

Help Message (svg-img_mgr list)

$ svg-img_mgr list --help

usage: SvgImgMgr.py list [-h] [-i] [--ids] [--hidden] svg

positional arguments:
  svg           The SVG file.

optional arguments:
  -h, --help    show this help message and exit
  -i, --images  List images.
  --ids         List id attributes (sometimes useful for debugging).
  --hidden      List hidden elements.

Help Message (svg-img_mgr extract)

$ 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.

optional arguments:
  -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.

Help Message (svg-img_mgr embed)

$ 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.

optional arguments:
  -h, --help  show this help message and exit

Help Message (svg-img_mgr rename)

$ 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.

optional arguments:
  -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>.

Help Message (svg-img_mgr dedupe)

$ svg-img_mgr dedupe --help

usage: SvgImgMgr.py dedupe [-h] svg

deduplicate images

positional arguments:
  svg         The SVG file.

optional arguments:
  -h, --help  show this help message and exit

Help Message (svg-img_mgr scrub)

$ 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.

optional arguments:
  -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.

Help Message (svg-img_mgr jessyink)

$ 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

optional arguments:
  -h, --help            show this help message and exit

Help Message (svg-img_mgr jessyink list)

$ svg-img_mgr jessyink list --help

usage: SvgImgMgr.py jessyink list [-h] [-c] [-t] svg

list JessyInk slides

positional arguments:
  svg          The SVG file.

optional arguments:
  -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.

Help Message (svg-img_mgr jessyink renumber)

$ 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.

optional arguments:
  -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.

Help Message (svg-img_mgr jessyink autotext)

$ 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 [args ...]]

set and unset JessyInk autotexts

positional arguments:
  svg                   The SVG file.
  args                  The elements to which to apply the changes.

optional arguments:
  -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.

Help Message (svg-img_mgr jessyink export)

$ 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.

optional arguments:
  -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.

Help Message (svg-img_mgr jessyink clear)

$ 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.

optional arguments:
  -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.

Help Message (svg-img_mgr inkscape)

$ 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

optional arguments:
  -h, --help          show this help message and exit

Help Message (svg-img_mgr inkscape dedupemarkers)

$ 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.

optional arguments:
  -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.

Help Message (ji2pdf)

$ ji2pdf

USAGE
  ji2pdf <jessyink svg file> <output directory> [<arguments to svg-img_mgr jessyink export>]

DESCRIPTION
  Export a JessyInk presentation to a PDF document. This depends on

      * svg-img_mgr
      * inkscape
      * pdfunite (poppler)

  Copy and modify the script if you want to use something else.

EXAMPLES
  Export the full presentation with all effects:

      ji2pdf presentation.pdf slides/

  Same as above but with simplified SVG files (the output should be the same):

      ji2pdf presentation.pdf slides/ --simplify

  Export slides with final effects:

      ji2pdf presentation.pdf slides/ -s /-1

Help Message (jessyink_to_slides)

$ 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"

CHANGELOG

2017-03-20

  • Added support for JessyInk views when exporting slides.

2017-03-19

  • Added the --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.
  • Added option to remove unused definitions to scrub subcommand. This subcommand now includes options to independently remove sodipodi:absref attributes.

2017-03-15

  • Removed leftover debugging messages from previous update.
  • Moved dedupemarkers method to new Inkscape subcommand.
  • dedupemarkers should now preserve arrow colors (previous version cast them all to stock black).
  • Fixed bug when exporting slides that contain references to objects on other slides. Hidden objects were previously deleted to reduce the total size of exported files. When I have time, I will update this method to check for references to objects and delete everything else.

2017-03-14

  • added support for setting and unsetting JessyInk autotexts
  • added support for deduplicated path markers to work around Inkscape bug

2017-03-11

  • added support for renumbering JessyInk view effects
  • new JessyInk mode: clear
  • code tweaks

2017-02-28

  • added subcommand for deduplicating images
  • minor code tweaks

TODO

TODO

  • Export slides with JessyInk views.
  • Add optiosn to select slides by number or title.
Contact
echo xyne.archlinux.ca | sed 's/\./@/'
Feeds
Blog News
Validation
XHTML 1.0 Strict CSS level 3 Atom 1.0