svgtools

2017-01-07 00:36 UTC
  • Xyne

Metadata

Description:

Tools for working with SVG files and JessyInk presentations.

Latest Version:

2016.9.26.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]
                    {list,ls,extract,ex,embed,em,rename,mv,scrub,sc,jessyink,ji}
                    ...

Manage images within an SVG file.

positional arguments:
  {list,ls,extract,ex,embed,em,rename,mv,scrub,sc,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)
    scrub (sc)          remove sodipodi:absref tags
    jessyink (ji)       JessyInkt commands

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

Help Message (svg-img_mgr jessyink)

$ svg-img_mgr jessyink --help

usage: SvgImgMgr.py jessyink [-h] {list,ls,renumber,rn,export,ex} ...

JessyInk commands

positional arguments:
  {list,ls,renumber,rn,export,ex}
                        sub-command help
    list (ls)           list JessyInk slides
    renumber (rn)       renumber JessyInk effects to fill numbering gaps
    export (ex)         export JessInk slides

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

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/

  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"
Contact
echo xyne.archlinux.ca | sed 's/\./@/'
Feeds
Blog News
Validation
XHTML 1.0 Strict CSS level 3 Atom 1.0