I have a button that creates a pdf of a form, the trouble is I have a button on the form that I don’t want in the pdf.
I’ve tried setting visible to False and also removing it from parent but it still shows up in the pdf.
Does anyone have any ideas?
Two ideas to hide the button
- Make a copy of the form that will only be used for generating the PDF. Delete the button from this form.
- Probably better way is to pass something like an origin string to the form constructor. Then if it’s a person viewing it, the button will show, but if its a PDF then it hides the button.
Here is some pseudo code for option 2 (not tested though).
class YourForm(YourFormTemplate):
def __init__(self, origin, **properties):
# Set Form properties and Data Bindings.
self.init_components(**properties)
# Any code you write here will run when the form opens.
if origin == 'pdf':
self.button.visible = False
else:
self.button.visible = True
When calling the PDF generator on the server.
def create_pdf():
pdf = anvil.pdf.render_form("YourForm", origin)
return pdf
4 Likes
pdf= anvil.pdf.render_form("YourForm", origin='pdf')
Small correction 
Br
Jesper
2 Likes
+1 for creating a duplicate form for the purpose of PDF rendering! Just pass a dict containing the output to this form (so you don’t repeat any server calls). For me this has the advantage of absolute layout customization and very light coding (you only have to assign the output dict to your layout components).
Of course if you only need to hide a single button, this would be an overkill 