Hide things when creating a PDF

Two ideas to hide the button

  1. Make a copy of the form that will only be used for generating the PDF. Delete the button from this form.
  2. 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