@embedpdf/plugin-attachment 3.0.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +61 -0
  2. package/package.json +9 -9
package/README.md ADDED
@@ -0,0 +1,61 @@
1
+ <!-- Generated from docs/content/headless/documents/attachments.mdx by docs/content/scripts/readmes.mjs. Edit there, then run `pnpm readme:sync`. -->
2
+
3
+ # @embedpdf/plugin-attachment
4
+
5
+ Attachments for EmbedPDF: lists the files a PDF carries, and saves, adds and removes them.
6
+
7
+ This plugin comes with each EmbedPDF framework package. Import it from the one you use:
8
+
9
+ | Framework | Import from | Docs |
10
+ | :-------- | :---------- | :--- |
11
+ | React | `@embedpdf/react/attachment` | [Attachments](https://www.embedpdf.com/docs/headless/react/documents/attachments) |
12
+ | Vue | `@embedpdf/vue/attachment` | [Attachments](https://www.embedpdf.com/docs/headless/vue/documents/attachments) |
13
+ | Svelte | `@embedpdf/svelte/attachment` | [Attachments](https://www.embedpdf.com/docs/headless/svelte/documents/attachments) |
14
+ | Angular | `@embedpdf/angular/attachment` | [Attachments](https://www.embedpdf.com/docs/headless/angular/documents/attachments) |
15
+
16
+ ## In React
17
+
18
+ A PDF can carry other files: a spreadsheet with the numbers behind a report, the original of a
19
+ scanned contract. They sit in two places: the document's own attachments, and file attachment
20
+ annotations, a file pinned to a spot on a page. Register `attachmentPlugin()` to list both as one
21
+ list:
22
+
23
+ **`attachment-list.tsx`**
24
+
25
+ ```tsx
26
+ import { displayNameOf, useAttachment, useAttachmentState } from '@embedpdf/react/attachment';
27
+ import type { AttachedFile } from '@embedpdf/react/attachment';
28
+ import { saveFile } from '@embedpdf/react/runtime';
29
+
30
+ export function AttachmentList() {
31
+ const attachment = useAttachment();
32
+ const { files, canDownload } = useAttachmentState();
33
+
34
+ const save = async (file: AttachedFile) => {
35
+ const { bytes, name, mimeType } = await attachment.download(file);
36
+ saveFile(bytes, name, mimeType ?? undefined);
37
+ };
38
+
39
+ return (
40
+ <ul>
41
+ {files.map((file) => (
42
+ <li key={file.id}>
43
+ <bdi>{displayNameOf(file)}</bdi>
44
+ <button disabled={!canDownload} onClick={() => save(file)}>
45
+ Save
46
+ </button>
47
+ </li>
48
+ ))}
49
+ </ul>
50
+ );
51
+ }
52
+ ```
53
+
54
+ What `useAttachmentState()` gives you updates by itself: after your own changes, and on a shared
55
+ document, after someone else's. Nothing is read when a document opens: the attachments load the
56
+ first time something asks for them. The files on the pages come from the
57
+ [annotation plugin](https://www.embedpdf.com/docs/headless/react/annotations), when you've registered it.
58
+
59
+ ## License
60
+
61
+ Apache-2.0
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@embedpdf/plugin-attachment",
3
- "version": "3.0.0",
3
+ "version": "3.2.0",
4
4
  "private": false,
5
- "description": "Document-scoped attachments: the files a document carries, in its attachments and in file attachment annotations, as one list with this session's pending adds and removes shown; adding and removing them as undoable changes, downloading them, and going to a page's file.",
5
+ "description": "Attachments for EmbedPDF: lists the files a PDF carries, and saves, adds and removes them.",
6
6
  "type": "module",
7
7
  "main": "./dist/index.js",
8
8
  "module": "./dist/index.js",
@@ -22,18 +22,18 @@
22
22
  "dist"
23
23
  ],
24
24
  "dependencies": {
25
- "@embedpdf/engine-core": "3.0.0",
26
- "@embedpdf/plugin-annotation": "3.0.0",
27
- "@embedpdf/plugin-stage": "3.0.0",
28
- "@embedpdf/core": "3.0.0"
25
+ "@embedpdf/core": "3.2.0",
26
+ "@embedpdf/plugin-annotation": "3.2.0",
27
+ "@embedpdf/engine-core": "3.2.0",
28
+ "@embedpdf/plugin-stage": "3.2.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "typescript": "^5.0.0",
32
32
  "vitest": "^2.1.9",
33
+ "@embedpdf/engine": "3.2.0",
33
34
  "@embedpdf/tooling-build": "0.0.0",
34
- "@embedpdf/plugin-history": "3.0.0",
35
- "@embedpdf/engine": "3.0.0",
36
- "@embedpdf/plugin-interaction": "3.0.0"
35
+ "@embedpdf/plugin-history": "3.2.0",
36
+ "@embedpdf/plugin-interaction": "3.2.0"
37
37
  },
38
38
  "license": "Apache-2.0",
39
39
  "sideEffects": false,