DocAssemble Development

How to Generate PDF & DOCX Documents Using Docassemble

Table of Contents

Introduction

A law firm wants to automate a client document. At first, the requirement sounds refreshingly simple:

“Ask the client a few questions and generate a PDF.”

Then the follow-up requests begin.

  • Show one clause for married users and another for unmarried users.
  • Add a row for every beneficiary.
  • Include uploaded supporting documents.
  • Generate an editable Word version.
  • Produce a polished final PDF.
  • Insert the client’s signature.
  • Use a different template for each US state.
  • Hide sections that do not apply.

Suddenly, the “simple form” has become a small software product wearing a legal-document costume.

This is exactly where Docassemble Document Generation becomes useful. Docassemble combines guided interviews, variables, conditional logic, Python, and document templates to create customized legal and business documents from user input.

It can support PDF forms, editable DOCX files, generated PDFs, multilingual templates, state-specific documents, signatures, attachments, and complex clauses. But reliable automation depends on more than uploading a Word file and hoping the software understands your intentions.

In this guide, we will explain how Docassemble PDF Generation and Docassemble DOCX Generation work, how to prepare templates, how to use variables and conditional logic, and how to avoid common formatting and maintenance problems.

What Is Docassemble Document Generation?

Docassemble Document Generation connects four main components:

  1. A guided interview
  2. Stored variables
  3. Legal or business logic
  4. A PDF, DOCX, or text-based document template

A user answers questions through an online interview. Each answer is stored in a named variable. Docassemble then uses those variables to calculate values, choose clauses, repeat sections, and populate a document.

For example, a client may answer questions about:

  • Their full legal name
  • Mailing address
  • Marital status
  • Children
  • Beneficiaries
  • Assets
  • State of residence
  • Preferred representative

The interview can then generate a document containing only the information and clauses relevant to that client.

The Basic Docassemble Document Workflow

A standard workflow usually looks like this:

  1. The user opens the interview.
  2. Docassemble asks structured questions.
  3. Answers are stored as variables.
  4. Logic calculates additional values.
  5. An attachment block references a template.
  6. Variables are inserted into the template.
  7. The user previews or downloads the document.
  8. The final file may be emailed, signed, stored, or sent to another system.

The clever part is not simply replacing {client_name} with “Sarah Johnson.” The real value comes from deciding whether an entire clause, table, disclosure, or document should appear based on the interview answers.

PDF vs DOCX in Docassemble Document Automation

Docassemble supports both PDF and DOCX templates, but they are suited to different use cases.


Comparison Area

PDF Template

DOCX Template

Best for

Fixed government or court forms

Contracts, letters, agreements and flexible documents

Layout flexibility

Limited to existing form fields

Highly flexible

Editable after generation

Usually no

Yes

Conditional paragraphs

More difficult
Easier

Repeating tables
Limited
Strong support

Dynamic clauses

Possible but less convenient

Well suited

Formatting control

Excellent for fixed layouts

Excellent for flowing documents

Output format
PDF
DOCX and usually PDF

The correct format depends on the document.

Use PDF when the layout must remain fixed, such as a court-issued form with predefined field positions.

Use DOCX when paragraphs, clauses, tables, signatures, or page lengths may change dynamically.

How Docassemble PDF Generation Works

Docassemble PDF Generation is often used when a legal organization already has a fillable PDF form.

This is common for:

  • Court filings
  • Government applications
  • Benefits forms
  • Legal-aid forms
  • Intake paperwork
  • Compliance forms
  • State-specific legal documents

The PDF should ideally contain properly named form fields. Docassemble maps interview variables to those fields and produces a completed PDF.

A simplified attachment block may look like this:

attachment:
  name: Completed client form
  filename: client_form
  pdf template file: client_form.pdf
  fields:
    - ClientName: client.name.full()
    - ClientAddress: client.address.on_one_line()
    - IsMarried: client_is_married

In this example:
ClientName is the PDF field name.
client.name.full() supplies the value.
IsMarried may populate a checkbox or boolean field.

Preparing a PDF Template

Before uploading the template, inspect its fields carefully.

Check:

  • Field names
  • Checkbox values
  • Radio-button values
  • Date formats
  • Character limits
  • Multiline fields
  • Font sizes
  • Signature fields
  • Page alignment

A PDF may look perfectly normal but still contain field names such as TextField12, TextField13, and TextField14.

Technically, those names work. Practically, they turn future maintenance into an archaeological project.

Rename fields clearly whenever possible:

  • client_full_name
  • client_address
  • filing_date
  • county_name
  • has_minor_children

Clear naming makes mapping, testing, and debugging much easier.

Challenges With PDF Templates

