# pdf-tools / PDF Workbench

`pdf-tools` is a self-hostable, browser-only PDF workbench for fast page-level PDF operations. It is built for situations where uploading PDFs to a third-party service is undesirable, but users still need simple, visual tools to split, merge, reorder, rotate, duplicate, delete, extract, and export pages.

Current hosted version: <https://pdftools.add-ideas.de>

Current release: **v0.3.0 — Selection workspace and maintenance release**. See [`CHANGELOG.md`](CHANGELOG.md) for release notes and milestone history.

The app is a static React/Vite single-page application. There is no backend service, no server-side queue, and no server-side document storage. When hosted correctly, the server only delivers HTML, JavaScript, CSS, and static assets; PDF processing happens in the user's browser.

## Purpose

Many everyday PDF tasks are not full document-authoring tasks. They are page-workbench tasks:

- remove pages before sending a document;
- rotate scanned pages;
- split a PDF into single-page files;
- merge another PDF into the current document;
- extract a subset of pages;
- reorder pages visually;
- keep a local working state while experimenting;
- undo and redo page operations before exporting.

`pdf-tools` focuses on this page-level workflow. It is intentionally not a full PDF editor, OCR solution, digital-signature workflow, DMS, or Adobe Acrobat replacement.

## Where the project comes from

The project started as a pragmatic, browser-only PDF helper for quick administrative and document-preparation tasks. The guiding idea is simple: many users need small PDF operations, but sensitive or internal documents should not have to leave the browser just to remove, rotate, split, or rearrange pages.

This makes the project especially useful for self-hosted environments, public-sector settings, universities, small organizations, and internal tools where operational simplicity and document locality matter.

## Distinguishing features

- **Browser-only processing**: PDF files are processed locally in the browser. The hosting server does not receive the selected PDFs.
- **Static self-hosting**: The production build can be served by any static web server or reverse proxy.
- **Visual page workspace**: Users work with page thumbnails, drag-and-drop ordering, selection, page preview, and page-level actions.
- **Named local workspaces**: Workspaces can be saved in the browser with the PDF binary and editing state stored in IndexedDB.
- **Undo/redo command history**: Workspace operations are recorded as commands with label, timestamp, and payload. The history view shows undo and redo states.
- **Progressive thumbnails**: Thumbnails are generated progressively so the UI becomes useful before all pages have finished rendering.
- **Thumbnail cache by page and rotation**: Rotated thumbnails are cached and only changed thumbnails need to be regenerated.
- **Stable page references**: Duplicated pages and reordered pages are tracked as workspace page references rather than only by original page number.
- **Merge choices**: Loading another PDF can replace the current document, append pages, or insert pages at a chosen position.
- **In-app help**: The app includes a Help/Tutorial dialog with keyboard shortcuts and workflow explanations.

## Current features

### File and workspace handling

- Load a local PDF file.
- Save a named workspace in the browser.
- Restore saved workspaces from IndexedDB.
- Reset the active workspace, with a save prompt for unsaved changes.
- Delete saved workspaces after confirmation.
- Store workspace history and redo history.

### Page operations

- Generate page thumbnails in the browser.
- Reorder pages with drag and drop.
- Select individual pages.
- Select page ranges with Shift-click.
- Drag a selected page to move the whole selection.
- Duplicate/copy selected pages into a chosen position.
- Rotate pages clockwise and counter-clockwise.
- Delete one page or all selected pages after confirmation.
- Preview pages in a modal overlay.
- Flip through preview pages with buttons or arrow keys.

### Export tools

- Export the current reordered/rotated/duplicated/deleted workspace as a new PDF.
- Extract selected pages into a new PDF.
- Open selected pages as a new active workspace for continued editing.
- Split the source PDF into single-page PDFs.
- Merge another PDF by replacing, appending, or inserting it into the current workspace.

### Keyboard shortcuts

