pdfjinja icon indicating copy to clipboard operation
pdfjinja copied to clipboard

Example code for python 3.6 is not working on macOS 10.13.1

Open Twirl1910 opened this issue 7 years ago • 2 comments

I always get the error-code:

File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pdfjinja.py", line 208, in exec_pdftk p = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 707, in init restore_signals, start_new_session) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 1326, in _execute_child raise child_exception_type(errno_num, err_msg) FileNotFoundError: [Errno 2] No such file or directory: 'pdftk'

I installed pdftk (even version 2.02 from here https://github.com/jkraemer/pdf-forms/issues/30) and used the example code in python:

import os

from pdfjinja import PdfJinja import pypdftk

dirname = os.path.dirname(file) template_pdf_file = os.path.join(dirname, 'sample.pdf') template_pdf = PdfJinja(template_pdf_file)

rendered_pdf = template_pdf({ 'firstName': 'Faye', 'lastName': 'Valentine', 'address': { 'street': '223B Baker Street', 'apt': '6F', 'city': 'London', 'zipcode': 94455 }, 'sig': os.path.join(dirname, 'sig.png'), 'spirit': 'Panda', 'evil': True, 'language': { 'english': True }, 'attachments': [{ 'data': os.path.join(dirname, 'attachment.png'), 'text': 'Tux\nFriendly Penguin\nMascot :)', 'dimensions': [100, 200, 400, 400] }] })

output_file = os.path.join(dirname, 'output.pdf') rendered_pdf.write(open(output_file, 'wb'))

Twirl1910 avatar Dec 30 '17 22:12 Twirl1910

You have to download pdftk https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/ and then run the script again. I had this same issue, but now the script takes too long. Please let me know if you can fix it and if you have the same issue as me (no errors but bot generate the PDF).

dfrojas avatar Feb 07 '18 02:02 dfrojas

@dfrojas just ran test script (python 2.7.9 on osX 10.13.3). Output pdf is created and left empty, script ran (apparently doing nothing) for about 20mins until I killed it.

pmourelle avatar Mar 31 '18 22:03 pmourelle