QB Document Generator — User Guide

The QB Document Generator is a cloud service that enables users to create Microsoft Word (.docx) file templates which then can be populated with QuickBase data to create .PDF or .docx output files.


Table of Contents

  1. Required QuickBase Tables
  2. Authoring a Template Document
  3. Triggering Document Generation
  4. URL Parameter Reference
  5. Token Reference
  6. Subtable Configuration
  7. Field Type Support
  8. Images
  9. Image Output (JPEG / PNG)
  10. HTML Rich Text
  11. Barcodes
  12. Troubleshooting

1. Required QuickBase Tables

Two QB tables must be created inside the QB application. The FIDs shown below are the defaults the worker expects. If your tables were created in a different order and have different FIDs, you can override each one with a URL parameter (see §4).

1a. Document Templates

Stores the Word template files.

# Field Name Type Default FID URL Param Override Notes
1 Template Name Text 6 Descriptive name
2 Description Text 7 Optional notes
3 MS Word Template File File Attachment 8 tpfilefid Required — the .docx template
4 Active Checkbox 9 Optional status flag
5 No Data Message Text 10 tpndmfid Shown in subtables when query returns 0 rows
6 Output Type Text 11 Optional label
7 Related App Text 12 Optional
8 Subtables DBID Formula — Text 13 tpstdbfid Required — formula: [_DBID_DOCUMENT_SUBTABLES]