| Shortcut                   | Action                                              |
| -------------------------- | --------------------------------------------------- |
| `F1` / `?`                 | Open in-app help and tutorial                       |
| `Ctrl`/`⌘` + `A`           | Select all pages                                    |
| `Delete` / `Backspace`     | Delete selected pages after confirmation            |
| `Esc`                      | Clear the current selection or close an open dialog |
| `Ctrl`/`⌘` + `Z`           | Undo                                                |
| `Ctrl`/`⌘` + `Shift` + `Z` | Redo                                                |
| `Ctrl`/`⌘` + `Y`           | Redo                                                |
| `←` / `→` in preview       | Move to previous / next page                        |
| `Esc` in preview           | Close preview                                       |

Keyboard shortcuts are ignored while typing in form fields.

## In-app documentation concept

The app includes a Help/Tutorial dialog reachable from the header via **Help ?**, `F1`, or `?`.

Recommended structure for in-app documentation:

1. **Quick tutorial**: short task-oriented steps from loading a PDF to exporting.
2. **Keyboard shortcuts**: a compact reference for power users.
3. **Concepts**: explain the difference between a PDF file, a workspace, command history, and exported output.
4. **Privacy model**: state clearly that processing is browser-local and workspaces are saved in local browser storage.
5. **Roadmap hints**: link users to the README or project repository for planned features, instead of overloading the app UI.

This keeps the app useful for first-time users without turning the main interface into a manual.

## Administrator notes

### Deployment model

`pdf-tools` is deployed as a static web application:

```text
browser  <-- HTTPS -->  static web server / reverse proxy  -->  built app assets
```

There is no application server to operate. Administrators only need to host the built files from `dist/`.

### Build and test from source

```bash
npm ci
npm run check
```

`npm run check` runs the main project quality gate:

```bash
npm run typecheck
npm run lint
npm run test
npm run build
```

The production build is written to `dist/`.

Useful individual development commands:

```bash
npm run dev           # start the Vite development server
npm run preview       # preview the production build locally
npm run test          # run tests once
npm run test:watch    # run tests in watch mode
npm run typecheck     # run TypeScript without emitting files
npm run lint          # run ESLint
npm run format        # format the project with Prettier
npm run format:check  # verify Prettier formatting
```

### Static hosting

Any static hosting setup should work, for example:

- nginx;
- Apache httpd;
- Caddy;
- Traefik in front of a static file container;
- GitLab Pages or another static publishing target;
- a minimal container serving `dist/`.

A typical nginx location for a single-page app looks like this:

```nginx
location / {
    try_files $uri $uri/ /index.html;
}
```

### Reverse proxy considerations

For production, serve the built app via HTTPS. The reverse proxy only sees requests for static app assets. It should not receive the user's PDF files, because the files are opened through browser APIs and processed locally.

For the Vite development server, `vite.config.ts` can restrict allowed hosts. The current development configuration includes `pdftools.add-ideas.de` as an allowed host for the dev server. This is not required for a normal production static build.

### Content Security Policy

A strict CSP is possible, but it must account for browser-local rendering details. Thumbnails use data URLs, downloads use blob URLs, and pdf.js uses a worker.

A starting point for testing could be:

```http
Content-Security-Policy: default-src 'self'; script-src 'self'; worker-src 'self' blob:; img-src 'self' data: blob:; style-src 'self' 'unsafe-inline'; object-src 'none'; base-uri 'self'; form-action 'none'
```

Adjust this to your hosting environment and test PDF loading, thumbnail rendering, preview, and downloads before enforcing it broadly.

### Storage and persistence

Saved workspaces are stored in the user's browser using IndexedDB. A workspace may include:

- the source PDF binary;
- workspace name and metadata;
- page order and duplicated page references;
- rotations;
- selected pages;
- undo and redo command history.

This has several operational consequences:

- Workspaces are local to the browser profile and device.
- Clearing browser data can delete saved workspaces.
- Server backups do not include user workspaces.
- Different users on different devices do not share workspaces through the server.
- Browser storage quotas apply.

### Privacy and logging

The server should only log asset requests for the app itself. It should not log PDF filenames or contents unless the hosting environment adds custom client-side telemetry or upload logic. Avoid adding analytics that could weaken the project's privacy model.

### Browser support

The app expects modern browser APIs, including:

