|
| 1 | +# pylint: disable=duplicate-code |
| 2 | + |
| 3 | +from python_anvil.api import Anvil |
| 4 | +from python_anvil.api_resources.mutations.create_etch_packet import CreateEtchPacket |
| 5 | +from python_anvil.api_resources.payload import ( |
| 6 | + DocumentMarkdown, |
| 7 | + EtchSigner, |
| 8 | + MarkdownContent, |
| 9 | + SignatureField, |
| 10 | + SignerField, |
| 11 | +) |
| 12 | + |
| 13 | + |
| 14 | +API_KEY = 'my-api-key' |
| 15 | + |
| 16 | + |
| 17 | +def main(): |
| 18 | + anvil = Anvil(api_key=API_KEY) |
| 19 | + |
| 20 | + # Create an instance of the builder |
| 21 | + packet = CreateEtchPacket( |
| 22 | + name="Etch packet with existing template", |
| 23 | + # |
| 24 | + # Optional changes to email subject and body content |
| 25 | + signature_email_subject="Please sign these forms", |
| 26 | + signature_email_body="This form requires information from your driver's " |
| 27 | + "license. Please have that available.", |
| 28 | + # |
| 29 | + # URL where Anvil will send POST requests when server events happen. |
| 30 | + # Take a look at https://www.useanvil.com/docs/api/e-signatures#webhook-notifications |
| 31 | + # for other details on how to configure webhooks on your account. |
| 32 | + # You can also use sites like webhook.site, requestbin.com or ngrok to |
| 33 | + # test webhooks. |
| 34 | + # webhook_url="https://my.webhook.example.com/etch-events/", |
| 35 | + # |
| 36 | + # Email overrides for the "reply-to" email header for signer emails. |
| 37 | + # If used, both `reply_to_email` and `reply_to_name` are required. |
| 38 | + # By default, this will point to your organization support email. |
| 39 | + # reply_to_email="[email protected]", |
| 40 | + # reply_to_name="My Name", |
| 41 | + # |
| 42 | + # Merge all PDFs into one. Use this if you have many PDF templates |
| 43 | + # and/or files, but want the final downloaded package to be only |
| 44 | + # 1 PDF file. |
| 45 | + # merge_pdfs=True, |
| 46 | + ) |
| 47 | + |
| 48 | + # Get your file(s) ready to sign. |
| 49 | + # For this example, a PDF will not be uploaded. We'll create and style the |
| 50 | + # document with HTML and CSS and add signing fields based on coordinates. |
| 51 | + |
| 52 | + # Define the document with Markdown |
| 53 | + file1 = DocumentMarkdown( |
| 54 | + id="markdownFile", |
| 55 | + filename="markdown.pdf", |
| 56 | + title="Sign this markdown file", |
| 57 | + fields=[ |
| 58 | + # This is markdown content |
| 59 | + MarkdownContent( |
| 60 | + table=dict( |
| 61 | + rows=[ |
| 62 | + ['Description', 'Quantity', 'Price'], |
| 63 | + ['3x Roof Shingles', '15', '$60.00'], |
| 64 | + ['5x Hardwood Plywood', '10', '$300.00'], |
| 65 | + ['80x Wood Screws', '80', '$45.00'], |
| 66 | + ], |
| 67 | + ) |
| 68 | + ), |
| 69 | + SignatureField( |
| 70 | + page_num=0, |
| 71 | + id="sign1", |
| 72 | + type="signature", |
| 73 | + # The position and size of the field. The coordinates provided here |
| 74 | + # (x=300, y=300) is the top-left of the rectangle. |
| 75 | + rect=dict(x=300, y=300, width=250, height=30), |
| 76 | + ), |
| 77 | + ], |
| 78 | + ) |
| 79 | + |
| 80 | + # Gather your signer data |
| 81 | + signer1 = EtchSigner( |
| 82 | + name="Jackie", |
| 83 | + |
| 84 | + # Fields where the signer needs to sign. |
| 85 | + # Check your cast fields via the CLI (`anvil cast [cast_eid]`) or the |
| 86 | + # PDF Templates section on the Anvil app. |
| 87 | + # This basically says: "In the 'myNewFile' file (defined in |
| 88 | + # `file1` above), assign the signature field with cast id of |
| 89 | + # 'sign1' to this signer." You can add multiple signer fields here. |
| 90 | + fields=[ |
| 91 | + SignerField( |
| 92 | + # this is the `id` in the `DocumentUpload` object above |
| 93 | + file_id="markdownFile", |
| 94 | + # This is the signing field id in the `SignatureField` above |
| 95 | + field_id="sign1", |
| 96 | + ), |
| 97 | + ], |
| 98 | + signer_type="embedded", |
| 99 | + # |
| 100 | + # You can also change how signatures will be collected. |
| 101 | + # "draw" will allow the signer to draw their signature |
| 102 | + # "text" will insert a text version of the signer's name into the |
| 103 | + # signature field. |
| 104 | + # signature_mode="draw", |
| 105 | + # |
| 106 | + # Whether or not to the signer is required to click each signature |
| 107 | + # field manually. If `False`, the PDF will be signed once the signer |
| 108 | + # accepts the PDF without making the user go through the PDF. |
| 109 | + # accept_each_field=False, |
| 110 | + # |
| 111 | + # URL of where the signer will be redirected after signing. |
| 112 | + # The URL will also have certain URL params added on, so the page |
| 113 | + # can be customized based on the signing action. |
| 114 | + # redirect_url="https://www.google.com", |
| 115 | + ) |
| 116 | + |
| 117 | + # Add your signer. |
| 118 | + packet.add_signer(signer1) |
| 119 | + |
| 120 | + # Add files to your payload |
| 121 | + packet.add_file(file1) |
| 122 | + |
| 123 | + # If needed, you can also override or add additional payload fields this way. |
| 124 | + # This is useful if the Anvil API has new features, but `python-anvil` has not |
| 125 | + # yet been updated to support it. |
| 126 | + # payload = packet.create_payload() |
| 127 | + # payload.aNewFeature = True |
| 128 | + |
| 129 | + # Create your packet |
| 130 | + # If overriding/adding new fields, use the modified payload from |
| 131 | + # `packet.create_payload()` |
| 132 | + res = anvil.create_etch_packet(payload=packet, include_headers=True) |
| 133 | + print(res) |
| 134 | + |
| 135 | + |
| 136 | +if __name__ == '__main__': |
| 137 | + main() |
0 commit comments