PDF forms are reliable when the structure is fixed, but they are less flexible when content changes substantially.

Problems may include:

  • Text not fitting inside fields
  • Long names being cut off
  • Inconsistent checkbox behavior
  • Different PDF creation tools producing different field structures
  • Limited support for repeating sections
  • Difficulty inserting variable-length clauses
  • Font or appearance problems

A PDF cannot easily “move everything down” when a paragraph becomes longer. That is why document-heavy legal workflows often use DOCX templates for dynamic documents.

How Docassemble DOCX Generation Works

Docassemble DOCX Generation is ideal for documents where the text, clauses, tables, or length may change.

Common examples include:

  • Engagement letters
  • Contracts
  • Wills
  • Trusts
  • Settlement agreements
  • Demand letters
  • Employment documents
  • Legal opinions
  • Policy documents
  • Compliance reports

The DOCX template is created in Microsoft Word. Variables and logic are inserted into the document using template expressions.

A basic DOCX attachment may look like this:

attachment:
  name: Client agreement
  filename: client_agreement
  docx template file: client_agreement.docx
Inside the Word template, you might insert variables such as:
{{ client.name.full() }}

{{ client.address.block() }}

{{ format_date(agreement_date) }}

When the interview runs, Docassemble replaces those expressions with the correct values.

Why DOCX Templates Are Popular

DOCX templates allow legal teams to preserve familiar Word formatting while adding automation.

They support:

  • Headers and footers
  • Page numbers
  • Tables
  • Conditional paragraphs
  • Dynamic lists
  • Signatures
  • Images
  • Defined styles
  • Repeated sections
  • Custom fonts
  • Editable final documents

A user can receive the Word file for further editing and a PDF version for review or distribution.

Building Variables for Docassemble Legal Document Generation

Reliable Docassemble Legal Document Generation begins with well-structured variables.

A simple question block might look like this:

question: |

 Tell us about yourself

fields:
  - First name: client.name.first
  - Middle name: client.name.middle
    required: False
  - Last name: client.name.last
  - Email address: client.email
    datatype: email

Docassemble stores these answers in an object called client.

Using structured objects is usually better than creating unrelated variables such as:

client_first_name
client_middle_name
client_last_name
client_email

Objects make templates and logic more readable.
For example:
{{ client.name.full() }}

is cleaner than manually joining three separate name variables in every document.

Structured variables are especially important when the workflow includes:

  • Multiple clients
  • Spouses
  • Children
  • Beneficiaries
  • Witnesses
  • Attorneys
  • Properties
  • Assets
  • Organizations

Adding Conditional Clauses to DOCX Templates

Conditional text is one of the most valuable features of Docassemble Document Automation.

Suppose a clause should appear only when the client is married.

The interview may store:

question: |

  Are you currently married?

yesno: client_is_married

The DOCX template can then contain logic similar to:

{% if client_is_married %}

The Client confirms that they are legally married as of the effective date of this agreement.

{% endif %}

If the answer is yes, the paragraph appears. If the answer is no, it is omitted.

Conditional logic can be used for:

  • State-specific language
  • Minor children
  • Joint ownership
  • Payment terms
  • Optional services
  • Disclosures
  • Signature blocks
  • Witness requirements
  • Jurisdiction clauses
  • Risk notices

The goal is not to place complicated legal reasoning inside Word wherever possible. Keep major logic in the interview or Python code, and use the template mainly for presentation.

Otherwise, your Word document may slowly evolve into a software application that nobody knows how to debug.

Creating Repeating Tables and Lists

Many legal documents contain variable-length information.

For example, one client may have one beneficiary while another may have eight.

Hard-coding eight beneficiary sections creates empty pages and awkward formatting. Instead, use a Docassemble list and repeat the relevant content.

The interview can gather beneficiaries into a list:

objects:
  - beneficiaries: DAList.using(object_type=Individual, complete_attribute='complete')

The DOCX template can then loop through the list:
{% for person in beneficiaries %}

{{ loop.index }}. {{ person.name.full() }} — {{ person.relationship }}

{% endfor %}

Repeating logic is useful for:

  • Beneficiaries
  • Children
  • Assets
  • Properties
  • Debts
  • Parties
  • Witnesses
  • Employment history
  • Legal claims
  • Supporting documents

Tables should be tested with both short and long content. A template that looks perfect with two rows may fall apart spectacularly with twenty-two.

Adding Images, Signatures, and Uploaded Files

Docassemble can collect touchscreen signatures and insert them into generated documents.

A signature question may look like:

question: |

  Please sign below

signature: client_signature

under: |

  ${ client.name.full() }

The resulting signature can be inserted into a DOCX or PDF document where appropriate.

