Skip to content
forked from jbaiter/pdiiif

Create PDFs from IIIF manifests, completely client-side (with server-based fallback for unsupported browsers)

License

Notifications You must be signed in to change notification settings

crkn-rcdr/pdiiif

 
 

Repository files navigation

pdiiif logo

Demo

Sample PDF generated with the library

Library API Documentation

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.

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.

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 (via chunked-encoding in the HTTP response on the server, and by making use of the new Native Filesystem API in browsers).

It is also well-suited for embedding in other applications due to its relatively small footprint, 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 and his work on Poc||GTFO for the inspiration!)

Features

  • PDF Page for every single-image Canvas in a Manifest
  • Rendering Canvases with multiple images
  • PDF Table of Contents from IIIF Ranges
  • Cover page with metadata, attribution and licensing information
  • Hidden text layer from ALTO or hOCR OCR
  • Render IIIF layers as PDF "optional content groups" that can be toggled
  • Rendering of IIIF Annotations as PDF annotations
  • Include IIIF Manifest and referenced OCR files as PDF attachments
  • Generate polyglot PDFs that are also ZIP files of all resources

Cookbook Matrix

The IIIF 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)
IIIF Properties (8 of 15 supported)
Structuring Resources (3 of 6 supported)
Image Recipes (6 of 6 supported)
Annotation Recipes (4 of 5 supported)
  • Simple Annotation — Tagging: YES
  • Tagging with an External Resource: NO
  • Annotation with a Non-Rectangular Polygon: YES
  • Simplest Annotation: YES
  • Embedded or referenced Annotations: YES

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

Structure of the repository

  • ./pdiiif-lib: Contains the library source code
  • ./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: Sample web application (using Svelte) to demonstrate using pdiiif in the browser

About

Create PDFs from IIIF manifests, completely client-side (with server-based fallback for unsupported browsers)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 83.1%
  • Svelte 9.7%
  • Handlebars 3.0%
  • HTML 2.1%
  • JavaScript 1.5%
  • Dockerfile 0.6%