Skip to content

Commit

Permalink
Format with npm run prettier -- --write
Browse files Browse the repository at this point in the history
  • Loading branch information
akx committed Jan 27, 2025
1 parent fd43cbd commit c934648
Show file tree
Hide file tree
Showing 111 changed files with 9,166 additions and 11,005 deletions.
14 changes: 7 additions & 7 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# PDFKit Guide

The PDFKit guide can be read a number of ways. The first is online at [pdfkit.org](http://pdfkit.org/).
The PDFKit guide can be read a number of ways. The first is online at [pdfkit.org](http://pdfkit.org/).
You can also read the guide in PDF form, in this directory or [online](http://pdfkit.org/docs/guide.pdf).

Both the website and the PDF guide are generated from the Markdown files
Expand All @@ -9,18 +9,18 @@ You will need to have ImageMagick 7 installed so the `magick` command is
on your `$PATH`.

The examples are actually run when generating the PDF in order to show the results inline.
The `generate.js` file in this directory is actually quite short. It parses the markdown files into a
The `generate.js` file in this directory is actually quite short. It parses the markdown files into a
tree structure using [markdown-js](https://github.com/evilstreak/markdown-js), syntax highlights the code
examples using [codemirror](https://github.com/marijnh/codemirror), compiles and runs the code examples and puts the results
inline, and generates the PDF using PDFKit. You can read the generator script source code to get a feeling for
inline, and generates the PDF using PDFKit. You can read the generator script source code to get a feeling for
how you might do something slightly more complex than the guide itself shows.

The markdown syntax used is pretty much standard, with a couple tweaks.

1. Code example output is references using the image notation, using the alt text as the example number starting from
zero in the current file, and the title as the example output height. E.g. `![x](name "height")`.
1. Code example output is references using the image notation, using the alt text as the example number starting from
zero in the current file, and the title as the example output height. E.g. `![x](name "height")`.

2. Page breaks are added before `h1` and `h2`s, unless there are two in a row. `h3` is treated the same as `h2` but
can be used to avoid this in the case you need multiple `h2`s on the same page.
can be used to avoid this in the case you need multiple `h2`s on the same page.

3. The horizontal rule syntax (`* * *`) denotes an explicit page break
194 changes: 97 additions & 97 deletions docs/accessibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,29 @@ Some other simpler tasks are also required.
This checklist covers everything that is required to create a conformant PDF/UA (PDF for
Universal Accessibility) document (which is an extension of Tagged PDF):

* Pass the option `pdfVersion: '1.5'` (or a higher version) when creating your `PDFDocument`
(depending on the features you use, you may only need 1.4; refer to the PDF reference for
details).
* Pass the option `subset: 'PDF/UA'` when creating your `PDFDocument` (if you wish the PDF to
be identified as PDF/UA-1).
* Pass the option `tagged: true` when creating your `PDFDocument` (technically, this sets the
`Marked` property in the `Markings` dictionary to `true` in the PDF).
* Provide a `Title` in the `info` option, and pass `displayTitle: true` when creating your
`PDFDocument`.
* Specify natural language in the document options and/or logical structure and/or
non-structure marked `Span` content.
* Add logical structure with all significant content included.
* Include accessibility information (such as alternative text, actual text, etc.) in the
logical structure and/or non-structure marked `Span` content.
* Include all spaces which separate words/sentences/etc. in your marked structure content,
even at the ends of lines, paragraphs, etc.. I.e. don't do `doc.text("Hello, world!")` but
instead do `doc.text("Hello, world! ")`.
* Mark all non-structure content as artifacts.
* As well as creating the logical structure, write objects to the PDF in the natural
"reading order".
* Do not convey information solely using visuals (such as colour,
contrast or position on the page).
* No flickering or flashing content.
- Pass the option `pdfVersion: '1.5'` (or a higher version) when creating your `PDFDocument`
(depending on the features you use, you may only need 1.4; refer to the PDF reference for
details).
- Pass the option `subset: 'PDF/UA'` when creating your `PDFDocument` (if you wish the PDF to
be identified as PDF/UA-1).
- Pass the option `tagged: true` when creating your `PDFDocument` (technically, this sets the
`Marked` property in the `Markings` dictionary to `true` in the PDF).
- Provide a `Title` in the `info` option, and pass `displayTitle: true` when creating your
`PDFDocument`.
- Specify natural language in the document options and/or logical structure and/or
non-structure marked `Span` content.
- Add logical structure with all significant content included.
- Include accessibility information (such as alternative text, actual text, etc.) in the
logical structure and/or non-structure marked `Span` content.
- Include all spaces which separate words/sentences/etc. in your marked structure content,
even at the ends of lines, paragraphs, etc.. I.e. don't do `doc.text("Hello, world!")` but
instead do `doc.text("Hello, world! ")`.
- Mark all non-structure content as artifacts.
- As well as creating the logical structure, write objects to the PDF in the natural
"reading order".
- Do not convey information solely using visuals (such as colour,
contrast or position on the page).
- No flickering or flashing content.

## Marked Content

Expand All @@ -57,18 +57,18 @@ Tags to use are listed in a later section.

When marking content, you can provide options (take care to use correct capitalisation):

* `type` - used for artifact content; may be `Pagination` (e.g. headers and footers),
`Layout` (e.g. rules and backgrounds) or `Page` (cut marks etc.)
* `bbox` - bounding box for artifact content: `[left, top, right, bottom]` in default
coordinates
* `attached` - used for `Pagination` artifact content, array of one or more strings:
`Top`, `Bottom`, `Left`, `Right`
* `lang` - used for `Span` content: human language code (e.g. `en-AU`) which overrides default
document language, and any enclosing structure element language
* `alt` - used for `Span` content: alternative text for an image or other visual content
* `expanded` - used for `Span` content: the expanded form of an abbreviation or acronym
* `actual` - used for `Span` content: the actual text the content represents (e.g. if it is
rendered as vector graphics)
- `type` - used for artifact content; may be `Pagination` (e.g. headers and footers),
`Layout` (e.g. rules and backgrounds) or `Page` (cut marks etc.)
- `bbox` - bounding box for artifact content: `[left, top, right, bottom]` in default
coordinates
- `attached` - used for `Pagination` artifact content, array of one or more strings:
`Top`, `Bottom`, `Left`, `Right`
- `lang` - used for `Span` content: human language code (e.g. `en-AU`) which overrides default
document language, and any enclosing structure element language
- `alt` - used for `Span` content: alternative text for an image or other visual content
- `expanded` - used for `Span` content: the expanded form of an abbreviation or acronym
- `actual` - used for `Span` content: the actual text the content represents (e.g. if it is
rendered as vector graphics)

It is advisable not to use `Span` content for specifying alternative text, expanded form, or
actual text, especially if there is a possibility of the content automatically wrapping, which
Expand Down Expand Up @@ -169,10 +169,10 @@ you cannot mix atomic and incremental styles for the same structure element.

For an element to be flushed out, it must:

* be ended,
* have been added to its parent, and
* if it has content defined through closures (see next section), be attached to the document's
structure (through its ancestors)
- be ended,
- have been added to its parent, and
- if it has content defined through closures (see next section), be attached to the document's
structure (through its ancestors)

When you call `doc.end()`, the document's structure is recursively ended, resulting in all
elements being flushed out. If you created elements but forgot to add them to the document's
Expand Down Expand Up @@ -200,8 +200,8 @@ This is equivalent to:
myStruct.add(myStructContent);
myStruct.end();

Note that the content is marked and the closure is executed *if/when the element is attached to
the document's structure*. This means that you can do something like this:
Note that the content is marked and the closure is executed _if/when the element is attached to
the document's structure_. This means that you can do something like this:

const myParagraph = doc.struct('P', [
() => { doc.text("Please see ", { continued: true }); },
Expand Down Expand Up @@ -231,11 +231,11 @@ It's best to add elements to their parents as you go.

When creating a structure element, you can provide options:

* `title` - title of the structure element (e.g. "Chapter 1")
* `lang` - human language code (e.g. `en-AU`) which overrides default document language
* `alt` - alternative text for an image or other visual content
* `expanded` - the expanded form of an abbreviation or acronym
* `actual` - the actual text the content represents (e.g. if it is rendered as vector graphics)
- `title` - title of the structure element (e.g. "Chapter 1")
- `lang` - human language code (e.g. `en-AU`) which overrides default document language
- `alt` - alternative text for an image or other visual content
- `expanded` - the expanded form of an abbreviation or acronym
- `actual` - the actual text the content represents (e.g. if it is rendered as vector graphics)

Example of a structure tree with options specified:

Expand Down Expand Up @@ -308,69 +308,69 @@ ensure you give them with the correct capitalisation.
Non-structure tags:

* `Artifact` - used to mark all content not part of the logical structure
* `ReversedChars` - every string of text has characters in reverse order for technical reasons
(due to how fonts work for right-to-left languages); strings may have spaces at the
beginning or end to separate words, but may not have spaces in the middle
- `Artifact` - used to mark all content not part of the logical structure
- `ReversedChars` - every string of text has characters in reverse order for technical reasons
(due to how fonts work for right-to-left languages); strings may have spaces at the
beginning or end to separate words, but may not have spaces in the middle

"Grouping" elements:

* `Document` - whole document; must be used if there are multiple parts or articles
* `Part` - part of a document
* `Art` - article
* `Sect` - section; may nest
* `Div` - generic division
* `BlockQuote` - block quotation
* `Caption` - describing a figure or table
* `TOC` - table of contents, may be nested, and may be used for lists of figures, tables, etc.
* `TOCI` - table of contents (leaf) item
* `Index` - index (text with accompanying `Reference` content)
* `NonStruct` - non-structural grouping element (element itself not intended to be exported to
other formats like HTML, but 'transparent' to its content which is processed normally)
* `Private` - content only meaningful to the creator (element and its content not intended to
be exported to other formats like HTML)
- `Document` - whole document; must be used if there are multiple parts or articles
- `Part` - part of a document
- `Art` - article
- `Sect` - section; may nest
- `Div` - generic division
- `BlockQuote` - block quotation
- `Caption` - describing a figure or table
- `TOC` - table of contents, may be nested, and may be used for lists of figures, tables, etc.
- `TOCI` - table of contents (leaf) item
- `Index` - index (text with accompanying `Reference` content)
- `NonStruct` - non-structural grouping element (element itself not intended to be exported to
other formats like HTML, but 'transparent' to its content which is processed normally)
- `Private` - content only meaningful to the creator (element and its content not intended to
be exported to other formats like HTML)

"Block" elements:

* `H` - heading (first element in a section, etc.)
* `H1` to `H6` - heading of a particular level intended for use only if nesting sections
is not possible for some reason
* `P` - paragraph
* `L` - list; should include optional `Caption`, and list items
* `LI` - list item; should contain `Lbl` and/or `LBody`
* `Lbl` - label (bullet, number, or "dictionary headword")
* `LBody` - list body (item text, or "dictionary definition"); may have nested lists or other blocks
- `H` - heading (first element in a section, etc.)
- `H1` to `H6` - heading of a particular level intended for use only if nesting sections
is not possible for some reason
- `P` - paragraph
- `L` - list; should include optional `Caption`, and list items
- `LI` - list item; should contain `Lbl` and/or `LBody`
- `Lbl` - label (bullet, number, or "dictionary headword")
- `LBody` - list body (item text, or "dictionary definition"); may have nested lists or other blocks

"Table" elements:

* `Table` - table; should either contain `TR`, or `THead`, `TBody` and/or `TFoot`
* `TR` - table row
* `TH` - table heading cell
* `TD` - table data cell
* `THead` - table header row group
* `TBody` - table body row group; may have more than one per table
* `TFoot` - table footer row group
- `Table` - table; should either contain `TR`, or `THead`, `TBody` and/or `TFoot`
- `TR` - table row
- `TH` - table heading cell
- `TD` - table data cell
- `THead` - table header row group
- `TBody` - table body row group; may have more than one per table
- `TFoot` - table footer row group

"Inline" elements:

* `Span` - generic inline content
* `Quote` - inline quotation
* `Note` - e.g. footnote; may have a `Lbl` (see "block" elements)
* `Reference` - content in a document that refers to other content (e.g. page number in an index)
* `BibEntry` - bibliography entry; may have a `Lbl` (see "block" elements)
* `Code` - code
* `Link` - hyperlink; should contain a link annotation
* `Annot` - annotation (other than a link)
* `Ruby` - Chinese/Japanese pronunciation/explanation
* `RB` - Ruby base text
* `RT` - Ruby annotation text
* `RP` - Ruby punctuation
* `Warichu` - Japanese/Chinese longer description
* `WT` - Warichu text
* `WP` - Warichu punctuation
- `Span` - generic inline content
- `Quote` - inline quotation
- `Note` - e.g. footnote; may have a `Lbl` (see "block" elements)
- `Reference` - content in a document that refers to other content (e.g. page number in an index)
- `BibEntry` - bibliography entry; may have a `Lbl` (see "block" elements)
- `Code` - code
- `Link` - hyperlink; should contain a link annotation
- `Annot` - annotation (other than a link)
- `Ruby` - Chinese/Japanese pronunciation/explanation
- `RB` - Ruby base text
- `RT` - Ruby annotation text
- `RP` - Ruby punctuation
- `Warichu` - Japanese/Chinese longer description
- `WT` - Warichu text
- `WP` - Warichu punctuation

"Illustration" elements (should have `alt` and/or `actualtext` set):

* `Figure` - figure
* `Formula` - formula
* `Form` - form widget
- `Figure` - figure
- `Formula` - formula
- `Form` - form widget
26 changes: 13 additions & 13 deletions docs/annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ underline or strikeout portions of text. Annotations are added using the
various helper methods, and each type of annotation is defined by a rectangle
and some other properties. Here is a list of the available annotation methods:

* `note(x, y, width, height, contents, options)`
* `link(x, y, width, height, url, options)`
* `goTo(x, y, w, h, name, options)`
* `highlight(x, y, width, height, options)`
* `underline(x, y, width, height, options)`
* `strike(x, y, width, height, options)`
* `lineAnnotation(x1, y1, x2, y2, options)`
* `rectAnnotation(x, y, width, height, options)`
* `ellipseAnnotation(x, y, width, height, options)`
* `textAnnotation(x, y, width, height, text, options)`
* `fileAnnotation(x, y, width, height, file, options)`
- `note(x, y, width, height, contents, options)`
- `link(x, y, width, height, url, options)`
- `goTo(x, y, w, h, name, options)`
- `highlight(x, y, width, height, options)`
- `underline(x, y, width, height, options)`
- `strike(x, y, width, height, options)`
- `lineAnnotation(x1, y1, x2, y2, options)`
- `rectAnnotation(x, y, width, height, options)`
- `ellipseAnnotation(x, y, width, height, options)`
- `textAnnotation(x, y, width, height, text, options)`
- `fileAnnotation(x, y, width, height, file, options)`

Many of the annotations have a `color` option that you can specify. You can
use an array of RGB values, a hex color, a named CSS color value, or a named
Expand All @@ -39,7 +39,7 @@ more than one annotation on a single area and one of those annotations is a
link, make sure that the link is the last one you add, otherwise it will be
covered by another annotation and the user won't be able to click it.

* * *
---

Here is an example that uses a few of the annotation types.

Expand Down Expand Up @@ -89,7 +89,7 @@ The output of this example looks like this.
Annotations are currently not the easiest things to add to PDF documents, but
that is the fault of the PDF spec itself. Calculating a rectangle manually isn't
fun, but PDFKit makes it easier for a few common annotations applied to text, including
links, underlines, and strikes. Here's an example showing two of them:
links, underlines, and strikes. Here's an example showing two of them:

doc.fontSize(20)
.fillColor('red')
Expand Down
14 changes: 7 additions & 7 deletions docs/attachments.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ When embedding a data URL, the `type` option will be set to the data URL's MIME

There are a few other options for `doc.file`:

* `name` - specify the embedded file's name
* `type` - specify the embedded file's subtype as a [MIME-Type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types)
* `description` - add descriptive text for the embedded file
* `hidden` - if true, do not show file in the list of embedded files
* `creationDate` - override the date and time the file was created
* `modifiedDate` - override the date and time the file was last updated
* `relationship` - relationship between the PDF document and its attached file. Can be 'Alternative', 'Data', 'Source', 'Supplement' or 'Unspecified'.
- `name` - specify the embedded file's name
- `type` - specify the embedded file's subtype as a [MIME-Type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types)
- `description` - add descriptive text for the embedded file
- `hidden` - if true, do not show file in the list of embedded files
- `creationDate` - override the date and time the file was created
- `modifiedDate` - override the date and time the file was last updated
- `relationship` - relationship between the PDF document and its attached file. Can be 'Alternative', 'Data', 'Source', 'Supplement' or 'Unspecified'.

If you are attaching a file from your file system, creationDate and modifiedDate will be set to the source file's creationDate and modifiedDate.

Expand Down
8 changes: 4 additions & 4 deletions docs/destinations.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ Examples of creating anchor:
// Insert anchor for this text
doc.text('End of paragraph', { destination: 'ENDP' });


Examples of go to link to anchor:

// Go to annotation
doc.goTo(10, 10, 100, 20, 'LINK')

// Go to annotation for this text
doc.text('Another goto', 20, 0, {
goTo: 'ENDP',
underline: true
});

goTo: 'ENDP',
underline: true
});
Loading

0 comments on commit c934648

Please sign in to comment.