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
- Query Farm hosting
- Available · $10/month organization minimum
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'))
| 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.
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;
INSTALL vgi FROM community;
LOAD vgi;
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'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'pdf' AS pdf (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-pdf:0.5.0'
);
3. Run a query
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'))
Run the connector on a server you manage. You operate the service and choose who can connect.
1. Deploy the connector on your server
Follow the connector’s deployment instructions. Use its supported HTTP transport, or launch it remotely over SSH. The connection guide explains both options.
2. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
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;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach the connector
For an HTTP deployment, replace the example URL with your endpoint. Add the authentication options your deployment requires. For SSH, use the SSH connection instructions.
ATTACH 'pdf' AS pdf
(TYPE vgi, LOCATION 'https://your-connector.example.com');
4. Run a query
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'))
Query Farm operates PDF for your team. Hosting has a $10 monthly minimum per organization; usage counts toward it. From $2.97 per instance-month ($10 monthly minimum).
1. Create your hosted connector
Open the console, choose your organization and deployment size, and add any service credentials there.
2. Install the vgi extension
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;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach your deployment
Copy the ATTACH statement from your deployment in the console and run it in DuckDB or Haybarn. Use pdf as the catalog alias for the query below.
4. Run a query
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'))
Technical details
- Verified connector release
- v0.5.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
- Verified on
- December 1, 2026
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'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'pdf' AS pdf (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-pdf:0.5.0'
);
Overview
Extract PDF structure (tables, word boxes, geometry, forms, metadata) and render pages to PNG.
Query the structure, layout, and coordinates of PDF documents directly in SQL -- pull tabular data, per-word geometry, page dimensions, form submissions, and document properties, check whether a file is encrypted, and rasterize any page to an image, all streamed to DuckDB over Apache Arrow. Where a plain-text extractor flattens a document to a string, this worker preserves where every word, cell, and box sits on the page.
Who it is for
Built for data engineers, analysts, and document-mining pipelines that need to pull structured data out of reports, invoices, statements, and scanned forms without leaving SQL. Reach for it whenever the position of content matters -- reconstructing tabular layouts, locating text by coordinate, auditing filled-in forms, or generating page thumbnails -- and reach for a plain-text extraction worker instead when you only need the raw prose.
Key concepts
- Path or bytes. Inputs are accepted as either a
VARCHARfilesystem path the worker opens, or aBLOBof raw bytes travelling over Arrow -- so a document already living in a DuckDB column works as directly as a file on disk. - PDF points. All geometry is reported in PDF points (1 pt = 1/72 inch) with the origin at the top-left corner of the page.
- Long-format output. Set-returning functions expand one document into many tidy rows, ready to pivot, filter, and join with ordinary SQL.
Backed by permissive libraries only
Table detection and word geometry come from pdfplumber (docs); high-fidelity page rasterization is powered by pypdfium2 (docs), Google's Chromium PDFium engine; document properties, encryption detection, and AcroForm reading use pikepdf (docs); and rendered bitmaps are encoded to PNG with Pillow (docs). Deliberately never PyMuPDF -- only permissively licensed dependencies.
Catalog
Everything pdf exposes once attached — read straight from the worker's
released build.
main 1 view · 8 functions
Extract PDF structure: tables, word boxes, geometry, forms, metadata, rendering
Schema 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'));
| 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;
functions
Registry of every object this worker exposes (name, kind, category, summary).
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;
form_fields (pdf VARCHAR) +1 overload
AcroForm field name->value map of a PDF (VARCHAR path)
form_fields(pdf VARCHAR) → MAP(VARCHAR, VARCHAR)form_fields(pdf BLOB) → MAP(VARCHAR, VARCHAR)
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;
is_encrypted (pdf VARCHAR) +1 overload
True if the PDF (VARCHAR path) is encrypted, NULL if unreadable
is_encrypted(pdf VARCHAR) → BOOLEANis_encrypted(pdf BLOB) → BOOLEAN
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;
page_count (pdf VARCHAR) +1 overload
Number of pages in a PDF (VARCHAR path), or NULL if unreadable
page_count(pdf VARCHAR) → INTEGERpage_count(pdf BLOB) → INTEGER
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;
pdf_metadata (pdf VARCHAR) +1 overload
Document metadata (Title/Author/Producer/...) of a PDF (VARCHAR path)
pdf_metadata(pdf VARCHAR) → MAP(VARCHAR, VARCHAR)pdf_metadata(pdf BLOB) → MAP(VARCHAR, VARCHAR)
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;
render_page (pdf VARCHAR, page INTEGER, dpi INTEGER) +3 overloads
Render one (1-based) page of a PDF (VARCHAR path) to a PNG BLOB (default 150 DPI)
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
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;
pages (pdf := ANY)
Per-page geometry (page, width, height, rotation) of a PDF (VARCHAR path or BLOB bytes)
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;
tables (page := INTEGER, pdf := ANY)
Long-format table cells (page, table_index, row, col, value) of a PDF (VARCHAR path or BLOB bytes)
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;
words (page := INTEGER, pdf := ANY)
Per-word bounding boxes (page, text, x0, top, x1, bottom) of a PDF (VARCHAR path or BLOB bytes)
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;
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.
Related workers
Docgen
Documents & media
Fill Word templates from query rows to produce invoices, letters and other DOCX or PDF documents
Image
Documents & media
Decode images, read EXIF and GPS tags, spot near-duplicates by perceptual hash, and make thumbnails
Apache Tika
Documents & media
Pull text and metadata out of PDFs, Office files and other documents, detect their type and language, and OCR scanned images