- File API;
- Blob and object URLs;
- IndexedDB;
- Web Workers;
- Canvas;
- modern JavaScript modules.

Use current versions of Chromium, Firefox, Safari, or Edge.

## Versioning and release baseline

The application version shown in the header is defined in `src/version.ts`. The package version in `package.json` and the displayed app version should be kept in sync for releases.

The current development baseline is:

```text
v0.3.0 — Selection workspace and maintenance release
```

This release preserves the browser-only workspace baseline and adds the first post-refactor feature: opening selected pages as a new active workspace. Workspace state, thumbnail handling, generated download URLs, page-grid components, tests, type-checking, linting, and formatting are separated enough to support additional feature work without turning `App.tsx` back into a monolith.

## Project structure

```text
src/
  App.tsx                         Main application orchestration and UI wiring
  components/
    ActionDialog.tsx              Reusable confirmation/action dialog
    ActionsPanel.tsx              Export, extract, and split actions
    FileLoader.tsx                PDF file loading
    HelpDialog.tsx                In-app tutorial and shortcut reference
    Layout.tsx                    Application shell/header
    PagePreviewModal.tsx          Large page preview with navigation
    ReorderPanel.tsx              Page grid, selection, drag/drop, copy/delete/rotate
    WorkspacePanel.tsx            Workspace save/load/reset and undo/redo history
  pdf/
    pdfService.ts                 pdf-lib operations: load, merge, split, export
    pdfThumbnailService.ts        pdf.js thumbnail rendering
    pdfTypes.ts                   PDF-related types
  workspace/
    workspaceCommands.ts          Command model for undo/redo
    workspaceDb.ts                IndexedDB persistence
    workspaceTypes.ts             Workspace data model
  styles.css                      Global styles
  version.ts                      App version displayed in the header
```

## Roadmap

### Milestone 1: Fast preview and thumbnails

- [x] Remove unused legacy page list view.
- [x] Bound thumbnail generation by width and height.
- [x] Display thumbnails progressively.
- [x] Add preview page flipping.
- [x] Attach preview controls to the modal container.
- [x] Add first keyboard shortcuts.
- [x] Cache thumbnails by page and rotation.
- [x] Regenerate only changed rotated thumbnails.
- [x] Show software version number.

### Milestone 2: Real page workspace

- [x] Introduce stable page references instead of only original page indices.
- [x] Support duplicate selected pages.
- [x] Save and reload the last state from browser storage.
- [x] Support named workspaces.
- [x] Store PDF binaries directly in IndexedDB.
- [x] Reset workspace.
- [x] Add command history as a foundation for undo/redo.
- [x] Add undo/redo.
- [x] Display undo/redo history with redo entries visually separated.
- [x] Extract selection as a new active workspace.
- [ ] Reduce undo/redo storage footprint if large documents make snapshots too heavy.
- [ ] Add grid/list view toggle.

### Milestone 3: Better merge and mobile handling

- [ ] Add a full multi-file merge queue.
- [ ] Support drag-and-drop of PDFs into the page grid at the hovered position.
- [ ] Add custom long-press drag on mobile.
- [ ] Consolidate frequently used actions into a toolbar.

### Milestone 4: Structural PDF editing

- [ ] Metadata editing.
- [ ] Crop pages.
- [ ] Add tools directly in the preview overlay.
- [ ] Read/fill/flatten forms.
- [ ] Read bookmarks, then evaluate bookmark editing.
- [ ] Read annotations, then evaluate annotation writing.

### Milestone 5: Export and power tools

- [ ] Basic text extraction.
- [ ] ZIP export for split results.
- [ ] Optimize/compress MVP.
- [ ] Carefully scoped encrypted PDF handling.

## Non-goals for now

- Server-side PDF processing.
- Collaborative editing.
- User accounts.
- OCR.
- Full content-stream editing.
- Digital signature creation/validation workflows.
- DMS replacement functionality.

## License

GPL-3.0. See `LICENSE`.
Description
No description provided
Readme AGPL-3.0 871 KiB
Languages
TypeScript 94.6%
CSS 4.3%
JavaScript 0.7%
HTML 0.4%