{ "info": { "author": "Marc Brinkmann", "author_email": "git@marcbrinkmann.de", "bugtrack_url": null, "classifiers": [], "description": "svglue\n======\n\nsvglue is a small library that takes a template in form of a specially prepared\nSVG document and fills in text and images to create an output SVG file. Style\ninformation like opacity, size, and ordering is kept.\n\nIt's mainly intended to be used to set up a nice workflow creating templates\nfor PDF generation:\n\n 1. Create your template in Inkscape, a placeholder text-element where you\n want to fill in text later, or a rectangle for filling in images.\n 2. Add a custom attribute ``template-id`` to every ```` or ````\n element that you want to replace. Each ``template-id`` must be a unique\n identifier.\n 3. Using ``svglue``, you can programmatically replace every text or rect\n using its ``template-id`` with either a raster image, another SVG graphic\n or replacement text.\n 4. Finally, use something like `rsvg `_,\n `CairoSVG `_ or another SVG-renderer to create a PDF\n document.\n\n\nExample code:\n-------------\n\nStep 3::\n\n #!/usr/bin/env python\n\n import svglue\n\n\n # load the template from a file\n tpl = svglue.load(file='sample-tpl.svg')\n\n # replace some text\n tpl.set_text('sample-text', u'This was replaced.')\n\n # replace the pink box with 'hello.png'. if you do not specify the mimetype,\n # the image will get linked instead of embedded\n tpl.set_image('pink-box', file='hello.png', mimetype='image/png')\n\n # svgs are merged into the svg document (i.e. always embedded)\n tpl.set_svg('yellow-box', file='Ghostscript_Tiger.svg')\n\n # to render the template, cast it to a string. this also allows passing it\n # as a parameter to set_svg() of another template\n src = str(tpl)\n\n # write out the result as an SVG image and render it to pdf using cairosvg\n import cairosvg\n with open('output.pdf', 'w') as out, open('output.svg', 'w') as svgout:\n svgout.write(src)\n cairosvg.svg2pdf(bytestring=src, write_to=out)\n\nIt's important to note that versions <= 0.5 of ``cairosvg`` have a bug that\nrenders the tiger scaled incorrectly. For now, you can use a different renderer\nfor better results until that bug is fixed.\n\n\nInstallation\n------------\n``svglue`` is `available via PyPI `_, so\na simple ``pip install svglue`` should suffice to install.\n\n\nAPI reference\n-------------\n\nNote that the main target for this library is Python3. The later\nversions of `cairosvg` do not compile on Python2 anymore for me.\n\nIf you need Python2 support, restrict the version of `svglue` to `<=0.2.1`.\n\nsvglue.load(src=None, file=None)\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nLoads a template, returning a ``Template``-object. The ``src``/``file`` load\npattern is used through the library - ``src`` is a string containing the\nsource of the SVG file, or ``file`` can either be a file-like object (with a\n``read()`` method) or a filename for the source file. Only one of\n``src``/``file`` may be specified.\n\nTemplate.set_text(tid, text)\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nReplaces the text inside the element ```` (whose id is the\nactual ``tid``) with the specified ``text``.\n\nTemplate.set_image(tid, src=None, file=None, mimetype=None)\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nReplaces a rectangle whose id is ``tid`` (````) with an\n```` tag to link/embed the specified image. If ``mimetype`` is ``None``,\nthe image is linked (so ``file`` should be the path/URI of thte image).\n\nIf ``mimetype`` is given (should be either ``image/png`` or ``image/jpeg``),\nthe supplied image is stored inline in the resulting SVG document.\n\nTemplate.set_svg(tid, src=None, file=None)\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nConceptually similiar to ``Template.set_image()``, this replaces a rectangle\nwith an SVG-image. However, no linking is supported, the SVG is copied into the\nresulting SVG-documents ````-section and a ````-Element replaces\nthe rectangle.\n\nSince ``Template.__str__()`` (see below) is used to render templates, this\nallows nesting templates by simply passing them as the second argument to\n``set_svg()``.\n\nTemplate.__str__()\n~~~~~~~~~~~~~~~~~~\nRenders the template. Returns the template with all supplied info filled in.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/mbr/svglue", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "svglue", "package_url": "https://pypi.org/project/svglue/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/svglue/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/mbr/svglue" }, "release_url": "https://pypi.org/project/svglue/0.3.0/", "requires_dist": null, "requires_python": null, "summary": "Create templates using Inkscape, then fill them in (and render them to PDF, if you like).", "version": "0.3.0" }, "last_serial": 2640668, "releases": { "0.2.0": [ { "comment_text": "", "digests": { "md5": "c3ba153a9460451d2116621987e7802a", "sha256": "b67bb844bd12b6a260f08973bbf74093c1419d608ba6942342aad4bda3ad820c" }, "downloads": -1, "filename": "svglue-0.2.0.tar.gz", "has_sig": true, "md5_digest": "c3ba153a9460451d2116621987e7802a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4282, "upload_time": "2016-12-08T11:00:29", "url": "https://files.pythonhosted.org/packages/8b/1e/08b8b5ae5bafe9a89947d2cdb801d5c844595c691e6281289ac8a958ed20/svglue-0.2.0.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "e6416143ee9355a41845966f6eabcce3", "sha256": "9801ab6ae1c2ed98d12e14efa5444f782471b8db88643b8717396fc830e91525" }, "downloads": -1, "filename": "svglue-0.2.1.tar.gz", "has_sig": true, "md5_digest": "e6416143ee9355a41845966f6eabcce3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4268, "upload_time": "2016-12-09T17:59:07", "url": "https://files.pythonhosted.org/packages/4f/0e/9a51fcb05489b0a3ef05f790e961411b689bcb67887be7b1a5254e9651ea/svglue-0.2.1.tar.gz" } ], "0.2dev": [ { "comment_text": "", "digests": { "md5": "e8069cea6af4e64557534deeb889411d", "sha256": "47e80e90b9b58860329892dba76f4b85f9c9942624e01dfc80c88ea91fa20981" }, "downloads": -1, "filename": "svglue-0.2dev.tar.gz", "has_sig": true, "md5_digest": "e8069cea6af4e64557534deeb889411d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4081, "upload_time": "2013-04-29T14:25:11", "url": "https://files.pythonhosted.org/packages/75/d2/c95c61ea2be08930368cd95a60801c5b09556f9a583ae808bf58668a0ee2/svglue-0.2dev.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "481da84b83f03a0ecb206f265b406cf0", "sha256": "6e284c6894f9b857fac577f6da3940861951112bff136248ce645545397c8735" }, "downloads": -1, "filename": "svglue-0.3.0.tar.gz", "has_sig": true, "md5_digest": "481da84b83f03a0ecb206f265b406cf0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4418, "upload_time": "2017-02-14T10:13:50", "url": "https://files.pythonhosted.org/packages/0b/14/d169b395e913f04102c933466ccfe8f1aad2b28516968899cb1af284c732/svglue-0.3.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "481da84b83f03a0ecb206f265b406cf0", "sha256": "6e284c6894f9b857fac577f6da3940861951112bff136248ce645545397c8735" }, "downloads": -1, "filename": "svglue-0.3.0.tar.gz", "has_sig": true, "md5_digest": "481da84b83f03a0ecb206f265b406cf0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4418, "upload_time": "2017-02-14T10:13:50", "url": "https://files.pythonhosted.org/packages/0b/14/d169b395e913f04102c933466ccfe8f1aad2b28516968899cb1af284c732/svglue-0.3.0.tar.gz" } ] }