Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jbaiter/pdiiif
Create PDFs from IIIF manifests, completely client-side (with server-based fallback for unsupported browsers)
https://github.com/jbaiter/pdiiif
iiif ocr pdf-generation
Last synced: about 1 month ago
JSON representation
Create PDFs from IIIF manifests, completely client-side (with server-based fallback for unsupported browsers)
- Host: GitHub
- URL: https://github.com/jbaiter/pdiiif
- Owner: jbaiter
- License: mit
- Created: 2020-09-14T06:51:32.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-07-30T21:34:17.000Z (5 months ago)
- Last Synced: 2024-10-01T18:16:40.766Z (3 months ago)
- Topics: iiif, ocr, pdf-generation
- Language: TypeScript
- Homepage:
- Size: 2.35 MB
- Stars: 28
- Watchers: 5
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE
Awesome Lists containing this project
- awesome-iiif - pdiiif - a JavaScript library to create PDFs from IIIF manifests, completely client-side (with server-based fallback for unsupported browsers). (Presentation Manifest Tools / Image viewers (Image API only))
README
[![pdiiif logo](pdiiif-web/assets/logo.svg)](https://pdiiif.jbaiter.de)
[**Demo**](https://pdiiif.jbaiter.de)
[**Sample PDF generated with the library**](https://pdiiif.jbaiter.de/wunder.pdf)
[**Library API Documentation**](https://jbaiter.github.io/pdiiif)
**pdiiif** is a JavaScript library to **create PDFs from IIIF Manifests.**
For the most part, it runs both in browsers and as a Node.js server-side
application. When generating a PDF in the browser, almost all communication happens
directly between the user's browser and the IIIF APIs referenced from the Manifest.
The only exception is for generating the cover page, which by default needs to be
generated on the server. (see [this section](#cover-page-endpoints) for more details)It comes with a small **sample web application** that demonstrates
how to use the library in the browser, you can check out a public instance
of it at https://pdiiif.jbaiter.de, the source code is located in the
[`pdiiif-web` subdirectory](https://github.com/jbaiter/pdiiif/tree/main/pdiiif-web).A main goal of the library is to be as _memory-efficient_ as possible, by
never holding more than a few pages in memory and streaming directly to
the user's disk (precise method depends on the environment).It is also well-suited for embedding in other applications due to
its relatively small footprint, for example, the example web application comes
in at **~120KiB gzipped** with all dependencies.In addition to the images on the IIIF Canvases referenced in the manifest,
the library can create a **hidden text layer** from OCR associated with
each canvas (ALTO or hOCR referenced from a canvas' `seeAlso` property).In order to not sever the connection between the PDF and the original IIIF
resources on the Web, every PDF generated by `pdiiif` includes the IIIF Manifest
as a PDF attachment, as well as every OCR file referenced in `seeAlso`.
Additionally, `pdiiif` can generate the PDFs in a way that also makes them
valid ZIP files that contain the manifest and all of the images and OCR files,
with almost no storage overhead. (thanks to [Ange Albertini](https://github.com/corkami)
and his work on [Poc||GTFO](https://pocorgtfo.hacke.rs/) for the inspiration!)## Features
- [x] PDF Page for every single-image Canvas in a Manifest
- [x] Rendering Canvases with multiple images
- [x] PDF Table of Contents from IIIF Ranges
- [x] Cover page with metadata, attribution and licensing information
- [x] Hidden text layer from ALTO or hOCR OCR
- [x] Render IIIF layers as PDF "optional content groups" that can be toggled
- [x] Rendering of IIIF Annotations as PDF annotations
- [x] Include IIIF Manifest and referenced OCR files as PDF attachments
- [x] Generate polyglot PDFs that are also ZIP files of all resources## Quickstart
Besides using the public instance at https://pdiiif.jbaiter.de, you can also run the app yourself.
The easiest way to do this is with Docker:```
$ docker build . -t pdiiif
# SYS_ADMIN capabilities are required (for Puppeteer's headless Chrome instance to generate cover page PDFs)
$ docker run -p 8080:8080 --cap-add=SYS_ADMIN --name pdiiif pdiiif
```## Cookbook Matrix
The [IIIF Cookbook](https://iiif.io/api/cookbook/) has a matrix of "recipes" with viewer support, here's an overview
of the recipe support in pdiiif:Basic Recipes (4 of 6 supported)
- [x] [Simplest Manifest - Single Image File](https://iiif.io/api/cookbook/recipe/0001-mvm-image/): Partial, only for JPEG and PNG images.
- [ ] [Simplest Manifest - Audio](https://iiif.io/api/cookbook/recipe/0002-mvm-audio/): NO, PDF has support for audio, but support in pdiiif unlikely, unless there is substantial demand for it
- [ ] [Simplest Manifest - Video](https://iiif.io/api/cookbook/recipe/0003-mvm-video/): NO, PDF has support for video, but support in pdiiif unlikely, unless there is substantial demand for it
- [x] [Support Deep Viewing with Basic Use of a IIIF Image Service](https://iiif.io/api/cookbook/recipe/0005-image-service/): YES, Deep Viewing isn't useful in PDF, but IIIF Image Services are fully supported
- [x] [Internationalization and Multi-language Values (label, summary, metadata, requiredStatement)](https://iiif.io/api/cookbook/recipe/0006-text-language/): YES
- [x] [Simple Manifest - Book](https://iiif.io/api/cookbook/recipe/0009-book-1/): YESIIIF Properties (8 of 15 supported)
- [x] [Embedding HTML in descriptive properties (label, summary, metadata, requiredStatement)](https://iiif.io/api/cookbook/recipe/0007-string-formats/): Partially, only for server-generated cover page
- [x] [Rights statement (rights, requiredStatement)](https://iiif.io/api/cookbook/recipe/0008-rights/): YES
- [x] [Viewing direction and Its Effect on Navigation (viewingDirection)](https://iiif.io/api/cookbook/recipe/0010-book-2-viewing-direction/): Partially, `right-to-left` and `left-to-right` only, viewer support very spotty
- [ ] [Book 'behavior' Variations (continuous, individuals) (behaviorimage)](https://iiif.io/api/cookbook/recipe/0011-book-3-behavior/): NO, general support unlikely since paging preference is global in PDF, but if behavior is global for the manifest, it should be doable
- [ ] [Load a Preview Image Before the Main Content (placeholderCanvas)](https://iiif.io/api/cookbook/recipe/0013-placeholderCanvas/): NO, not applicable
- [ ] [Audio Presentation with Accompanying Image (accompanyingCanvas)](https://iiif.io/api/cookbook/recipe/0014-accompanyingcanvas/): NO, no support for audio
- [ ] [Begin playback at a specific point - Time-based media (start)](https://iiif.io/api/cookbook/recipe/0015-start/): NO, no support for time-based media
- [x] [Metadata on any Resource (metadata)](https://iiif.io/api/cookbook/recipe/0029-metadata-anywhere/): Partial, only Manifest metadata
- [ ] [Providing Alternative Representations (rendering)](https://iiif.io/api/cookbook/recipe/0046-rendering/): NO, utility in PDF questionable
- [ ] [Linking to Structured Metadata (seeAlso)](https://iiif.io/api/cookbook/recipe/0053-seeAlso/): NO, could be placed on the cover page
- [x] [Image Thumbnail for Manifest (thumbnail)](https://iiif.io/api/cookbook/recipe/0117-add-image-thumbnail/): YES
- [x] [Displaying Multiple Values with Language Maps (label, summary, metadata, requiredStatement)](https://iiif.io/api/cookbook/recipe/0118_multivalue/): YES
- [x] [Load Manifest Beginning with a Specific Canvas (start)](https://iiif.io/api/cookbook/recipe/0202-start-canvas/): NO, but support possible
- [ ] [Navigation by Chronology (navDate)](https://iiif.io/api/cookbook/recipe/0230-navdate/): NO
- [x] [Acknowledge Content Contributors (provider)](https://iiif.io/api/cookbook/recipe/0234-provider/): YESStructuring Resources (3 of 6 supported)
- [x] [Table of Contents for Book Chapters (structures)](https://iiif.io/api/cookbook/recipe/0024-book-4-toc/): YES
- [ ] [Table of Contents for A/V Content](https://iiif.io/api/cookbook/recipe/0026-toc-opera/): NO
- [ ] [Multi-volume Work with Individually-bound Volumes](https://iiif.io/api/cookbook/recipe/0030-multi-volume/): NO
- [x] [Multiple Choice of Images in a Single View (Canvas)](https://iiif.io/api/cookbook/recipe/0033-choice/): YES
- [ ] [Foldouts, Flaps, and Maps (behavior)](https://iiif.io/api/cookbook/recipe/0035-foldouts/): NO, support unlikely due to global paging preference in PDF
- [x] [Composition from Multiple Images](https://iiif.io/api/cookbook/recipe/0036-composition-from-multiple-images/): Partial, as long as all images have a JPEG representationImage Recipes (6 of 6 supported)
- [x] [Simplest Manifest - Single Image File](https://iiif.io/api/cookbook/recipe/0001-mvm-image/): Partial, only for JPEG and PNG images
- [x] [Image and Canvas with Differing Dimensions](https://iiif.io/api/cookbook/recipe/0004-canvas-size/): YES
- [x] [Support Deep Viewing with Basic Use of a IIIF Image Service](https://iiif.io/api/cookbook/recipe/0005-image-service/): YES, Deep Viewing isn't useful in PDF, but IIIF Image Services are fully supported
- [x] [Simple Manifest - Book](https://iiif.io/api/cookbook/recipe/0009-book-1/): YES
- [x] [Viewing direction and Its Effect on Navigation (viewingDirection)](https://iiif.io/api/cookbook/recipe/0010-book-2-viewing-direction/): Partially, `right-to-left` and `left-to-right` only, viewer support very spotty
- [x] [Load Manifest Beginning with a Specific Canvas (start)](https://iiif.io/api/cookbook/recipe/0202-start-canvas/): YESAnnotation Recipes (4 of 5 supported)
- [x] Simple Annotation — Tagging: YES
- [ ] Tagging with an External Resource: NO
- [x] Annotation with a Non-Rectangular Polygon: YES
- [x] Simplest Annotation: YES
- [x] Embedded or referenced Annotations: YES## Structure of the repository
- [`./pdiiif-lib`](https://github.com/jbaiter/pdiiif/tree/main/pdiiif-lib): Contains the library source code
- [`./pdiiif-api`](https://github.com/jbaiter/pdiiif/tree/main/pdiiif-api): Small node.js server application that
is responsible for generating the cover pages and that can be used as a fallback for browsers that don't support
the Native Filesystem API or service workers.
- [`./pdiiif-web`](https://github.com/jbaiter/pdiiif/tree/main/pdiiif-web): Sample web application (using Svelte)
to demonstrate using pdiiif in the browser## Cover Page Endpoints
pdiiif tries to includes a cover page with a thumbnail, descriptive metadata and rights and attribution information.
Since typesetting these pages is beyond the scope of what our bespoke PDF generator can provide (most notably, TTF/OTF
font retrieval for arbitrary languages/scripts and font subsetting), this cover page currently needs to be generated
elsewhere. By default, the library is using a public endpoint at https://pdiiif.jbaiter.de/api/coverpage, which generates
a PDF with the default template. The endpoint can be changed with the `coverPageEndpoint` configuration parameter in the
options passed to the `convertManifest` function.If you want to customize the template that is being used, you can either host the API provided in this repository yourself
(see [Quickstart](quickstart)) and override the template by mounting your own custom [Handlebars](https://handlebarsjs.com/)
template into the image at `/opt/pdiiif/pdiiif-api/dist/asses/coverpage.hbs`. For a list of available helpers that you can
use, refer to [`handlebars-helpers`](https://github.com/helpers/handlebars-helpers#helpers). Also available are these two
custom helpers:
- `qrcode`, takes a value and an optional `{ width, height, padding, color, background, ecl }` options object and returns
the value encoded as a SVG QR code image
- `sanitize-html`, takes an arbitrary HTML string and sanitizes it according to the [IIIF HTML rules](https://iiif.io/api/presentation/3.0/#45-html-markup-in-property-values)If you want to provide your own implementation, make sure that your HTTP endpoint generates a valid PDF and accepts a JSON
POST body with the following shape (i.e. does not throw an error when encountering any of these fields):```typescript
{
title: string;
manifestUrl: string;
thumbnail?: {
url: string;
iiifImageService?: string;
};
provider?: {
label: string;
homepage?: string;
logo?: string;
};
requiredStatement?: {
label: string;
value: string;
};
rights?: {
text: string;
url?: string;
logo?: string;
};
// [key, value] pairs, with value either single- or multi-valued
metadata?: Array<[string, string | Array]>;
pdiiifVersion: string;
}
```