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

Implement PDF support when not using AppEngine #2

Merged
merged 2 commits into from
Dec 18, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion geocamUtil/pdf.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# All Rights Reserved. # All Rights Reserved.
# __END_LICENSE__ # __END_LICENSE__


import tempfile
import os


class PdfConversionError(Exception): class PdfConversionError(Exception):
pass pass
Expand All @@ -18,4 +20,26 @@ def convertPdf(data,
Pass in the raw binary PDF data. Returns the raw binary image data Pass in the raw binary PDF data. Returns the raw binary image data
result after rasterization. result after rasterization.
""" """
raise NotImplementedError()
#write to temporary pdf file
tempInputFile = tempfile.NamedTemporaryFile(suffix='.pdf', delete=False)
tempInputFile.seek(0)
tempInputFile.write(data)
tempInputFile.flush()

outputFileName = tempInputFile.name.replace('.pdf', '.png')

ret = os.system('convert -flatten %s %s > /dev/null' % (tempInputFile.name, outputFileName))

os.remove(tempInputFile.name)

if ret != 0 or os.path.isfile(outputFileName) == False:
raise PdfConversionError('Error found while converting pdf')

outputFile = open(outputFileName, 'r')
outputFileData = outputFile.read()

outputFile.close()
os.remove(outputFileName)

return outputFileData