Tip: Create fields in the order above and the built-in QB fields (Record ID#, Date Created, etc., FIDs 1–5) will result in the worker's default FIDs being assigned automatically — no URL overrides needed.

The No Data Message (FID 10) is displayed in a subtable when the QB query returns zero rows. Leave blank to suppress the table entirely when empty.

The Subtables DBID (FID 13) must be a Formula — Text field containing exactly:

[_DBID_DOCUMENT_SUBTABLES]

This is a QB table name reference that resolves to the DBID of your Document Subtables table.

1b. Document Subtables

Stores per-template subtable configurations (one record per subtable section).

# Field Name Type Default FID URL Param Override Notes
1 Settings Multi-Line Text 6 stcfgfid Required — the subtable config string (see §6)

Tip: Settings should be the first user-created field so QB assigns FID 6 automatically.

1c. Your Application Table(s)

The worker reads data from whatever table you point it at (msdb). No changes required to existing tables, except:


2. Authoring a Template Document

Create a standard .docx file in Word. Replace the data you want populated with tokens.

Token Overview

Token Purpose
~FID~ Insert a field value from the master record
~I:FID:SIZE~ Insert an image from the master record with explicit sizing
​=barcode(f[FID],type,WxH) Render a barcode
~strid=N~ Replace this paragraph with a subtable

Tip: Word sometimes splits tokens across multiple text runs (e.g. ~12 in one run and 3~ in another). The worker automatically merges adjacent runs before substitution, so tokens will resolve correctly even if Word has split them.

Example Template Snippet

Invoice #: ~6~                    Date: ~8~
Bill To:   ~45~

~strid=1~          ← this paragraph becomes the line-items table

Notes: ~92~

Uploading the Template

Attach the .docx file to the MS Word Template File field (FID 8) of the corresponding record in your Document Templates table.


3. Triggering Document Generation

Add a Formula — URL field to your source table. When clicked, it calls the worker.

Minimal Formula (DOCX output)

"https://gen.baseforbusinessutilities.com/doc_generator"
& "?clientid=my-client-id"
& "&tpdbid=TEMPLATES_TABLE_DBID"
& "&tpid=TEMPLATE_RECORD_ID"
& "&msdb=" & Dbid()
& "&msid=" & [Record ID#]
& "&faid=OUTPUT_FIELD_ID"
& "&fn=" & URLEncode([Invoice #])
& "&docfmt=docx"

PDF Output

& "&docfmt=pdf"

Image Output (JPEG or PNG)

& "&docfmt=jpeg"
& "&docfmt=png"

Single-page documents return the image file directly. Multi-page documents return a .zip archive containing page-0001.jpg (or .png), page-0002.jpg, etc.

Append or Prepend Existing PDF Files

Use addfiles and/or prefiles to merge one or more existing QB file attachment PDFs around the generated document before it is uploaded. Works with both pdf and image output formats.

Each parameter is a dot-separated list of file references. Three reference formats are supported:

Format Example Description
Field ID 227 File attached to that field on the master record
Cross-table ref dbid:rid:fid File in another table (DBID, record ID, field ID)
Indirect ref FID123 Value of field 123 is itself a dbid:rid:fid pointer
& "&prefiles=227"                          ← prepend field 227 attachment
& "&addfiles=228"                          ← append field 228 attachment
& "&addfiles=227.bu5h2c6bg:42:15"         ← field 227 + a cross-table ref

Stamp a "Last Generated" Field

& "&efpdte=DATETIME_FIELD_ID"

Stream File to Browser (in addition to QB upload)

& "&stream=y"

Fire a Pre-Generation Action

Executes a URL (fire-and-forget) before the document is built — useful for triggering a QB action or webhook:

& "&preqbaction=" & URLEncode("https://yourcompany.quickbase.com/db/TABLE?a=API_EditRecord&...")

4. URL Parameter Reference

Core Parameters

Parameter Required Description
clientid Yes Key in the QB_CLIENTS KV store; identifies the QB app credentials
tpdbid Yes DBID of the Document Templates table
tpid Yes Record ID of the template to use
msdb Yes DBID of the source (master) table
msid Yes Record ID of the source record
faid Yes Field ID on msdb where the generated file is uploaded
fn No Output filename without extension (default: document)
docfmt No Output format: docx (default), pdf, jpeg, or png
preqbaction No URL to fire before generation (fire-and-forget)
efpdte No Field ID on msdb to stamp with the generation timestamp (ms since epoch)
stream No y — also stream the file back as a browser download
addfiles No Dot-separated file refs to append after the generated document (PDF/image only)
prefiles No Dot-separated file refs to prepend before the generated document (PDF/image only)
appid No Ignored; accepted for URL compatibility

FID Override Parameters

Use these when your Document Templates or Document Subtables table has different field IDs than the defaults. All are optional — omit them if your tables use the standard field layout from §1.

Parameter Default Overrides
tpfilefid 8 FID of the DOCX file attachment in the Document Templates table
tpndmfid 10 FID of the No Data Message in the Document Templates table
tpstdbfid 13 FID of the Subtables DBID formula in the Document Templates table
stcfgfid 6 FID of the Settings string in the Document Subtables table

5. Token Reference

5a. Field Substitution — ~FID~

Replaces the token with the value of field FID from the master record.

~168~       → value of field 168
~45~        → value of field 45

5b. Sized Image — ~I:FID:SIZE~

Embeds an image from field FID at a specific size. The token must be the only content of its paragraph (on its own line). Case-insensitive (~i:~ and ~I:~ both work).

Size Format Meaning
~I:23:100~ Width = 100 px; height proportional
~I:23:100x50~ Exact 100 × 50 px (may distort)
~I:23:25%~ 25% of original dimensions
~I:23:25%F~ Same as 25% ("fixed percent")

5c. Barcode — =barcode(f[FID],type,WxH)

Generates a barcode image from the value of field FID. See §11 for full details.

=barcode(f[123],qrcode,60x60)

=barcode(f[123],code128-b,200x80)

5d. Subtable — ~strid=N~

Replaces the entire paragraph with a formatted table built from a QB query. N is the Record ID of the configuration record in the Document Subtables table.

~strid=4~

6. Subtable Configuration

Each subtable is configured by a record in the Document Subtables table. The entire configuration lives in a single text string in field 6.

Settings String Format

~dbid=TABLE_DBID,qry={QUERY},hdr=#COLOR-COLOR,sub=#COLOR-#COLOR,align=ALIGN,slist=FID,clist=COLUMNS~

All parts are comma-separated key=value pairs. clist must always be last because column definitions can contain commas.

Key Required Description
dbid Yes DBID of the table to query
qry Yes QB query string; use [Record ID#] as a placeholder for the master record ID
hdr No Header row colors: #RRGGBB-colorname (bg-text). Default: #808080-white
sub No Row colors: #RRGGBB-#RRGGBB (odd-even). Default: #FFFFFF-#FFFFFF
align No Table alignment: l, c, or r. Default: l
slist No Sort field ID
clist Yes Column definitions (see below)

Query Placeholder

Use [Record ID#] anywhere in the qry string — it is replaced with the master record's ID at runtime:

qry={'165'.EX.[Record ID#]}AND{'655'.EX.'0'}

Column Definition Format (clist)

Columns are separated by . (dot). Each column follows one of two formats:

Standard column: [ALIGN][TYPE][FID]:[WIDTH_PX]:[HEADER]

Image column: [ALIGN]I[FID]:[SIZE]:[HEADER] (no colon between I and FID)

Part Values Description
ALIGN L R C Left, Right, Center
TYPE (blank or T) Plain text
$ Currency — formats as $1,234.56
I Image column (file attachment or <img> HTML field)
FID number QB field ID
WIDTH_PX number Column width in pixels
SIZE see below For image columns: size specification
HEADER text Column header text

Image column size formats:

Format Meaning
200 Width = 200 px; height proportional
100x50 Exact 100 × 50 px
25% 25% of original dimensions
25%F Same as 25%

Full Example

~dbid=bhkkqamev,qry={'165'.EX.[Record ID#]}AND{'655'.EX.'0'},hdr=#848484-white,sub=#FFFFFF-#F0F0F0,align=c,slist=314,clist=LT14:70:ITEM.CT124:200:DESCRIPTION.RF18:70:QTY.CN1245:70:UNITS.R$787:70:PRICE.R$24:70:AMOUNT~

Broken down:

Column Spec Align Type FID Width Header
LT14:70:ITEM Left Text 14 70 px ITEM
CT124:200:DESCRIPTION Center Text 2688 200 px DESCRIPTION
RF18:70:QTY Right Text 2146 70 px QTY
CN1245:70:UNITS Center Text 1245 70 px UNITS
R$787:70:PRICE Right Currency 787 70 px PRICE
R$24:70:AMOUNT Right Currency 24 70 px AMOUNT

No-Data Message

When a subtable query returns zero rows, the worker displays a single merged-cell row with the text from the No Data Message field (FID 10) of the template record. If that field is blank, the table is omitted entirely.


7. Field Type Support

The following QuickBase field types are handled automatically when used with ~FID~ tokens:

QB Field Type Rendering
Text Plain text insertion
Multi-Line Text Plain text; <BR> tags converted to line breaks
Rich Text / Formula returning HTML Full HTML-to-Word conversion (see §10)
Numeric Raw value
Currency Formatted as $1,234.56
Date Formatted as MM-DD-YYYY
Date/Time (Timestamp) Formatted as MM-DD-YYYY
Checkbox true / false
File Attachment (dbfile) — image Image embedded inline (see §8)
File Attachment (dbfile) — non-image Silently suppressed (raw filename/URL is never shown)
Formula — Text returning <img> HTML Image embedded inline (see §8)
Formula — URL Plain URL text
Formula — any other Treated as text

8. Images

8a. Master Record — Auto-Embed (~FID~)

If a field's value is a file attachment or an HTML <img> tag, the image is automatically embedded when you use a plain ~FID~ token on its own paragraph line. The image is scaled to fill the full content width.

~227~        ← if field 227 is a file attachment or <img> HTML, renders as an image

8b. Master Record — Explicit Size (~I:FID:SIZE~)

Use this token when you need precise control over image dimensions. Place it alone on its own paragraph line:

~I:227:300~          width = 300 px, height proportional
~I:227:300x200~      exactly 300 × 200 px
~I:227:50%~          50 % of original size

8c. Subtable Image Columns

Use I as the type character in a clist column definition. The worker tries the QB REST API first (file attachment fields), then falls back to extracting a URL from the field value (formula fields returning <img> HTML):

CI2688:200:PHOTO        center-aligned, FID 2688, 200 px wide, header "PHOTO"
CI2688:100x50:PHOTO     exact 100 × 50 px
LI:2688:25%:PHOTO       left-aligned, 25% of original size

8d. Subtable Auto-Image (HTML Fields)

Any subtable text column whose field value is an <img src="URL"> HTML tag will automatically render the image — no special column type needed. The image is scaled to the column width.

This is useful for formula fields that generate barcode <img> tags or reference external image URLs.

Supported Image Formats

PNG, JPEG, GIF, WebP


9. Image Output (JPEG / PNG)

When docfmt=jpeg or docfmt=png is used, the worker converts the generated document to rasterised images via Gotenberg (LibreOffice → PDF → Chromium/PDF.js render).

Single-page documents

The image file is returned directly and uploaded to QB as a .jpg or .png.

Multi-page documents

A .zip archive is returned containing one image per page, named sequentially:

page-0001.jpg
page-0002.jpg
page-0003.jpg
...

The worker detects this automatically — the QB file attachment field will receive a .zip file. Your formula URL does not need to change; the extension is set automatically based on the output.

With addfiles / prefiles

When addfiles or prefiles is used with an image format, the referenced PDFs are merged with the generated PDF before rasterisation. The final ZIP (or single image) covers all pages from all merged documents.

Requirements

Image output requires the Gotenberg secrets to be configured:

GOTENBERG_URL
GOTENBERG_CLIENT_ID
GOTENBERG_CLIENT_SECRET

10. HTML Rich Text

When a ~FID~ token's value is HTML, it is converted to Word (OOXML) formatting automatically.

Supported HTML Elements

HTML Word Output
<b>, <strong> Bold
<i>, <em> Italic
<u> Underline
<br>, <BR/> Line break
<p>, <div> Paragraph
<h1><h6> Headings (bold, sized)
<ul>, <ol>, <li> Bullet / numbered lists
<hr> Horizontal rule
<table>, <tr>, <td>, <th> Embedded table
<img src="..."> Embedded image
<span style="color:..."> Inline text color
<font color="..."> Inline text color

Block vs Inline

The worker detects which case applies automatically.

Example: QB Formula Returning a Table

A QB formula field can produce an HTML table:

<table>
  <tr><th>Tier</th><th>Price</th></tr>
  <tr><td>1–10 units</td><td>$5.00</td></tr>
  <tr><td>11–50 units</td><td>$4.50</td></tr>
</table>

When this field is referenced via ~FID~ on its own paragraph line, the entire HTML table is converted to a Word table and inserted into the document.


11. Barcodes

Use the barcode token to generate and embed a barcode image from a field value.

Token Syntax

~=barcode(f[FID],type,WxH)~
Part Description
FID Field ID whose value becomes the barcode data
type Barcode symbology (see table below)
W Output image width in pixels
H Output image height in pixels

The token is case-insensitive.

Text Display Suffix (Linear Barcodes Only)

Append a suffix to type to control human-readable text:

Suffix Effect
(none) Hide text entirely
-b Show text below the bars
-t Show text above the bars
~=barcode(f[123],code128,200x80)~       no text
~=barcode(f[123],code128-b,200x80)~     text below
~=barcode(f[123],code39-t,150x60)~      text above

Supported Symbologies

type Symbology Dimension
qrcode QR Code 2D
datamatrix Data Matrix 2D
pdf417 PDF417 2D
code128 Code 128 (auto) Linear
code128a Code 128A Linear
code128b Code 128B Linear
code39 Code 39 Linear
code39extended Code 39 Extended Linear
code93 Code 93 Linear
code93extended Code 93 Extended Linear
code11 Code 11 Linear
codabar Codabar Linear
code32 Code 32 Linear
ean8 EAN-8 Linear
ean13 EAN-13 Linear

Examples

~=barcode(f[56],qrcode,80x80)~
~=barcode(f[78],ean13,200x80)~
~=barcode(f[101],code128-b,250x100)~

Barcodes are generated by barcode.tec-it.com at runtime and embedded as GIF images.


12. Troubleshooting

"No file found at Document Templates record…"

The template record exists but has no .docx file attached to FID 8 (the MS Word Template File field). Upload a .docx to that field.

Token not replaced (still shows ~168~ in output)

  1. Confirm the FID is correct — check the field in QB (Admin > Fields).
  2. The field may not be in the master table (msdb). Each token references a field on the master record, not related tables.
  3. The field value might be empty. An empty field still replaces the token with an empty string.

Subtable is missing / not rendered

  1. Confirm ~strid=N~ is on its own paragraph line in the template (no other text in that paragraph).
  2. Confirm the Record ID N exists in the Document Subtables table.
  3. Check the dbid in the settings string — it must match the table you're querying.
  4. Confirm the formula in FID 13 of the template record returns the correct DBID.

Image shows "Picture can't be displayed"

  1. Confirm the image field contains a valid file attachment or a valid <img src="URL"> value.
  2. For external image URLs, confirm the URL is publicly accessible (no authentication required).
  3. QB-hosted image URLs are fetched via the QB REST API using the user token — confirm the token has read access to the source table.

Currency fields show raw numbers

Currency formatting is applied automatically when the QB field type is Currency. If the field is a Formula returning a number, it will not be formatted as currency. Change the field type to Currency in QB, or use a $ type column in subtable clist (e.g. R$24:70:AMOUNT).

Date shows as a raw number (milliseconds)

The field type in QB must be Date or Date/Time. Formula fields returning a date-like number are not automatically formatted. Use a proper Date field in QB.

Barcode renders as empty

  1. Confirm the field value is non-empty for the master record being generated.
  2. Check that the barcode type and data are compatible (e.g. EAN-13 requires exactly 12 or 13 digits).
  3. The tec-it service must be reachable from the Cloudflare Worker — it is a public API with no authentication required.