I have written a python script to create then upload PDFs into our Asana to optimize our process and I am having difficulties getting my uploaded PDFs to show filled out fields in the Asana preview viewer. The PDFs do contain the form fields information, I know this because when they’re downloaded or opened in a new tab (from Asana) they show the fields filled out. And when originally saved to my local machine the form fields show up filled out in all PDF viewers I can find/use. Which makes me believe that its Asana’s PDF viewer, but I would love some help.
I also found this: PDF Attachment Not Displaying Correctly - Bugs / Closed - Asana Community Forum
which says its fixed, but it seems that it is not working for me.
Here is how I am writing/uploading the PDF to Asana:
“”" Method for Writing/Upload “”"
def write_pdf():
For writing to a PDF
if (not ‘/AcroForm’) in input_pdf.Root.keys(): # Ensure AcroForm exists
input_pdf.Root.AcroForm = pdfrw.PdfDict()
input_pdf.Root.AcroForm.update(pdfrw.PdfDict(NeedAppearances=pdfrw.PdfObject(‘true’))) # Ensure NeedAppearances is set to true
pdfrw.PdfWriter().write(f"xxxxx.pdf", input_pdf) # Write to the new PDF
Extract metadata from the PDF file
metadata = pdfrw.PdfReader(f"xxxx.pdf").Info
Upload filled PDF to the task
url = “https://app.asana.com/api/1.0/attachments?opt_pretty=true”
files = { # Compile the file for upload
“file”: (
f"xxxx.pdf",
open(f"xxxx.pdf", “rb”),
“application/pdf”
)
}
payload = { # Compile the payload for the response
“resource_subtype”: “asana”,
“parent”: task[‘gid’],
“metadata”: metadata
}
headers = { # Compile the header for the response
“accept”: “application/json”,
“authorization”: f"Bearer {token}"
}
response = requests.post(url, data=payload, files=files, headers=headers)
#######################################################