Skip to content

Commit

Permalink
Update docs to v0.12 (#1233)
Browse files Browse the repository at this point in the history
  • Loading branch information
blikblum authored Apr 5, 2021
1 parent 1aeacf6 commit 362c703
Show file tree
Hide file tree
Showing 34 changed files with 913 additions and 107 deletions.
Binary file modified demo/out.pdf
Binary file not shown.
317 changes: 317 additions & 0 deletions docs/accessibility.html

Large diffs are not rendered by default.

29 changes: 8 additions & 21 deletions docs/annotations.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Annotations in PDFKit</title><link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Source+Code+Pro:400,700|Alegreya:700|Merriweather"><link rel="stylesheet" href="/docs/css/index.css"><link rel="stylesheet" href="/docs/css/github.css"></head><body><nav class="sidebar"><ul><li><a href="/">Home</a></li><li><a href="/docs/../index.html">Documentation</a><ul><li><a href="/docs/getting_started.html">Getting Started </a></li><li><a href="/docs/vector.html">Vector Graphics </a></li><li><a href="/docs/text.html">Text </a></li><li><a href="/docs/images.html">Images </a></li><li><a href="/docs/annotations.html" class="selected">Annotations </a></li></ul></li><li><a href="/docs/guide.pdf">PDF Guide</a></li><li><a href="/demo/out.pdf">Example PDF</a></li><li><a href="/demo/browser.html">Interactive Browser Demo</a></li><li><a href="http://github.com/devongovett/pdfkit">Source Code</a></li></ul></nav><div class="main"><h1 id="annotations_in_pdfkit">Annotations in PDFKit</h1>
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Annotations in PDFKit</title><link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Source+Code+Pro:400,700|Alegreya:700|Merriweather"><link rel="stylesheet" href="/docs/css/index.css"><link rel="stylesheet" href="/docs/css/github.css"></head><body><nav class="sidebar"><ul><li><a href="/">Home</a></li><li><a href="/docs/../index.html">Documentation</a><ul><li><a href="/docs/getting_started.html">Getting Started </a></li><li><a href="/docs/paper_sizes.html">Paper Sizes</a></li><li><a href="/docs/vector.html">Vector Graphics </a></li><li><a href="/docs/text.html">Text </a></li><li><a href="/docs/images.html">Images </a></li><li><a href="/docs/outline.html">Outlines </a></li><li><a class="selected" href="/docs/annotations.html">Annotations </a></li><li><a href="/docs/forms.html">Forms </a></li><li><a href="/docs/destinations.html">Destinations</a></li><li><a href="/docs/attachments.html">Attachments </a></li><li><a href="/docs/accessibility.html">Accessibility</a></li><li><a href="/docs/you_made_it.html">You made it!</a></li></ul></li><li><a href="/docs/guide.pdf">PDF Guide</a></li><li><a href="/demo/out.pdf">Example PDF</a></li><li><a href="/demo/browser.html">Interactive Browser Demo</a></li><li><a href="http://github.com/foliojs/pdfkit">Source Code</a></li></ul></nav><div class="main"><h1 id="annotations_in_pdfkit">Annotations in PDFKit</h1>

<p>Annotations are interactive features of the PDF format, and they make it
possible to include things like links and attached notes, or to highlight,
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:</p>

<ul><li><code>note(x, y, width, height, contents, options)</code></li><li><code>link(x, y, width, height, url, options)</code></li><li><code>highlight(x, y, width, height, options)</code></li><li><code>underline(x, y, width, height, options)</code></li><li><code>strike(x, y, width, height, options)</code></li><li><code>lineAnnotation(x1, y1, x2, y2, options)</code></li><li><code>rectAnnotation(x, y, width, height, options)</code></li><li><code>ellipseAnnotation(x, y, width, height, options)</code></li><li><code>textAnnotation(x, y, width, height, text, options)</code></li></ul>
<ul><li><code>note(x, y, width, height, contents, options)</code></li><li><code>link(x, y, width, height, url, options)</code></li><li><code>goTo(x, y, w, h, name, options)</code></li><li><code>highlight(x, y, width, height, options)</code></li><li><code>underline(x, y, width, height, options)</code></li><li><code>strike(x, y, width, height, options)</code></li><li><code>lineAnnotation(x1, y1, x2, y2, options)</code></li><li><code>rectAnnotation(x, y, width, height, options)</code></li><li><code>ellipseAnnotation(x, y, width, height, options)</code></li><li><code>textAnnotation(x, y, width, height, text, options)</code></li><li><code>fileAnnotation(x, y, width, height, file, options)</code></li></ul>

<p>Many of the annotations have a <code>color</code> option that you can specify. You can
use an array of RGB values, a hex color, or a named CSS color value for that
Expand Down Expand Up @@ -51,11 +51,14 @@
// Create the crossed out text
doc.moveDown()
.strike(20, doc.y, doc.widthOfString(&#39;STRIKE!&#39;), height)
.text(&#39;STRIKE!&#39;);</code></pre>
.text(&#39;STRIKE!&#39;);

// Adding go to as annotation
doc.goTo(20, doc.y, 10, 20, &#39;LINK&#39;, {});</code></pre>

<p>The output of this example looks like this.</p>

<p><img src="img/15.png"/></p>
<p><img src="img/16.png"/></p>

<p>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&#39;t
Expand All @@ -72,23 +75,7 @@

<p>The output is as you&#39;d expect:</p>

<p><img src="img/16.png"/></p>

<h1>You made it!</h1>

<p>That&#39;s all there is to creating PDF documents in PDFKit. It&#39;s really quite
simple to create beautiful multi-page printable documents using Node.js!</p>

<p>This guide was generated from Markdown files using a
PDFKit generation script. The examples are actually run to generate the output shown
inline. The script generates both the website and the PDF guide, and
can be found <a href="http://github.com/devongovett/pdfkit/tree/master/docs/generate.coffee">on Github</a>.
Check it out if you want to see an example of a slightly more complicated renderer using
a parser for Markdown and a syntax highlighter.</p>

<p>If you have any questions about what you&#39;ve learned in this guide, please don&#39;t
hesitate to <a href="http://twitter.com/devongovett">ask the author</a> or post an issue
on <a href="http://github.com/devongovett/pdfkit/issues">Github</a>. Enjoy!</p><nav><a href="/docs/images.html" class="previous">Previous</a></nav></div><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script><script src="/docs/js/scroll.js"></script><script src="/docs/js/highlight.pack.js"></script><script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
<p><img src="img/17.png"/></p><nav><a class="previous" href="/docs/outline.html">Previous</a><a class="next" href="/docs/forms.html">Next</a></nav></div><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script><script src="/docs/js/scroll.js"></script><script src="/docs/js/highlight.pack.js"></script><script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
Expand Down
53 changes: 53 additions & 0 deletions docs/attachments.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Attachments in PDFKit</title><link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Source+Code+Pro:400,700|Alegreya:700|Merriweather"><link rel="stylesheet" href="/docs/css/index.css"><link rel="stylesheet" href="/docs/css/github.css"></head><body><nav class="sidebar"><ul><li><a href="/">Home</a></li><li><a href="/docs/../index.html">Documentation</a><ul><li><a href="/docs/getting_started.html">Getting Started </a></li><li><a href="/docs/paper_sizes.html">Paper Sizes</a></li><li><a href="/docs/vector.html">Vector Graphics </a></li><li><a href="/docs/text.html">Text </a></li><li><a href="/docs/images.html">Images </a></li><li><a href="/docs/outline.html">Outlines </a></li><li><a href="/docs/annotations.html">Annotations </a></li><li><a href="/docs/forms.html">Forms </a></li><li><a href="/docs/destinations.html">Destinations</a></li><li><a class="selected" href="/docs/attachments.html">Attachments </a><ul><li><a href="#embedded_files">Embedded Files</a></li><li><a href="#file_annotations">File Annotations</a></li></ul></li><li><a href="/docs/accessibility.html">Accessibility</a></li><li><a href="/docs/you_made_it.html">You made it!</a></li></ul></li><li><a href="/docs/guide.pdf">PDF Guide</a></li><li><a href="/demo/out.pdf">Example PDF</a></li><li><a href="/demo/browser.html">Interactive Browser Demo</a></li><li><a href="http://github.com/foliojs/pdfkit">Source Code</a></li></ul></nav><div class="main"><h1 id="attachments_in_pdfkit">Attachments in PDFKit</h1>

<h2 id="embedded_files">Embedded Files</h2>

<p>Embedded files make it possible to embed any external file into a PDF.
Adding an embedded file is as simple as calling the <code>file</code> method and specifying a filepath.</p>

<pre><code>doc.file(path.join(__dirname, &#39;example.txt&#39;))</code></pre>

<p>It is also possible to embed data directly as a Buffer, ArrayBuffer or base64 encoded string.
If you are embedding data, it is recommended you also specify a filename like this:</p>

<pre><code>doc.file(Buffer.from(&#39;this will be a text file&#39;), { name: &#39;example.txt&#39; })</code></pre>

<p>When embedding a data URL, the <code>type</code> option will be set to the data URL&#39;s MIME type automatically:</p>

<pre><code>doc.file(&#39;data:text/plain;base64,YmFzZTY0IHN0cmluZw==&#39;, { name: &#39;base64.txt&#39; })</code></pre>

<p>There are a few other options for <code>doc.file</code>:</p>

<ul><li><code>name</code> - specify the embedded file&#39;s name</li><li><code>type</code> - specify the embedded file&#39;s subtype as a <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types">MIME-Type</a></li><li><code>description</code> - add descriptive text for the embedded file</li><li><code>hidden</code> - if true, do not show file in the list of embedded files</li><li><code>creationDate</code> - override the date and time the file was created</li><li><code>modifiedDate</code> - override the date and time the file was last updated</li></ul>

<p>If you are attaching a file from your file system, creationDate and modifiedDate will be set to the source file&#39;s creationDate and modifiedDate.</p>

<p>Setting the <code>hidden</code> option prevents this file from showing up in the pdf viewer&#39;s attachment panel.
While this may not be very useful for embedded files, it is absolutely necessary for file annotations, to prevent them from showing up twice in the attachment panel.</p>

<h2 id="file_annotations">File Annotations</h2>

<p>A file annotation contains a reference to an embedded file that can be placed anywhere in the document.
File annotations show up in your reader&#39;s annotation panel as well as the attachment panel.</p>

<p>In order to add a file annotation, you should first read the chapter on annotations.
Like other annotations, you specify position and size with <code>x</code>, <code>y</code>, <code>width</code> and <code>height</code>, unlike other annotations you must also specify a file object.
The file object may contain the same options as <code>doc.file</code> in the previous section with the addition of the source file or buffered data in <code>src</code>.</p>

<p>Here is an example of adding a file annotation:</p>

<pre><code>const file = {
src: path.join(__dirname, &#39;example.txt&#39;),
name: &#39;example.txt&#39;,
description: &#39;file annotation description&#39;
}
const options = { Name: &#39;Paperclip&#39; }

doc.fileAnnotation(100, 100, 100, 100, file, options)</code></pre>

<p>The annotation&#39;s appearance may be changed by setting the <code>Name</code> option to one of the three predefined icons <code>GraphPush</code>, <code>Paperclip</code> or <code>Push</code> (default value).</p><nav><a class="previous" href="/docs/destinations.html">Previous</a><a class="next" href="/docs/accessibility.html">Next</a></nav></div><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script><script src="/docs/js/scroll.js"></script><script src="/docs/js/highlight.pack.js"></script><script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-48340245-1', 'pdfkit.org');
ga('send', 'pageview');</script></body></html>
33 changes: 33 additions & 0 deletions docs/destinations.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Destinations</title><link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Source+Code+Pro:400,700|Alegreya:700|Merriweather"><link rel="stylesheet" href="/docs/css/index.css"><link rel="stylesheet" href="/docs/css/github.css"></head><body><nav class="sidebar"><ul><li><a href="/">Home</a></li><li><a href="/docs/../index.html">Documentation</a><ul><li><a href="/docs/getting_started.html">Getting Started </a></li><li><a href="/docs/paper_sizes.html">Paper Sizes</a></li><li><a href="/docs/vector.html">Vector Graphics </a></li><li><a href="/docs/text.html">Text </a></li><li><a href="/docs/images.html">Images </a></li><li><a href="/docs/outline.html">Outlines </a></li><li><a href="/docs/annotations.html">Annotations </a></li><li><a href="/docs/forms.html">Forms </a></li><li><a class="selected" href="/docs/destinations.html">Destinations</a></li><li><a href="/docs/attachments.html">Attachments </a></li><li><a href="/docs/accessibility.html">Accessibility</a></li><li><a href="/docs/you_made_it.html">You made it!</a></li></ul></li><li><a href="/docs/guide.pdf">PDF Guide</a></li><li><a href="/demo/out.pdf">Example PDF</a></li><li><a href="/demo/browser.html">Interactive Browser Demo</a></li><li><a href="http://github.com/foliojs/pdfkit">Source Code</a></li></ul></nav><div class="main"><h1 id="destinations">Destinations</h1>

<p>Anchor may specify a destination by <code>addNamedDestination(name, ...args)</code>, which consists of a page, the location of the display window on that page, and the zoom factor to use when displaying that page.</p>

<p>Examples of creating anchor:</p>

<pre><code>// Insert anchor for current page
doc.addNamedDestination(&#39;LINK&#39;);

// Insert anchor for current page with only horizontal magnified to fit where vertical top is 100
doc.addNamedDestination(&#39;LINK&#39;, &#39;FitH&#39;, 100);

// Insert anchor to display a portion of the current page, 1/2 inch in from the top and left and zoomed 50%
doc.addNamedDestination(&#39;LINK&#39;, &#39;XYZ&#39;, 36, 36, 50);

// Insert anchor for this text
doc.text(&#39;End of paragraph&#39;, { destination: &#39;ENDP&#39; });</code></pre>

<p>Examples of go to link to anchor:</p>

<pre><code>// Go to annotation
doc.goTo(10, 10, 100, 20, &#39;LINK&#39;)

// Go to annotation for this text
doc.text(&#39;Another goto&#39;, 20, 0, {
goTo: &#39;ENDP&#39;,
underline: true
});</code></pre><nav><a class="previous" href="/docs/forms.html">Previous</a><a class="next" href="/docs/attachments.html">Next</a></nav></div><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script><script src="/docs/js/scroll.js"></script><script src="/docs/js/highlight.pack.js"></script><script>(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-48340245-1', 'pdfkit.org');
ga('send', 'pageview');</script></body></html>
Loading

0 comments on commit 362c703

Please sign in to comment.