Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 3707

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 61k
Author
Asked: November 26, 20242024-11-26T05:13:10+00:00 2024-11-26T05:13:10+00:00

New PDF Generation Features: customizable font size, color, table gridlines, and alignment

  • 61k

For this blog post, we’ll assume you’re already familiar with Anvil’s API. In case you’re not, I recommend taking 5 minutes to read this tutorial on generating an invoice PDF to quickly get up to speed.

There’s tools to simplify almost all daily tasks, but when it comes to PDFs, it’s quite lacking. Anvil is on its way to changing that, and today I’m excited to announce a number of new features to further streamline PDF generation.

Overview

With Anvil’s PDF generation API, the input is accepted in JSON format with the content as an array of objects defined under the data key.

{   "title": "Anvil Doghouse Project Invoice",   "fontSize": 18,   "textColor": "#171717",   "data": [     {...},   ] } 
Enter fullscreen mode Exit fullscreen mode

Let’s first take a look at the new features.

  • Per field customizable font size and color
  • Option to show or hide table row and column gridlines
  • Adjustable table column widths
  • Vertical alignment of table content

We’ll go through with a brief description of each feature then demonstrate them with an example.

Feature 1. Adjusting font size and color on each field

Each object under the data array is a field, and with the new release you’re able to adjust the font size and color of each field. Define fontSize and textColor to your liking on each field object, and you’re good to go.

If not specified, the font size and color will be inherited from the PDF body.

"data": [   {     "content": "March 4th, 2024",     "fontSize": 16,     "textColor": "#616161"   },   {     "label": "To",     "content": "Phoebe Beckett - phoebe@example.com",     "fontSize": 12,     "textColor": "#006ec2"   } ] 
Enter fullscreen mode Exit fullscreen mode

Customizing font size and color on fields

Feature 2. Displaying table row and column gridlines

In the case you want your table content to be more structured and defined, the rowGridlines and columnGridlines booleans are your friend. To add gridlines in-between each table row, set rowGridlines to true. Likewise for columnGridlines.

"data": [   "label": "Building material expenses",   "table": {     "rows": [       ["Description", "Quantity", "Price"],       ["3x Roof Shingles", "15", "$60.00"],       ["5x Hardwood Plywood", "10", "$300.00"],       ["80x Wood Screws", "80", "$45.00"]     ],    "rowGridlines": true,    "columnGridlines": true,    ...   },   ... ] 
Enter fullscreen mode Exit fullscreen mode

Table with row and column gridlines

Feature 3. Adjusting table column width down to the pixel

This is another feature for tables, giving you more control of how your tables are formatted. Under columnOptions, specify your width in either pixels or percentage.

For the example below, column 1 is defined to have a width 60% of the table’s total width and column 3 would have a width of 200px.

"data": [   "table": {     "rows": [...],     "columnOptions": [       { "align": "left", "width": "40%" },       { "align": "left" },       { "align": "left", "width": "200px" }     ],     ...   },   ... ] 
Enter fullscreen mode Exit fullscreen mode

Table with column gridlines

Feature 4. Vertically aligning table content

Horizontally aligning content is already supported within our tables, and now you can add vertical alignment! Set verticalAlign to top, center, or bottom to adjust the vertical position of your table content.

"data": [   "table": {     "rows": [...],     "columnOptions": [...],     "verticalAlign": "center",     ...   },   ... ] 
Enter fullscreen mode Exit fullscreen mode

Table with content center vertically aligned

Summing It Up

What better way to summarize all our new features than with an example? Here is our PDF generation API endpoint, improved with more customizability.

{   "title": "Anvil Doghouse Project Invoice",   "fontSize": 18,   "textColor": "#171717",   "data": [     {       "content": "March 4th, 2024",       "fontSize": 16,       "textColor": "#616161"     },     {       "label": "To",       "content": "Phoebe Beckett - phoebe@example.com",       "fontSize": 12     },     {       "label": "From",       "content": "Anvil Inc. - hello@useanvil.com",       "fontSize": 12     },     {       "label": "Building material expenses",       "table": {         "rows": [           ["Description", "Quantity", "Price"],           ["3x Roof Shingles", "15", "$60.00"],           ["5x Hardwood Plywood", "10", "$300.00"],           ["80x Wood Screws", "80", "$45.00"],           [...]         ],         "columnOptions": [           { "align": "left", "width": "60%" },           { "align": "center", "width": "100px" },           { "align": "right" }         ],         "verticalAlign": "top",         "firstRowHeaders": true,         "rowGridlines": true,         "columnGridlines": true       },       "fontSize": 10     },     {       "label": "Food expenses",       "table": {         "rows": [           ["Description", "Quantity", "Price"],           ["20x Dog Biscuits", "20", "$50.00"],           [...]         ],         "columnOptions": [           { "align": "left", "width": "40%" },           { "align": "left" },           { "align": "left", "width": "200px" }         ],         "verticalAlign": "center",         "firstRowHeaders": true,         "rowGridlines": false,         "columnGridlines": true       },       "fontSize": 10     },     {       "label": "Total Amount",       "table": {         "rows": [           ["**Tax**", "$64.80"],           ["***Total***", "$784.80"]         ],         "firstRowHeaders": false       },       "fontSize": 14,       "textColor": "#db0000"     }   ] } 
Enter fullscreen mode Exit fullscreen mode

The complete invoice

Now you’re all prepped up to build your own PDF programmatically from JSON input. PDFs can be tricky to deal with in all sorts of situations, but with Anvil we’ll take care of that so you can focus on solving problems more important to you.

Additional Resources

  • Take a look at our PDF generation API docs
  • Experiment with our API using the Anvil API Postman collection

Questions or feedback? Contact us at developers@useanvil.com.

apipdftutorialwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 1k
  • Popular
  • Answers
  • Author

    How to ensure that all the routes on my Symfony ...

    • 0 Answers
  • Author

    Insights into Forms in Flask

    • 0 Answers
  • Author

    Kick Start Your Next Project With Holo Theme

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.