Skip to content

Commit a0ac85a

Browse files
committed
Merge pull request #3 from ssebastianj/master
Fixed an issue while trying to read a temp generated PDF file and returning it.
2 parents 5570cbc + b1853aa commit a0ac85a

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

phantom_pdf/generator.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,14 @@ def _set_source_file_name(self):
9595

9696
def _return_response(self, file_src, basename):
9797
"""Read the generated pdf and return it in a django HttpResponse."""
98-
try:
99-
# Open the file created by PhantomJS
100-
return_file = open(file_src, 'r')
101-
except IOError:
102-
exc_msg = "The PDF was not created. Enable debug at RequestToPDF instance."
103-
raise Exception(exc_msg)
98+
# Open the file created by PhantomJS
99+
return_file = None
100+
with open(file_src, 'rb') as f:
101+
return_file = f.readlines()
104102

105103
response = HttpResponse(
106104
return_file,
107-
mimetype='application/force-download'
105+
content_type='application/pdf'
108106
)
109107
content_disposition = 'attachment; filename=%s.pdf' % (basename)
110108
response['Content-Disposition'] = content_disposition

0 commit comments

Comments
 (0)