Skip to content

PDF

Pull tables, words with their positions, page geometry, form fields and metadata out of PDFs, and render pages to PNG

Connector software
Free and open source
Service credentials
Not needed
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/pdf/index.md to help me query PDF with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

List each page's width and height.

Example output · captured
Connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
SET VARIABLE doc = (SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/multipage.pdf'));
SELECT page, width, height FROM pdf.main.pages(pdf := getvariable('doc'))
Result
page width height
1 612 792
2 612 792
3 612 792

Quick start

Choose where to run PDF, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'pdf' AS pdf (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-pdf-worker'
);

3. Run a query

query.sql
SET VARIABLE doc = (SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/multipage.pdf'));
SELECT page, width, height FROM pdf.main.pages(pdf := getvariable('doc'))
More example queries →
Technical details
Verified connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'pdf' AS pdf (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-pdf-worker'
);

Overview

Extract PDF structure (tables, word boxes, geometry, forms, metadata) and render pages to PNG.

Catalog

Everything pdf exposes once attached — read straight from the worker's released build.

pdf 1 schema
main 1 view · 8 functions

Extract PDF structure: tables, word boxes, geometry, forms, metadata, rendering

Schema examples (13)
Examples (13)

Count the pages in a PDF file.

SELECT pdf.main.page_count((SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/multipage.pdf')));

Check whether a PDF is encrypted.

SELECT pdf.main.is_encrypted((SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/form.pdf')));

Read the Title from a PDF's document metadata.

SELECT pdf.main.pdf_metadata((SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/meta.pdf')))['Title'];

Read a single AcroForm field value by name.

SELECT pdf.main.form_fields((SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/form.pdf')))['full_name'];
9 more examples

Render page 1 to a PNG and measure its byte size.

SELECT octet_length(pdf.main.render_page((SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/multipage.pdf')), 1));

List each page's width and height.

SET VARIABLE doc = (SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/multipage.pdf'));
SELECT page, width, height FROM pdf.main.pages(pdf := getvariable('doc'));
Result
page width height
1 612 792
2 612 792
3 612 792

Extract word text in reading order.

SET VARIABLE doc = (SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/words.pdf'));
SELECT page, text FROM pdf.main.words(pdf := getvariable('doc')) ORDER BY page, top, x0;

Pull detected table cells in long format.

SET VARIABLE doc = (SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/table.pdf'));
SELECT page, "row", col, value FROM pdf.main.tables(pdf := getvariable('doc'));

Browse the worker's object registry.

SELECT name, kind, category FROM pdf.main.functions ORDER BY category, name;

Triage a batch of PDFs in one pass: page count, encryption flag, metadata Author, and number of AcroForm fields per file (a non-PDF file comes back all NULL)

SELECT parse_filename(filename) AS file,
  pdf.main.page_count(content) AS pages,
  pdf.main.is_encrypted(content) AS encrypted,
  pdf.main.pdf_metadata(content)['Author'] AS author,
  cardinality(pdf.main.form_fields(content)) AS form_field_count
FROM read_blob(['https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/multipage.pdf', 'https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/meta.pdf', 'https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/form.pdf', 'https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/garbage.pdf'])
ORDER BY file;

Render a 36-DPI PNG thumbnail of every page that pages() lists and report its size in bytes, next to the page's width and height

SET VARIABLE doc = (SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/multipage.pdf'));
SELECT p.page, p.width, p.height, octet_length(pdf.main.render_page(getvariable('doc'), p.page, 36)) AS thumbnail_png_bytes FROM pdf.main.pages(pdf := getvariable('doc')) AS p ORDER BY p.page;

Find the words in each page's header band (top 10% of the page height), joining words() to pages() for the height

SET VARIABLE doc = (SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/words.pdf'));
SELECT w.page, w.text, round(w.top / p.height, 3) AS top_fraction FROM pdf.main.words(pdf := getvariable('doc')) AS w JOIN pdf.main.pages(pdf := getvariable('doc')) AS p ON p.page = w.page WHERE w.top < 0.1 * p.height ORDER BY w.page, w.top, w.x0;

Locate each table cell on the page: join tables() cells to words() boxes on matching text (single-word cells)

SET VARIABLE doc = (SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/table.pdf'));
SELECT t."row", t.col, t.value, w.x0, round(w.top, 1) AS top FROM pdf.main.tables(pdf := getvariable('doc')) AS t JOIN pdf.main.words(pdf := getvariable('doc')) AS w ON w.page = t.page AND w.text = t.value ORDER BY t.page, t.table_index, t."row", t.col;
Views
functions 3 examples4 cols

Registry of every object this worker exposes (name, kind, category, summary).

Columns
name VARCHAR
Object name (call it as pdf.main.<name>).
kind VARCHAR
'scalar', 'table function', or 'view'.
category VARCHAR
Category grouping: Structure, Content, Metadata, Rendering, or Discovery.
summary VARCHAR
One-line description of what the object returns.
Examples (3)

Browse every object the worker exposes, grouped by category

SELECT name, kind, category FROM pdf.main.functions ORDER BY category, name;

List just the content-extraction objects

SELECT name, summary
FROM pdf.main.functions
WHERE category = 'Content'
ORDER BY name;

Count how many objects the worker exposes

SELECT count(*) AS object_count FROM pdf.main.functions;
Link
Scalar functions
form_fields (pdf VARCHAR) +1 overload 2 examples

AcroForm field name->value map of a PDF (VARCHAR path)

Arguments
pdf VARCHAR
Filesystem path to a PDF.
Overloads
form_fields(pdf VARCHAR) → MAP(VARCHAR, VARCHAR)form_fields(pdf BLOB) → MAP(VARCHAR, VARCHAR)
ReturnsMAP(VARCHAR, VARCHAR)
Examples (2)

Read the 'full_name' AcroForm field (returns 'Ada Lovelace')

SELECT pdf.main.form_fields((SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/form.pdf')))['full_name'] AS full_name;

Form fields of a fillable PDF held as bytes (NULL for non-PDF bytes)

SELECT pdf.main.form_fields('not-a-pdf'::BLOB) AS fields;
Link
is_encrypted (pdf VARCHAR) +1 overload 2 examples

True if the PDF (VARCHAR path) is encrypted, NULL if unreadable

Arguments
pdf VARCHAR
Filesystem path to a PDF.
Overloads
is_encrypted(pdf VARCHAR) → BOOLEANis_encrypted(pdf BLOB) → BOOLEAN
ReturnsBOOLEAN
Examples (2)

Whether a sample PDF fetched with read_blob is encrypted (false)

SELECT pdf.main.is_encrypted((SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/form.pdf'))) AS encrypted;

Whether a PDF held as bytes is encrypted (NULL for non-PDF bytes)

SELECT pdf.main.is_encrypted('not-a-pdf'::BLOB) AS encrypted;
Link
page_count (pdf VARCHAR) +1 overload 3 examples

Number of pages in a PDF (VARCHAR path), or NULL if unreadable

Arguments
pdf VARCHAR
Filesystem path to a PDF.
Overloads
page_count(pdf VARCHAR) → INTEGERpage_count(pdf BLOB) → INTEGER
ReturnsINTEGER
Examples (3)

Page count of a sample PDF fetched with read_blob (returns 3)

SELECT pdf.main.page_count((SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/multipage.pdf'))) AS pages;

Page count of a PDF held as bytes (NULL for non-PDF bytes)

SELECT pdf.main.page_count('not-a-pdf'::BLOB) AS pages;

Triage a batch of PDFs in one pass: page count, encryption flag, metadata Author, and number of AcroForm fields per file (a non-PDF file comes back all NULL)

SELECT parse_filename(filename) AS file,
  pdf.main.page_count(content) AS pages,
  pdf.main.is_encrypted(content) AS encrypted,
  pdf.main.pdf_metadata(content)['Author'] AS author,
  cardinality(pdf.main.form_fields(content)) AS form_field_count
FROM read_blob(['https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/multipage.pdf', 'https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/meta.pdf', 'https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/form.pdf', 'https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/garbage.pdf'])
ORDER BY file;
Link
pdf_metadata (pdf VARCHAR) +1 overload 2 examples

Document metadata (Title/Author/Producer/...) of a PDF (VARCHAR path)

Arguments
pdf VARCHAR
Filesystem path to a PDF.
Overloads
pdf_metadata(pdf VARCHAR) → MAP(VARCHAR, VARCHAR)pdf_metadata(pdf BLOB) → MAP(VARCHAR, VARCHAR)
ReturnsMAP(VARCHAR, VARCHAR)
Examples (2)

Title from a sample PDF's metadata (returns 'Quarterly Report')

SELECT pdf.main.pdf_metadata((SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/meta.pdf')))['Title'] AS title;

Author from PDF bytes' metadata (NULL for non-PDF bytes)

SELECT pdf.main.pdf_metadata('not-a-pdf'::BLOB)['Author'] AS author;
Link
render_page (pdf VARCHAR, page INTEGER, dpi INTEGER) +3 overloads 4 examples

Render one (1-based) page of a PDF (VARCHAR path) to a PNG BLOB (default 150 DPI)

Arguments
pdf VARCHAR
Filesystem path to a PDF.
page INTEGER
1-based page number.
dpi INTEGER
Render resolution in DPI (capped at 300).
Overloads
render_page(pdf VARCHAR, page INTEGER) → BLOBrender_page(pdf VARCHAR, page INTEGER, dpi INTEGER) → BLOBrender_page(pdf BLOB, page INTEGER) → BLOBrender_page(pdf BLOB, page INTEGER, dpi INTEGER) → BLOB
ReturnsBLOB
Examples (4)

Render page 1 to a PNG and report its byte size

SELECT octet_length(pdf.main.render_page((SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/multipage.pdf')), 1)) AS png_bytes;

Render page 1 at 72 DPI and report its byte size

SELECT octet_length(pdf.main.render_page((SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/multipage.pdf')), 1, 72)) AS png_bytes;

Rendering non-PDF bytes yields NULL rather than an error

SELECT pdf.main.render_page('not-a-pdf'::BLOB, 1) IS NULL AS unreadable;
1 more example

Rendering non-PDF bytes at 72 DPI yields NULL rather than an error

SELECT pdf.main.render_page('not-a-pdf'::BLOB, 1, 72) IS NULL AS unreadable;
Link
Table functions
pages (pdf := ANY) 3 examples

Per-page geometry (page, width, height, rotation) of a PDF (VARCHAR path or BLOB bytes)

Named arguments
pdf := ANY
The PDF to read: either a filesystem path the worker opens, or the raw PDF bytes themselves.
Returns columns
page INTEGER
1-based page number.
width DOUBLE
Page width in PDF points (1 pt = 1/72 inch).
height DOUBLE
Page height in PDF points (1 pt = 1/72 inch).
rotation INTEGER
Page rotation in degrees (0, 90, 180, or 270).
Examples (3)
SET VARIABLE doc = (SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/multipage.pdf'));
SELECT page, width, height, rotation FROM pdf.main.pages(pdf := getvariable('doc')) ORDER BY page;
SET VARIABLE doc = (SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/multipage.pdf'));
SELECT count(*) AS landscape_pages FROM pdf.main.pages(pdf := getvariable('doc')) WHERE width > height;
SET VARIABLE doc = (SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/multipage.pdf'));
SELECT p.page, p.width, p.height, octet_length(pdf.main.render_page(getvariable('doc'), p.page, 36)) AS thumbnail_png_bytes FROM pdf.main.pages(pdf := getvariable('doc')) AS p ORDER BY p.page;
Link
tables (page := INTEGER, pdf := ANY) 3 examples

Long-format table cells (page, table_index, row, col, value) of a PDF (VARCHAR path or BLOB bytes)

Named arguments
page := INTEGER
Optional 1-based page number to restrict to (NULL = all pages). · default null
pdf := ANY
The PDF to read: either a filesystem path the worker opens, or the raw PDF bytes themselves.
Returns columns
page INTEGER
1-based page number the cell is on.
table_index INTEGER
0-based table ordinal within the page.
row INTEGER
0-based row index in the table (SQL keyword: quote as "row").
col INTEGER
0-based column index within the table.
value VARCHAR
Cell text (NULL for an empty/missing cell).
Examples (3)
SET VARIABLE doc = (SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/table.pdf'));
SELECT page, table_index, "row", col, value FROM pdf.main.tables(pdf := getvariable('doc')) ORDER BY page, table_index, "row", col LIMIT 8;
SET VARIABLE doc = (SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/table.pdf'));
SELECT count(*) AS cells FROM pdf.main.tables(pdf := getvariable('doc'), page := 1);
SET VARIABLE doc = (SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/table.pdf'));
SELECT t."row", t.col, t.value, w.x0, round(w.top, 1) AS top FROM pdf.main.tables(pdf := getvariable('doc')) AS t JOIN pdf.main.words(pdf := getvariable('doc')) AS w ON w.page = t.page AND w.text = t.value ORDER BY t.page, t.table_index, t."row", t.col;
Link
words (page := INTEGER, pdf := ANY) 3 examples

Per-word bounding boxes (page, text, x0, top, x1, bottom) of a PDF (VARCHAR path or BLOB bytes)

Named arguments
page := INTEGER
Optional 1-based page number to restrict to (NULL = all pages). · default null
pdf := ANY
The PDF to read: either a filesystem path the worker opens, or the raw PDF bytes themselves.
Returns columns
page INTEGER
1-based page number the word is on.
text VARCHAR
The word's text.
x0 DOUBLE
Left edge, in PDF points from the left.
top DOUBLE
Top edge, in PDF points from the top.
x1 DOUBLE
Right edge, in PDF points from the left.
bottom DOUBLE
Bottom edge, in PDF points from the top.
Examples (3)
SET VARIABLE doc = (SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/words.pdf'));
SELECT page, text, x0, top FROM pdf.main.words(pdf := getvariable('doc')) ORDER BY top, x0 LIMIT 5;
SET VARIABLE doc = (SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/words.pdf'));
SELECT count(*) AS words_on_page_1 FROM pdf.main.words(pdf := getvariable('doc'), page := 1);
SET VARIABLE doc = (SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/words.pdf'));
SELECT w.page, w.text, round(w.top / p.height, 3) AS top_fraction FROM pdf.main.words(pdf := getvariable('doc')) AS w JOIN pdf.main.pages(pdf := getvariable('doc')) AS p ON p.page = w.page WHERE w.top < 0.1 * p.height ORDER BY w.page, w.top, w.x0;
Link

Try these queries

Count the pages in a PDF file.

SELECT pdf.main.page_count((SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/multipage.pdf')))

Uses page_count

Check whether a PDF is encrypted.

SELECT pdf.main.is_encrypted((SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/form.pdf')))

Uses is_encrypted

Read the Title from a PDF's document metadata.

SELECT pdf.main.pdf_metadata((SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/meta.pdf')))['Title']

Uses pdf_metadata

Read a single AcroForm field value by name.

SELECT pdf.main.form_fields((SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/form.pdf')))['full_name']

Uses form_fields

Render page 1 to a PNG and measure its byte size.

SELECT octet_length(pdf.main.render_page((SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/multipage.pdf')), 1))

Uses render_page

Extract word text in reading order.

SET VARIABLE doc = (SELECT content FROM read_blob('https://raw.githubusercontent.com/Query-farm/vgi-pdf/v0.2.0/test/sql/data/words.pdf'));
SELECT page, text FROM pdf.main.words(pdf := getvariable('doc')) ORDER BY page, top, x0

Uses words

26 more examples in the Catalog, each listed under the table or function it uses.

PDF is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.