Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Implement PDF support when not using AppEngine #2

Merged
merged 2 commits into from

2 participants

@rburhum

For the cases where we don't use AppEngine (and thus we don't have access to the conversion.pdf library), we can use ImageMagick to generate pngs from the pdfs

@deleted deleted merged commit 1475535 into geocam:master
@rburhum

Great! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 25 additions and 1 deletion.
  1. +25 −1 geocamUtil/pdf.py
View
26 geocamUtil/pdf.py
@@ -4,6 +4,8 @@
# All Rights Reserved.
# __END_LICENSE__
+import tempfile
+import os
class PdfConversionError(Exception):
pass
@@ -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
Something went wrong with that request. Please try again.