0

I used the fillpdf function Tyler Houssian describes in this Stackoverflow-Answer. I produced a working code at home. Unfortunately the fillpdf function at the end of the script doesn't flatten the pdfs at my work computer although the Python version and the fillpdf version at work and home are the same (as well as the operating system Windows 10). Everything else the script describes works though and the script doesn't produce any errors. Are there any hidden dependencies to the fillpdf function I am not aware of?, or something else I can check?

import os
import pandas as pd
from fillpdf import fillpdfs

ods_file = "C:/Users/Anon/Desktop/Pythontest/Test.ods"
pdf_file = "C:/Users/Anon/Desktop/Pythontest/Test.pdf"

df = pd.read_excel(ods_file, engine="odf")

df = df[df["Uhrzeit"].notna()]

groups = df.groupby("Tag")
print(fillpdfs.get_form_fields(pdf_file))

for name, group in groups:
    folder_name = str(name)
    if not os.path.exists(folder_name):
        os.makedirs(folder_name)

    for index, row in group.iterrows():
        # PDF-Daten erstellen
        data_dict = {
            'name': row['Chiffre'],
            'adresse': str(row['Sitzungen']) + " " + str(row['(noch nX)']),
        'datum' : row['Datum'].strftime("%d.%m.%y"),
        'datum_2' : row['Uhrzeit'],
        }

        filename = str(row['Sitzungen']) + "_" + row['Chiffre'][3:] + ".pdf"

        output_file = os.path.join(folder_name, filename)
        fillpdfs.write_fillable_pdf(pdf_file, output_file, data_dict)
      # Flatten pdf
        output_flattened_file = os.path.join(folder_name, filename)
        fillpdfs.flatten_pdf(output_file, output_flattened_file)

What I already tried:

I double checked the that the first part of the code is still working on the work computer. I checked that the version of all the imported libraries (most recent, the same in both computers). I double checked the filepath of the input and output file for the the the following code segment and printed the result confirming that the it is correct

fillpdfs.flatten_pdf(output_file, output_flattened_file)

I tried alternative code to flatten the file and shortened the code in the process (yes I read the fillpdf-documentation for this). I confirmed the following code to be working on my home computer as well:

fillpdfs.write_fillable_pdf(pdf_file, output_file, data_dict, flatten=True)
Fabian K
  • 1
  • 2

0 Answers0