Docassemble can also work with:

  • Uploaded photographs
  • Scanned evidence
  • Identification documents
  • Logos
  • Supporting PDFs
  • Exhibits
  • Diagrams

When combining uploaded files with generated documents, think carefully about:

  • File type validation
  • Maximum upload size
  • Page orientation
  • Document order
  • Security
  • Malware scanning
  • Retention policy
  • User permissions

Just because a file can be attached does not mean it should remain on the server forever.

Generating Both PDF and Word Documents

One major advantage of Docassemble PDF and Word Document Automation is the ability to provide multiple formats from a single DOCX template.

A legal team may want:

  • DOCX for attorney editing
  • PDF for client review
  • PDF/A for archiving
  • A signed final PDF
  • A combined document package

The attachment can be configured with permitted output formats.

For example:

attachment:
  name: Final agreement
  filename: final_agreement
  docx template file: final_agreement.docx
  valid formats:
    - pdf
    - docx

This gives users both an editable Word document and a PDF copy.

Before relying on automated conversion, test the PDF output carefully. Word-to-PDF conversion can expose issues involving:

  • Fonts
  • Page breaks
  • Table widths
  • Headers
  • Footers
  • Images
  • Numbering
  • Margins

The DOCX may look perfect in Microsoft Word but slightly different after server-side conversion.

Supporting Multiple States and Jurisdictions

US legal organizations frequently need different templates or clauses for different jurisdictions.

A workflow may select a template based on state:

attachment:
  name: State-specific document
  filename: state_document
  docx template file:
    code: |
      "agreement_" + client.address.state.lower() + ".docx"

This could select:

  • agreement_ca.docx
  • agreement_tx.docx
  • agreement_ny.docx

Another approach is to use one master template with conditional clauses. The correct strategy depends on how different the documents are.

Use separate templates when:

  • Layouts differ significantly
  • State forms are officially prescribed
  • Signature rules vary
  • Entire sections change
  • Different teams own each jurisdiction

Use conditional clauses when:

  • Most of the document is shared
  • Only selected language changes
  • Centralized maintenance is important
  • State differences are limited

Organizations managing many templates should implement clear governance. Our template management and version control services help legal teams organize approved templates, jurisdictional variations, and document updates without relying on mysterious filenames such as final_final_v7_revised_REAL.docx.

Custom Document Generation With Docassemble

Custom Document Generation with Docassemble becomes valuable when a workflow needs more than basic field replacement.

Advanced implementations may include:

  • Calculations
  • Clause libraries
  • Multi-user review
  • Attorney approval
  • API data
  • Electronic signatures
  • Payment collection
  • Case-management integration
  • Document bundles
  • Multilingual output
  • Automated email delivery
  • Audit trails

For example, a legal-aid organization could:

  1. Screen a user for eligibility.
  2. Ask jurisdiction-specific questions.
  3. Generate a court form.
  4. Create an instructions letter.
  5. Attach uploaded evidence.
  6. Send the package to a case-management system.
  7. Notify a staff reviewer.

This is where professional custom Docassemble development services can help turn static templates into maintainable workflows.

Migrating Legacy Forms Into Docassemble

Many US law firms, courts, and legal-aid organizations still rely on older PDF forms, Word templates, spreadsheets, and manual questionnaires.

A legacy migration project typically involves:

  • Auditing existing documents
  • Identifying duplicate templates
  • Mapping form fields
  • Standardizing variables
  • Converting static forms into interviews
  • Adding conditional logic
  • Testing document output
  • Defining ownership and version control

Not every old form should be automated exactly as it exists.

Sometimes the best solution is to simplify the workflow before rebuilding it. Automating a confusing form does not make it less confusing. It simply delivers confusion faster.

Our legacy form migration services help organizations convert outdated forms into guided, maintainable digital workflows.

Common Docassemble Template Development Problems

Missing or Undefined Variables

If a template references a variable that the interview has not defined, document generation may fail.

Test every possible interview path, especially optional and conditional sections.

Broken DOCX Formatting

Copying content from older Word documents can introduce hidden styles, section breaks, and corrupted formatting.

Use clean styles and avoid unnecessary manual formatting.

Blank Pages

Blank pages are often caused by:

  • Extra paragraph marks
  • Page breaks
  • Section breaks
  • Hidden table rows
  • Conditional content leaving empty spaces

Tables Extending Beyond the Page

Test long names, addresses, and repeated rows. Set sensible column widths and avoid overloading one table with too much information.

Incorrect PDF Field Mapping

PDF field names are case-sensitive and may have unexpected export values. Verify every checkbox, radio button, and field.

Inconsistent Dates and Currency

