Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 0 additions & 123 deletions examples/create_etch_existing_cast.py

This file was deleted.

62 changes: 62 additions & 0 deletions examples/fill.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Fill a PDF template with your data via the Anvil API.
# Docs: https://www.useanvil.com/docs/api/fill-pdf
#
# Run this from the project root:
# ANVIL_API_KEY=YOUR_KEY python examples/fill.py && open ./fill-output.pdf

import os

from python_anvil.api import Anvil


API_KEY = os.environ.get("ANVIL_API_KEY")

# The PDF template ID to fill. This is a sample template available to anyone.
# See https://www.useanvil.com/help/tutorials/set-up-a-pdf-template for details
# on setting up your own template.
PDF_TEMPLATE_EID = "05xXsZko33JIO6aq5Pnr"

# Fill data can be an instance of `FillPDFPayload` or a plain dict.
# The keys in `data` must match the field IDs on the PDF template,
# which are usually camelCase.
FILL_DATA = {
"title": "My PDF Title",
"font_size": 10,
"text_color": "#333333",
"data": {
"shortText": "Hello World!",
"date": "2024-01-15",
"name": {"firstName": "Robin", "mi": "W", "lastName": "Smith"},
"email": "testy@example.com",
"phone": {"num": "5554443333", "region": "US", "baseRegion": "US"},
"usAddress": {
"street1": "123 Main St #234",
"city": "San Francisco",
"state": "CA",
"zip": "94106",
"country": "US",
},
"ssn": "456454567",
"ein": "897654321",
"checkbox": True,
"decimalNumber": 12345.67,
"dollar": 123.45,
"integer": 12345,
"percent": 50.3,
"longText": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
},
}


def main():
anvil = Anvil(api_key=API_KEY)

# Returns the PDF binary
res = anvil.fill_pdf(PDF_TEMPLATE_EID, FILL_DATA)

with open("./fill-output.pdf", "wb") as f:
f.write(res)


if __name__ == "__main__":
main()
87 changes: 0 additions & 87 deletions examples/fill_pdf.py

This file was deleted.

56 changes: 56 additions & 0 deletions examples/generate_html.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Generate a PDF from HTML and CSS via the Anvil API.
# Docs: https://www.useanvil.com/docs/api/generate-pdf#html--css-to-pdf
#
# Run this from the project root:
# ANVIL_API_KEY=YOUR_KEY python examples/generate_html.py
# Then: open ./generate-html-output.pdf

import os

from python_anvil.api import Anvil
from python_anvil.api_resources.payload import GeneratePDFPayload


API_KEY = os.environ.get("ANVIL_API_KEY")

HTML = """
<h1 class='header-one'>What is Lorem Ipsum?</h1>
<p>
Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been the industry's standard dummy text
ever since the <strong>1500s</strong>, when an unknown printer took
a galley of type and scrambled it to make a type specimen book.
</p>
<h3 class='header-two'>Where does it come from?</h3>
<p>
Contrary to popular belief, Lorem Ipsum is not simply random text.
It has roots in a piece of classical Latin literature from
<i>45 BC</i>, making it over <strong>2000</strong> years old.
</p>
"""

CSS = """
body { font-size: 14px; color: #171717; }
.header-one { text-decoration: underline; }
.header-two { font-style: italic; }
"""


def main():
anvil = Anvil(api_key=API_KEY)

payload = GeneratePDFPayload(
type="html",
title="Example HTML to PDF",
data=dict(html=HTML, css=CSS),
)

# Returns the PDF binary
response = anvil.generate_pdf(payload)

with open("./generate-html-output.pdf", "wb") as f:
f.write(response)


if __name__ == "__main__":
main()
54 changes: 54 additions & 0 deletions examples/generate_markdown.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Generate a PDF from Markdown-structured data via the Anvil API.
# Docs: https://www.useanvil.com/docs/api/generate-pdf#markdown-to-pdf
#
# Run this from the project root:
# ANVIL_API_KEY=YOUR_KEY python examples/generate_markdown.py
# Then: open ./generate-markdown-output.pdf

import os

from python_anvil.api import Anvil
from python_anvil.api_resources.payload import GeneratePDFPayload


API_KEY = os.environ.get("ANVIL_API_KEY")


def main():
anvil = Anvil(api_key=API_KEY)

payload = GeneratePDFPayload(
type="markdown",
title="Example Invoice",
data=[
dict(label="Name", content="Sally Jones"),
dict(
content=(
"Lorem **ipsum** dolor sit _amet_, consectetur adipiscing "
"elit, sed [do eiusmod](https://www.useanvil.com/docs) "
"tempor incididunt ut labore et dolore magna aliqua."
)
),
dict(
table=dict(
firstRowHeaders=True,
rows=[
["Description", "Quantity", "Price"],
["4x Large Widgets", "4", "$40.00"],
["10x Medium Sized Widgets in dark blue", "10", "$100.00"],
["10x Small Widgets in white", "6", "$60.00"],
],
)
),
],
)

# Returns the PDF binary
response = anvil.generate_pdf(payload)

with open("./generate-markdown-output.pdf", "wb") as f:
f.write(response)


if __name__ == "__main__":
main()
Loading
Loading