Comments (7)
+1
from cairosvg.
Until we write proper docs:
The cairosvg
module has svg2pdf
, svg2ps
, svg2svg
(!) and svg2png
functions. Each function expects one of these named arguments for the input: bytestring
, url
(which I think also accepts filenames) or file_obj
. If you provide a write_to
argument (which can be either a filename or a file object), the output is written there. Otherwise, the function returns a byte string.
This is basically it for the public API. Everything else is implementation details and could change in future versions.
from cairosvg.
Maybe I'm doing something wrong, but passing a filename to svg2ps
didn't work. Instead, I had to do:
cairosvg.svg2ps(open("/path/to/input.svg", "rb").read(), write_to="/tmp/output.ps")
If this is correct, I'd be happy to submit a PR fixing the documentation, so please confirm. Otherwise, let me know why
cairosvg.svg2ps("/path/to/input.svg", write_to="/tmp/output.ps")
didn't work -- I got the following error message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/site-packages/cairosvg/__init__.py", line 43, in <lambda>
surface_type.convert(*args, **kwargs))(_surface_type)
File "/usr/local/lib/python3.5/site-packages/cairosvg/surface/__init__.py", line 103, in convert
tree = Tree(**kwargs)
File "/usr/local/lib/python3.5/site-packages/cairosvg/parser.py", line 270, in __init__
tree = ElementTree.fromstring(bytestring)
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/xml/etree/ElementTree.py", line 1320, in XML
parser.feed(text)
File "<string>", line None
xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 1, column 0
not well-formed (invalid token): line 1, column 0
At the very least, the error could be more informative -- again, happy to submit a PR if you let me know where / what to change.
from cairosvg.
By the way, I also tried navigating to the folder where the input file is and running the script there passing only the filename, without the path, and also adding "file://" to the path (using both the full path and the filename only). None of this worked, so it seems to me a filename isn't actually accepted as input.
from cairosvg.
As described in the documentation:
The cairosvg module offers 4 functions:
svg2pdf
,
svg2png
,
svg2ps
, and
svg2svg
.These functions expect one of these parameters:
bytestring
, a byte string containing SVG, or
url
, an URL or a filename, or
file_obj
, a file-like object.
You can use:
cairosvg.svg2ps(file_obj=open("/path/to/input.svg", "rb"), write_to="/tmp/output.ps")
, orcairosvg.svg2ps(url="/path/to/input.svg", write_to="/tmp/output.ps")
from cairosvg.
file_obj
without .read()
, right?
from cairosvg.
Of course, I've changed the comment.
from cairosvg.
Related Issues (20)
- Failed to load CairoSVG in serverless program HOT 8
- closing the path for ellipse (and circle)? HOT 2
- `text` property `shape-inside` not respected HOT 1
- Convert to WebP HOT 1
- Add rlPyCairo to requirements.txt HOT 1
- Stroke Width is not taken into account for final height / width HOT 3
- OSE Error cairo-2 not found HOT 6
- Conversion of multiple files halted with error HOT 2
- SVG to PDF render improper PNG position HOT 1
- OSError: no library called "cairo-2" was found HOT 1
- RecursionError: maximum recursion depth exceeded in comparison HOT 1
- Truncating fractional height in pixels HOT 4
- svg2pdf incorrect width and height output - HOT 1
- Feature request: support style='background_color:xxxx' in the <svg> object
- Add support for blend modes
- Missing linked images and text HOT 6
- svg2png the stroke attribute causes display anomalies. HOT 1
- Fail of image path resolution in a defs/use context HOT 1
- SVG path parse error
- ValueError: could not convert string to float: 'null' HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cairosvg.