Flo Ledermann avatar Flo Ledermann committed b5da35a

adding actual python code, tweaking setup

Comments (0)

Files changed (2)

     author='Flo Ledermann',
     author_email='ledermann@ims.tuwien.ac.at',
     url='http://bitbucket.org/floledermann/pdfgen/',
+    license='GPL',
     package_dir = {'': 'src/python'},
     packages=['flyingpython'],
-    data_files=[('bin',['scripts/pdfgen.jar'])],
+    package_data={
+        'flyingpython': ["scripts/*.jar"]
+    },
+    entry_points = {
+        'console_scripts': [
+            'html2pdf = flyingpython:html_to_pdf',
+        ],
+    },
+    #data_files=[('bin/pdfgen',['scripts/pdfgen.jar'])],
     classifiers=[
         'Development Status :: 3 - Alpha',
         'Environment :: Web Environment',

src/python/flyingpython/__init__.py

+
+PDF_COMMAND = 'java -cp bin/pdfgen.jar com.floledermann.pdf.PDFRenderer'
+
+def html_to_pdf(html):
+    p = subprocess.Popen(settings.PDF_COMMAND, 
+                         shell=True, 
+                         stdout=subprocess.PIPE, 
+                         stdin=subprocess.PIPE, 
+                         stderr=subprocess.PIPE)
+    
+    import sys, codecs, locale   
+        
+    p2 = codecs.getwriter('utf-8')(p.stdin)    
+    p2.write(html)
+    p2.close()
+
+    pdf = p.stdout.read()
+    p.stdout.close()
+
+    err = p.stderr.read()
+    p.stderr.close()
+    
+    if p.wait() != 0:
+        if not err:
+            err = 'Error launching PDF renderer'
+
+        raise Exception(err)
+
+    return pdf
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.