-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
913 additions
and
107 deletions.
There are no files selected for viewing
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, 'example.txt'))</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('this will be a text file'), { name: 'example.txt' })</code></pre> | ||
|
||
<p>When embedding a data URL, the <code>type</code> option will be set to the data URL's MIME type automatically:</p> | ||
|
||
<pre><code>doc.file('data:text/plain;base64,YmFzZTY0IHN0cmluZw==', { name: 'base64.txt' })</code></pre> | ||
|
||
<p>There are a few other options for <code>doc.file</code>:</p> | ||
|
||
<ul><li><code>name</code> - specify the embedded file's name</li><li><code>type</code> - specify the embedded file'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's creationDate and modifiedDate.</p> | ||
|
||
<p>Setting the <code>hidden</code> option prevents this file from showing up in the pdf viewer'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'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, 'example.txt'), | ||
name: 'example.txt', | ||
description: 'file annotation description' | ||
} | ||
const options = { Name: 'Paperclip' } | ||
|
||
doc.fileAnnotation(100, 100, 100, 100, file, options)</code></pre> | ||
|
||
<p>The annotation'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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('LINK'); | ||
|
||
// Insert anchor for current page with only horizontal magnified to fit where vertical top is 100 | ||
doc.addNamedDestination('LINK', 'FitH', 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('LINK', 'XYZ', 36, 36, 50); | ||
|
||
// Insert anchor for this text | ||
doc.text('End of paragraph', { destination: 'ENDP' });</code></pre> | ||
|
||
<p>Examples of go to link to anchor:</p> | ||
|
||
<pre><code>// 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 | ||
});</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> |
Oops, something went wrong.