Create reusable formatting functions for:

  • Dates
  • Currency
  • Percentages
  • Phone numbers
  • Addresses
  • Names

Consistency makes the generated document feel deliberate rather than stitched together.

Testing Docassemble PDF and DOCX Documents

Document testing should cover more than one happy-path client.

Create test cases for:

  • Single and married users
  • Users with no children
  • Users with many children
  • Long legal names
  • Long addresses
  • Missing optional data
  • Multiple states
  • Multiple languages
  • Large uploaded files
  • Empty lists
  • Maximum list sizes
  • Special characters
  • Signatures
  • DOCX and PDF outputs

Review:

  • Legal accuracy
  • Clause selection
  • Formatting
  • Page numbering
  • Headers and footers
  • Table behavior
  • Signature placement
  • File naming
  • Accessibility
  • Download experience

For legal documents, include attorney or subject-matter review before production release.

Best Practices for Docassemble Document Automation

Use clear variable names and reusable objects.

Keep complex logic in YAML or Python instead of hiding too much logic inside Word templates.

Create reusable clauses and functions for repeated legal language.

Separate development, testing, and production environments.

Track template versions and approvals.

Test PDF conversion whenever a DOCX template changes.

Document the relationship between interview questions and document clauses.

Limit data collection to what the workflow actually needs.

Create audit logs for important generation events.

Plan for template updates from day one.

Reliable Docassemble Automation Services should not simply produce the correct document once. They should make the workflow maintainable when laws, forms, staff, and requirements change.

Final Thoughts 

Docassemble makes it possible to transform static PDF and Word templates into guided, intelligent document workflows.

PDF templates work well for fixed forms and official layouts. DOCX templates are usually better for contracts, letters, agreements, and documents with variable clauses or repeating sections.

The technology is only one part of the solution.

Successful Docassemble Document Generation requires:

  • Well-designed interview questions
  • Clear variable structures
  • Reliable legal logic
  • Clean templates
  • Strong testing
  • Template governance
  • Secure deployment
  • Ongoing maintenance

Start with the document, but do not stop there. Map the full workflow: who provides the information, who reviews it, where the output is stored, and what happens after generation.

That is the difference between a document that happens to be automated and a document automation system that people can actually depend on.

For organizations planning a complete implementation, Docassemble Development Services can support interview design, template automation, integrations, testing, deployment, and ongoing improvements.

Ready to Automate PDF and DOCX Documents With Docassemble?

Start Your Docassemble Project

FAQ

1. Can Docassemble generate both PDF and DOCX documents?

Yes. Docassemble can generate completed PDF forms and editable DOCX files from the same guided interview. PDF templates are usually better for fixed court or government forms, while DOCX templates work well for contracts, letters, agreements, and other documents where the content or page length may change.

2. What is the difference between Docassemble PDF generation and DOCX generation?

Docassemble PDF generation fills predefined fields inside an existing PDF form, so the layout generally remains fixed. DOCX generation uses a Microsoft Word template that can include dynamic paragraphs, conditional clauses, repeating tables, images, and signatures. In simple terms, PDFs are excellent for staying inside the lines, while DOCX templates have more room to move.

3. Can Docassemble add conditional clauses to legal documents?

Yes. Docassemble can include or remove clauses based on a user’s answers. For example, a document can display different language depending on marital status, state of residence, number of children, asset ownership, or selected legal services. This allows one interview to generate documents tailored to different client situations.

4. Can Docassemble generate repeating tables and lists?

Yes. Docassemble can generate repeating content for beneficiaries, children, assets, properties, witnesses, debts, or other collections of information. A DOCX template can automatically add one row or section for every item entered during the interview, so you do not need to create ten empty rows “just in case.”

5. Can signatures and uploaded files be included in Docassemble documents?

Yes. Docassemble can collect electronic signatures and place them inside generated PDF or DOCX documents. It can also work with uploaded files such as identification documents, photographs, exhibits, and supporting evidence. File validation, security, storage, and retention rules should be planned carefully before launch.

6. Can one Docassemble interview generate both a Word file and a PDF?

Yes. A DOCX template can usually be used to provide an editable Word document and a converted PDF version. This is useful when attorneys need to revise the Word file while clients or other parties receive a polished PDF. Both outputs should be tested because formatting can change slightly during PDF conversion.

7. What are the most common problems in Docassemble document generation?

Common problems include undefined variables, incorrect PDF field names, broken Word formatting, blank pages, long text overflowing fields, tables extending beyond the page, and conditional sections leaving unwanted spaces. Thorough testing with different user scenarios is essential because the document that works perfectly for one client may behave very differently for another.

en_USEnglish
Scroll to Top