user user - 3 years ago 96
Python Question

Trying to create an editable pdf with Python

I'm trying to create a PDF with checkboxes that can be checked (using python). I've been trying to use pisa to generate the pdf and have looked around the internet and tried different examples but I cannot find out how to make an editable PDF.

This is my most recent attempt:

import cStringIO
import ho.pisa as pisa
import os

# shortcut for dumping all logs on screen

def HTML2PDF(data, filename, open=False):
Simple test showing how to create a PDF file from
PML Source String. Also shows errors and tries to start
the resulting PDF
pdf = pisa.CreatePDF(cStringIO.StringIO(data), file(filename, "wb"))

if open and not(pdf.err):

return not pdf.err

if __name__=="__main__":
<form name="deleteForm" method="get" action="">
User 1 <input type="checkbox" name="user" value="delete" />

HTML2PDF(HTMLTEST, "test.pdf", open=True)

The form gives me an error:

Traceback (most recent call last):
File "C:/Users/horeth/PycharmProjects/Reportlab/HTMLtoPF/", line 32, in
HTML2PDF(HTMLTEST, "test.pdf", open=True)
File "C:/Users/horeth/PycharmProjects/Reportlab/HTMLtoPF/", line 14, in HTML2PDF
pdf = pisa.CreatePDF(cStringIO.StringIO(data), file(filename, "wb"))
IOError: [Errno 13] Permission denied: 'test.pdf'

The check boxes are for readers to decide if a user needs to be deleted or not.

I'm wondering if there is a way to create an editable PDF document with Python. This is just one of the attempts I've made so far, as an example.

Answer Source

Possible reasons. You don't have write permission to the directory. The file already exists but you do not have write access to it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download