Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running svg2rlg second time returns None. #95

Closed
hovodab opened this issue Sep 29, 2017 · 8 comments
Closed

Running svg2rlg second time returns None. #95

hovodab opened this issue Sep 29, 2017 · 8 comments

Comments

@hovodab
Copy link

hovodab commented Sep 29, 2017

I have to draw an image on every page of a PDF file. For that I have a function that does something like this:

def draw_logo(file_path):
      rlg = svg2rlg(file_path)
      # Draw on PDF. This part doesn't matter...

And for every page I call the function draw_logo. It draws the image on the first page, but when the function is called second time(for second page) svg2rlg returns None. Yet I have found a way to bypass this case, I still think things shouldn't work so.

@claudep
Copy link
Collaborator

claudep commented Sep 29, 2017

I cannot reproduce. Are you sure file_path is a real file path, or is it another file-like Python object?
Do you get a "Failed to load input file!" error log line the second time?

@hovodab
Copy link
Author

hovodab commented Sep 29, 2017

@claudep It is a real file path(str). What is your version of svglib? I use 0.8.1.
Yes. In the body of the function svg2rlg an exception is risen

  File "src/lxml/lxml.etree.pyx", line 3442, in lxml.etree.parse (src/lxml/lxml.etree.c:81716)
  File "src/lxml/parser.pxi", line 1832, in lxml.etree._parseDocument (src/lxml/lxml.etree.c:118903)
  File "src/lxml/parser.pxi", line 1852, in lxml.etree._parseFilelikeDocument (src/lxml/lxml.etree.c:119186)
  File "src/lxml/parser.pxi", line 1747, in lxml.etree._parseDocFromFilelike (src/lxml/lxml.etree.c:117974)
  File "src/lxml/parser.pxi", line 1162, in lxml.etree._BaseParser._parseDocFromFilelike (src/lxml/lxml.etree.c:112701)
  File "src/lxml/parser.pxi", line 595, in lxml.etree._ParserContext._handleParseResultDoc (src/lxml/lxml.etree.c:105896)
  File "src/lxml/parser.pxi", line 706, in lxml.etree._handleParseResult (src/lxml/lxml.etree.c:107604)
  File "src/lxml/parser.pxi", line 635, in lxml.etree._raiseParseError (src/lxml/lxml.etree.c:106458)
  File "/var/www/control/media/logos/logo.svg", line 1
lxml.etree.XMLSyntaxError: Document is empty, line 1, column 1

@claudep
Copy link
Collaborator

claudep commented Sep 29, 2017

Changes on master from the 0.8.1 release are minor, I don't think that makes a difference.
Are you able to place a breakpoint inside the svg2rlg function to see what's happening?
Is your file a .svg or .svgz file? Which Python? On Linux, Mac, Windows?

@hovodab
Copy link
Author

hovodab commented Sep 29, 2017

File is .svg
Ubuntu==16.04, python==3.5.2
Exception is risen on the line doc = etree.parse(path, parser=parser)

@claudep
Copy link
Collaborator

claudep commented Sep 29, 2017

I have quite a similar configuration (Debian instead of Ubuntu). That's a weird behavior.
Is the following Python code running fine for you?:

from lxml import etree
etree.parse("/var/www/control/media/logos/logo.svg")
etree.parse("/var/www/control/media/logos/logo.svg")

I don't see how the document would be empty the second time.

@hovodab
Copy link
Author

hovodab commented Sep 29, 2017

Yes, this runs without errors.

@claudep
Copy link
Collaborator

claudep commented Sep 29, 2017

I'm sorry, I don't see any obvious error on svglib side which would explain this error. I'm afraid you'll have to debug a bit more on your side.

@hovodab
Copy link
Author

hovodab commented Sep 29, 2017

@claudep Yes, I think I should. Thank you for your help. I will try to dig deeper.

@hovodab hovodab closed this as completed Sep 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants