python-3.xsubprocessjinja2pdf-generationpdf-form

PythonPDF: FileNotFoundError: [WinError 2] The system cannot find the file specified


I am getting the below error trace when I am using PDFJinja's example for filling form fields in an existing PDF file.

Code Snippet:

        dir_name = os.path.dirname("P:\\Project\\pdfjinja_services\\resources\\sample.pdf")
        template_pdf_file = os.path.join(dir_name, 'sample.pdf')
        template_pdf = PdfJinja(template_pdf_file, current_app.jinja_env)
        print(type(template_pdf))
        rendered_pdf = template_pdf({
            'firstName': 'Faye',
            'lastName': 'Valentine'   
        })
        output_file = os.path.join(dir_name, 'output.pdf')
        rendered_pdf.write(open(output_file, 'wb'))

Error:

Traceback (most recent call last):
File "P:\Professional\Python\CR\workspace\workspace-local\myplaybook\pdf_pdfjinja.py", line 10, in
rendered_pdf = template_pdf({
File "P:\Professional\Python\Softwares\python-3.9.6\lib\site-packages\pdfjinja.py", line 240, in call
filled = PdfFileReader(self.exec_pdftk(self.rendered))
File "P:\Professional\Python\Softwares\python-3.9.6\lib\site-packages\pdfjinja.py", line 212, in exec_pdftk
p = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE)
File "P:\Professional\Python\Softwares\python-3.9.6\lib\subprocess.py", line 951, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File "P:\Professional\Python\Softwares\python-3.9.6\lib\subprocess.py", line 1420, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

I am using python-3.9.6 and PDFJinja-1.1.0. Please let me know if I am missing any other dependencies.


Solution

  • You are missing a binary (per update pdftk), or the binary is not in your search path.