Skip to content

Commit

Permalink
Add support for remote images via a url
Browse files Browse the repository at this point in the history
  • Loading branch information
boralyl committed Dec 18, 2012
1 parent 699c60b commit e2dee89
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions django_xhtml2pdf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def fetch_resources(uri, rel):
path = os.path.join(d, uri.replace(settings.STATIC_URL, ""))
if os.path.exists(path):
break
elif uri.startswith("http://") or uri.startswith("https://"):
path = uri
else:
raise UnsupportedMediaPathException(
'media urls must start with %s or %s' % (
Expand All @@ -47,17 +49,17 @@ def generate_pdf_template_object(template_object, file_object, context):
return file_object

#===============================================================================
# Main
# Main
#===============================================================================

def generate_pdf(template_name, file_object=None, context=None): # pragma: no cover
"""
Uses the xhtml2pdf library to render a PDF to the passed file_object, from the
given template name.
This returns the passed-in file object, filled with the actual PDF data.
In case the passed in file object is none, it will return a StringIO instance.
"""
if not file_object:
file_object = StringIO.StringIO()
Expand Down

0 comments on commit e2dee89

Please sign in to comment.