空SVG文件错误,而不是

时间:2017-03-28 10:14:51

标签: python svg pycairo

使用Pycairo,我创建了一个“SVGSurface”(为我创建了一个svg文件),然后使用“context”编写它。在我完成之后,我需要使用svg文件,但似乎文件没有关闭,所以它给我一个错误,告诉文档是空的。

    ps = cairo.SVGSurface("header.svg", width, height)
    cr = cairo.Context(ps)
    drawRectangle (cr,
        papersize.convert_length(int(lg[0]), "px","pt"),
        papersize.convert_length(int(lg[2]), "px","pt"),
        papersize.convert_length(int(lg[1])-int(lg[0])-1, "px","pt"),
        papersize.convert_length(int(lg[3])-int(lg[2])-1, "px","pt"),
        0, 0, 0.5
    )
    cr.show_page()
    head = st.fromfile("header.svg")

它给了我这个错误:

 File "/usr/local/lib/python2.7/dist-packages/svgutils/transform.py", line 249, in fromfile
    svg_file = etree.parse(fid)
  File "src/lxml/lxml.etree.pyx", line 3427, in lxml.etree.parse (src/lxml/lxml.etree.c:81117)
  File "src/lxml/parser.pxi", line 1832, in lxml.etree._parseDocument (src/lxml/lxml.etree.c:118116)
  File "src/lxml/parser.pxi", line 1852, in lxml.etree._parseFilelikeDocument (src/lxml/lxml.etree.c:118399)
  File "src/lxml/parser.pxi", line 1747, in lxml.etree._parseDocFromFilelike (src/lxml/lxml.etree.c:117187)
  File "src/lxml/parser.pxi", line 1162, in lxml.etree._BaseParser._parseDocFromFilelike (src/lxml/lxml.etree.c:111914)
  File "src/lxml/parser.pxi", line 595, in lxml.etree._ParserContext._handleParseResultDoc (src/lxml/lxml.etree.c:105109)
  File "src/lxml/parser.pxi", line 706, in lxml.etree._handleParseResult (src/lxml/lxml.etree.c:106817)
  File "src/lxml/parser.pxi", line 635, in lxml.etree._raiseParseError (src/lxml/lxml.etree.c:105671)
lxml.etree.XMLSyntaxError: Document is empty, line 1, column 1 (line 1)

我试图用操作系统关闭文件,但它无法正常工作

0 个答案:

没有答案