Skip to content

Commit

Permalink
Merge pull request #2 from GGSN/master
Browse files Browse the repository at this point in the history
Implement PDF support when not using AppEngine
  • Loading branch information
deleted committed Dec 18, 2012
2 parents 1f99005 + ded3c4d commit 1475535
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion geocamUtil/pdf.py
Expand Up @@ -4,6 +4,8 @@
# All Rights Reserved.
# __END_LICENSE__

import tempfile
import os

class PdfConversionError(Exception):
pass
Expand All @@ -18,4 +20,26 @@ def convertPdf(data,
Pass in the raw binary PDF data. Returns the raw binary image data
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

0 comments on commit 1475535

Please sign in to comment.