Skip to content

Commit

Permalink
add attachments embedding
Browse files Browse the repository at this point in the history
  • Loading branch information
liborm85 committed Apr 1, 2022
1 parent c2465eb commit 1b05c08
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions content/document-definition-object/attachments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
+++
title = "Attachments embedding"
description = ""
weight = 298
alwaysopen = true
+++

pdfmake supports attaching files as annotations as well as embedded files.
Embedded files are added in the "files" dictionary and will show up in supported pdf viewers in their respective attachment panels.
File attachments are annotations which link to a file.
Any attachment or embedded file must provide at least a "src", providing a filename through "name" is highly recommended.
The "src" of any attachment can be provided in dataURL format (like the following attachment, taken from http://www.clipartbest.com/clipart-dT7zx5rT9), but local files are allowed as well.

```js
var dd = {
content: [
'Any attachment or embedded file must provide at least a "src", providing a filename through "name" is highly recommended.',
'The "src" of any attachment can be provided in dataURL format (like the following attachment, taken from http://www.clipartbest.com/clipart-dT7zx5rT9), but local files are allowed as well.',
{
attachment: {
src: 'data:image/png;base64,iVBOR....',
name: 'testImage.png'
}
},
'You can also define an attachment in the "attachments" dictionary and reference it by name.',
{
attachment: 'sampleImage'
},
'And there are three different standard icons for attachments, "GraphPush", "Paperclip", and "Push" (the default value). Set them with the "icon" option.',
{
attachment: 'sampleImage',
icon: 'GraphPush'
},
{
attachment: 'sampleImage',
icon: 'Paperclip'
},
{
attachment: 'sampleImage',
icon: 'Push'
},
'For better customization, add an image and attach a file to it with linkToFile:',
{
image: 'fonts/sampleImage.jpg',
width: 150,
linkToFile: 'sampleImage'
},
"You can add a description, which will show in your pdf viewer's attachments panel and as a tooltip when hovering over the attachment.",
{
attachment: {
src: 'data:image/png;base64,iVBOR....',
name: 'withDescription.png',
description: 'file description'
}
},
'You can also define the "src" of an attachment or embedded file in the "attachments" and "files" dictionary via URL address.',
],
attachments: {
sampleImage: {
src: 'fonts/sampleImage.jpg',
name: 'sampleImage.png'
}
},
files: {
README: {
src: 'https://raw.githubusercontent.com/bpampuch/pdfmake/master/README.md',
name: 'pdfmake README.md'
}
}
};
```

0 comments on commit 1b05c08

Please sign in to comment.