pdf_text_extractor

package module
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 23 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

PDF Text Extractor

Extract text from PDF files in PocketBase file fields and store the result in another field.

PDF Text Extractor settings in the PocketBase Superuser UI

The plugin supports multi-file fields, ignores non-PDF uploads, and merges multiple extracted PDFs with --- separators. Text extraction is powered by go-pdfium running through the wazero WebAssembly backend, so there is no CGO requirement and no separate PDFium binary to install.

Compatibility

Version v0.5.0 follows the same PocketBase line as pb-plugin-base:

  • PocketBase v0.42.x
  • xpb v0.1.0
  • pb-plugin-base v0.3.0
  • Go 1.27.1+

PocketBase now lives at ganigeorgiev.com/pocketbase/pocketbase. Custom Go applications must use the ganigeorgiev.com/pocketbase/* imports alongside xpb v0.1.0.

Installation

Install pb-plugin-base in the same PocketBase build to expose the plugin's settings UI:

go install github.com/pocketbuilds/xpb/cmd/xpb@v0.1.0
xpb build v0.42.3 \
  --with github.com/mjadobson/pb-plugin-base@v0.3.0 \
  --with github.com/mjadobson/pb-plugin-pdf@v0.5.0

Setup

Open Settings → Plugins → PDF Text Extractor and add one or more extraction rules.

Each rule is stored as its own record in the system collection _plugins_pdf, with these fields:

  • collection_name
  • input_field
  • output_field
  • recalculating
  • recalculation_error

The target collection must have:

  • a file field matching input_field
  • a text or editor field matching output_field

Only one rule may target the same collection_name + output_field pair. If legacy configuration contains conflicting rules for the same target, migration stops with an explicit error rather than silently choosing one.

Existing enabled pdf_text_extractor configuration in the legacy shared _plugins collection is imported automatically when _plugins_pdf is empty. Each legacy JSON-array entry becomes its own _plugins_pdf record. After a successful atomic import, the legacy row is left in place but disabled so deleting all new rules later does not cause them to reappear on restart.

The plugin runs after successful record creation, and after updates only when the configured file field value changes. It reloads active rules whenever _plugins_pdf records or collection schemas change.

Plugin Config

collection_name

The PocketBase collection name to watch.

input_field

The file field containing one or more uploads. Only files whose names end in .pdf are extracted.

output_field

The text or editor field where extracted content should be stored.

recalculating

Managed by the plugin UI. Clicking Recalculate sets it to true, starts an asynchronous backfill in batches of 100, and resets it to false when finished. The settings UI listens to PocketBase realtime events and shows a spinner while the backfill is active.

A legacy rule with either recalculate: true or recalculating: true is migrated with recalculating: true, so the requested backfill resumes after migration.

recalculation_error

Managed by the plugin. It is cleared when a recalculation starts. If one or more records fail, the backfill continues with the remaining records and this field stores a concise failure summary. The settings UI reports that partial failure when the realtime completion event arrives.

Behaviour

  • Empty input clears the output field.
  • Only .pdf files are processed.
  • Non-PDF files are ignored.
  • Multiple PDFs are joined with --- on its own line.
  • Extraction failures are logged and skipped so other files can still be processed.
  • Unrelated record updates do not re-parse PDFs; text is refreshed only when the configured file field changes.
  • Rule changes take effect for future create/update events without automatically backfilling existing records.
  • Rules that reference collections that do not exist yet are deferred and can become active after the collection is created.
  • Use Recalculate to backfill existing rows for a rule. A failure on one record is logged and reported without stopping later records in the batch.
  • Invalid pre-existing rules are skipped individually so valid rules can continue to run.

Development

Build a local PocketBase binary using the current checkout and the pinned pb-plugin-base release:

make build-pocketbase-binary
./pocketbase serve

Then open Settings → Plugins → PDF Text Extractor to test the plugin. Rebuild after changing Go code or embedded UI assets.

Run the development checks:

gofmt -w plugin.go plugin_test.go
git diff --check
go mod tidy
git diff --exit-code go.mod go.sum
go vet ./...
go test ./...
go test -race ./...
node --check ui/main.js

License

Licensed under the MIT License.

This plugin uses github.com/klippa-app/go-pdfium with its wazero WebAssembly runtime. Those dependencies are MIT- and Apache-licensed respectively. See LICENSE.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExtractPdfTextConfig

type ExtractPdfTextConfig struct {
	Id             string `json:"id"`
	CollectionName string `json:"collection_name"`
	InputField     string `json:"input_field"`
	OutputField    string `json:"output_field"`
	Recalculating  bool   `json:"recalculating,omitempty"`
}

type Plugin

type Plugin struct {
	// contains filtered or unexported fields
}

func (*Plugin) Author added in v0.5.0

func (p *Plugin) Author() string

func (*Plugin) Description

func (p *Plugin) Description() string

func (*Plugin) Icon added in v0.5.0

func (p *Plugin) Icon() string

func (*Plugin) Init

func (p *Plugin) Init(app core.App) error

func (*Plugin) Label added in v0.5.0

func (p *Plugin) Label() string

func (*Plugin) Name

func (p *Plugin) Name() string

func (*Plugin) Version

func (p *Plugin) Version() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址