@t4h.framework/pdf 0.1.1 → 0.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.
- package/.ai/skills/framework-pdf/SKILL.md +56 -13
- package/CHANGELOG.md +6 -0
- package/README.md +12 -0
- package/dist/activities/RenderPDFActivity.d.ts +13 -6
- package/dist/activities/RenderPDFActivity.d.ts.map +1 -1
- package/dist/activities/RenderPDFActivity.js +8 -2
- package/dist/activities/RenderPDFActivity.js.map +1 -1
- package/dist/pdf.d.ts +1 -0
- package/dist/pdf.d.ts.map +1 -1
- package/dist/pdf.js +1 -0
- package/dist/pdf.js.map +1 -1
- package/dist/tools/encrypt-pdf.d.ts +25 -0
- package/dist/tools/encrypt-pdf.d.ts.map +1 -0
- package/dist/tools/encrypt-pdf.js +42 -0
- package/dist/tools/encrypt-pdf.js.map +1 -0
- package/package.json +2 -1
|
@@ -3,10 +3,11 @@ name: framework-pdf
|
|
|
3
3
|
description: >-
|
|
4
4
|
Guides correct use of @t4h.framework/pdf in T4H Framework workflows: the
|
|
5
5
|
`render()` helper, PDF marker components (Document, Page, View, Text, Link,
|
|
6
|
-
Image, PageNumber), custom fonts, Binary image sources, styling,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
Image, PageNumber), custom fonts, Binary image sources, styling,
|
|
7
|
+
password-protected PDFs via the `encrypt` option, and the FileSystemClaim
|
|
8
|
+
the render activity requires. Use when generating PDFs in workflows,
|
|
9
|
+
building PDF templates with JSX, registering fonts, encrypting PDFs, or
|
|
10
|
+
working in packages/pdf.
|
|
10
11
|
---
|
|
11
12
|
|
|
12
13
|
# @t4h.framework/pdf
|
|
@@ -29,8 +30,11 @@ import {
|
|
|
29
30
|
Image,
|
|
30
31
|
PageNumber,
|
|
31
32
|
RenderPDFActivity,
|
|
33
|
+
ProtectionFlags,
|
|
34
|
+
ProtectionPresets,
|
|
32
35
|
type RenderPDFOptions,
|
|
33
36
|
type RenderPDFInput,
|
|
37
|
+
type EncryptPDFOptions,
|
|
34
38
|
type DocumentProps,
|
|
35
39
|
type PageProps,
|
|
36
40
|
type ViewProps,
|
|
@@ -44,9 +48,11 @@ import {
|
|
|
44
48
|
} from '@t4h.framework/pdf'
|
|
45
49
|
```
|
|
46
50
|
|
|
47
|
-
> Workflows use **`render()
|
|
48
|
-
> `RenderPDFActivity`, but workflow code
|
|
49
|
-
> extends it.
|
|
51
|
+
> Workflows use **`render()`** — for everything, including encryption. The
|
|
52
|
+
> package also exports the underlying `RenderPDFActivity`, but workflow code
|
|
53
|
+
> never imports, instantiates, or extends it. The `encryptPDF` tool in
|
|
54
|
+
> `src/tools/` is internal and not exported — encryption always goes through
|
|
55
|
+
> `render`'s `encrypt` option.
|
|
50
56
|
|
|
51
57
|
## Architecture
|
|
52
58
|
|
|
@@ -60,9 +66,13 @@ import {
|
|
|
60
66
|
2. **`run`** (activity side): fonts are registered, the `DocumentNode` tree is
|
|
61
67
|
converted back into real `@react-pdf/renderer` elements (`Binary` image
|
|
62
68
|
sources become `data:` URIs), rendered to a buffer, and written through
|
|
63
|
-
**`FileSystemClaim`** at `pdf/${activityId}.pdf`.
|
|
69
|
+
**`FileSystemClaim`** at `pdf/${activityId}.pdf`. With the `encrypt`
|
|
70
|
+
option, a password-protected copy is also written at
|
|
71
|
+
`pdf/${activityId}-encrypted.pdf`.
|
|
64
72
|
3. The activity returns the **`Binary`** the claim produced — a reference to
|
|
65
|
-
the stored file, not in-memory bytes. Replay-safe by construction.
|
|
73
|
+
the stored file, not in-memory bytes. Replay-safe by construction. With
|
|
74
|
+
`encrypt`, it returns the `[original, encrypted]` pair instead, and the
|
|
75
|
+
`render` return type narrows automatically based on the options.
|
|
66
76
|
|
|
67
77
|
---
|
|
68
78
|
|
|
@@ -232,6 +242,36 @@ Rules of thumb:
|
|
|
232
242
|
|
|
233
243
|
---
|
|
234
244
|
|
|
245
|
+
## Encryption
|
|
246
|
+
|
|
247
|
+
`render(element, { encrypt })` also persists a password-protected copy and
|
|
248
|
+
resolves with an `[original, encrypted]` tuple — the return type narrows
|
|
249
|
+
automatically:
|
|
250
|
+
|
|
251
|
+
```tsx
|
|
252
|
+
const [original, encrypted] = await render(<Invoice />, {
|
|
253
|
+
encrypt: {
|
|
254
|
+
password: customer.documentNumber,
|
|
255
|
+
protection: ProtectionPresets.ReadOnly,
|
|
256
|
+
},
|
|
257
|
+
})
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
- `password`: a bare string (same password opens and owns the file) or
|
|
261
|
+
`{ user, owner }` for a distinct owner password that bypasses permission
|
|
262
|
+
restrictions.
|
|
263
|
+
- `protection`: a `ProtectionFlags` bitmask granted to whoever opens with the
|
|
264
|
+
user password. Combine flags with `|` (`Print`, `Modify`, `CopyAndExtract`,
|
|
265
|
+
`AnnotateAndFill`, `FillForms`, `ExtractForAccessibility`, `Assemble`,
|
|
266
|
+
`PrintHighResolution`) or use a preset: `ProtectionPresets.ReadOnly`
|
|
267
|
+
(view + print only — invoices, statements) or `ProtectionPresets.All`.
|
|
268
|
+
- Permission flags are honored by PDF viewers, **not enforced
|
|
269
|
+
cryptographically** — the open password is the only real protection.
|
|
270
|
+
- Encryption is **only** available through `render`'s `encrypt` option. Never
|
|
271
|
+
import from `src/tools/encrypt-pdf.js` — it is internal and not exported.
|
|
272
|
+
|
|
273
|
+
---
|
|
274
|
+
|
|
235
275
|
## Testing
|
|
236
276
|
|
|
237
277
|
Test the **workflow** with `TestWorkflowEnvironment` from
|
|
@@ -300,10 +340,13 @@ react-pdf element trees without rendering.
|
|
|
300
340
|
strings); put inheritable text defaults on `Page`.
|
|
301
341
|
8. Use `fixed` + absolute positioning for running headers/footers and
|
|
302
342
|
`PageNumber` for pagination stamps.
|
|
303
|
-
9.
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
343
|
+
9. Password-protect PDFs **only** via `render`'s `encrypt` option — it
|
|
344
|
+
returns `[original, encrypted]`. Never import the internal `encryptPDF`
|
|
345
|
+
tool. Remember permission flags are viewer-honored, not cryptographic.
|
|
346
|
+
10. Test workflows with **`TestWorkflowEnvironment`** + **`mockClaim`**,
|
|
347
|
+
asserting the `%PDF-` magic bytes on the `fs.write` call.
|
|
348
|
+
11. Do not document or import APIs not exported from `@t4h.framework/pdf`
|
|
349
|
+
(the `helpers/` and `tools/` modules are internal).
|
|
307
350
|
|
|
308
351
|
See also: **framework-workflow-testing** for the test harness;
|
|
309
352
|
**framework-fs** for `FileSystemClaim`; **framework-http** for fetching
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @t4h.framework/pdf
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`389e0b7`](https://github.com/tech4humans-brasil/framework/commit/389e0b72b5025dc85f33b371c320a3821314d41e) Thanks [@gusteycamargo](https://github.com/gusteycamargo)! - Adds encryption option
|
|
8
|
+
|
|
3
9
|
## 0.1.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -131,6 +131,18 @@ const pdf = await render(<Doc />, {
|
|
|
131
131
|
|
|
132
132
|
Select variants in styles with `fontFamily`, `fontWeight` (`100–900`), and `fontStyle` (`'normal' | 'italic'`).
|
|
133
133
|
|
|
134
|
+
## Encryption
|
|
135
|
+
|
|
136
|
+
Pass `encrypt` to also persist a password-protected copy — `render` then resolves with an `[original, encrypted]` pair (the return type narrows automatically). `password` is a bare string or `{ user, owner }`; `protection` is a `ProtectionFlags` bitmask (defaults follow the viewer; use `ProtectionPresets.ReadOnly` for view-and-print documents). Permission flags are honored by viewers, not enforced cryptographically.
|
|
137
|
+
|
|
138
|
+
```tsx
|
|
139
|
+
import { ProtectionPresets, render } from '@t4h.framework/pdf'
|
|
140
|
+
|
|
141
|
+
const [original, encrypted] = await render(<Invoice />, {
|
|
142
|
+
encrypt: { password: '12345678900', protection: ProtectionPresets.ReadOnly },
|
|
143
|
+
})
|
|
144
|
+
```
|
|
145
|
+
|
|
134
146
|
## Page numbers
|
|
135
147
|
|
|
136
148
|
`PageNumber` resolves at layout time. The `format` string may reference `{pageNumber}` and `{totalPages}`; combine with `fixed` and absolute positioning for running footers.
|
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
import { Binary, SyncActivity } from '@t4h.framework/core';
|
|
2
2
|
import type { ReactElement } from 'react';
|
|
3
3
|
import { type Fonts } from '../helpers/register-fonts.js';
|
|
4
|
+
import { type EncryptPDFOptions } from '../tools/encrypt-pdf.js';
|
|
4
5
|
import type { DocumentNode } from '../typings/pdf.js';
|
|
5
6
|
export type RenderPDFOptions = {
|
|
6
7
|
fonts?: Fonts;
|
|
8
|
+
encrypt?: EncryptPDFOptions;
|
|
7
9
|
};
|
|
8
10
|
export type RenderPDFInput = {
|
|
9
11
|
document: DocumentNode;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export declare class RenderPDFActivity extends SyncActivity<readonly [element: ReactElement, options?: RenderPDFOptions], RenderPDFInput, Binary, Binary> {
|
|
12
|
+
} & RenderPDFOptions;
|
|
13
|
+
export declare class RenderPDFActivity extends SyncActivity<readonly [element: ReactElement, options?: RenderPDFOptions], RenderPDFInput, Binary | [Binary, Binary], Binary | [Binary, Binary]> {
|
|
13
14
|
private readonly claims;
|
|
14
15
|
toInput(element: ReactElement, options?: RenderPDFOptions): RenderPDFInput;
|
|
15
|
-
run(input: RenderPDFInput): Promise<Binary>;
|
|
16
|
-
toOutput(output: Binary): Binary;
|
|
16
|
+
run(input: RenderPDFInput): Promise<Binary | [Binary, Binary]>;
|
|
17
|
+
toOutput(output: Binary | [Binary, Binary]): Binary | [Binary, Binary];
|
|
17
18
|
}
|
|
18
|
-
export declare function render(element: ReactElement, options
|
|
19
|
+
export declare function render(element: ReactElement, options: RenderPDFOptions & {
|
|
20
|
+
encrypt: EncryptPDFOptions;
|
|
21
|
+
}): Promise<[original: Binary, encrypted: Binary]>;
|
|
22
|
+
export declare function render(element: ReactElement, options?: RenderPDFOptions & {
|
|
23
|
+
encrypt?: undefined;
|
|
24
|
+
}): Promise<Binary>;
|
|
25
|
+
export declare function render(element: ReactElement, options?: RenderPDFOptions): Promise<Binary | [Binary, Binary]>;
|
|
19
26
|
//# sourceMappingURL=RenderPDFActivity.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RenderPDFActivity.d.ts","sourceRoot":"","sources":["../../src/activities/RenderPDFActivity.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAkB,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAE1E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAIzC,OAAO,EAAiB,KAAK,KAAK,EAAE,MAAM,8BAA8B,CAAA;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,CAAC,EAAE,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"RenderPDFActivity.d.ts","sourceRoot":"","sources":["../../src/activities/RenderPDFActivity.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAkB,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAE1E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAIzC,OAAO,EAAiB,KAAK,KAAK,EAAE,MAAM,8BAA8B,CAAA;AACxE,OAAO,EAAc,KAAK,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,OAAO,CAAC,EAAE,iBAAiB,CAAA;CAC5B,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,EAAE,YAAY,CAAA;CACvB,GAAG,gBAAgB,CAAA;AAEpB,qBAAa,iBAAkB,SAAQ,YAAY,CACjD,SAAS,CAAC,OAAO,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,gBAAgB,CAAC,EAC5D,cAAc,EACd,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACzB,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAC1B;IACC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqC;IAErD,OAAO,CACZ,OAAO,EAAE,YAAY,EACrB,OAAO,CAAC,EAAE,gBAAgB,GACzB,cAAc;IAQJ,GAAG,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAmBpE,QAAQ,CACb,MAAM,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAChC,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;CAG7B;AAED,wBAAsB,MAAM,CAC1B,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,gBAAgB,GAAG;IAAE,OAAO,EAAE,iBAAiB,CAAA;CAAE,GACzD,OAAO,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC,CAAA;AACjD,wBAAsB,MAAM,CAC1B,OAAO,EAAE,YAAY,EACrB,OAAO,CAAC,EAAE,gBAAgB,GAAG;IAAE,OAAO,CAAC,EAAE,SAAS,CAAA;CAAE,GACnD,OAAO,CAAC,MAAM,CAAC,CAAA;AAClB,wBAAsB,MAAM,CAC1B,OAAO,EAAE,YAAY,EACrB,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA"}
|
|
@@ -4,12 +4,14 @@ import { FileSystemClaim } from '@t4h.framework/fs';
|
|
|
4
4
|
import { documentToElement } from '../helpers/document-to-element.js';
|
|
5
5
|
import { elementToDocument } from '../helpers/element-to-document.js';
|
|
6
6
|
import { registerFonts } from '../helpers/register-fonts.js';
|
|
7
|
+
import { encryptPDF } from '../tools/encrypt-pdf.js';
|
|
7
8
|
export class RenderPDFActivity extends SyncActivity {
|
|
8
9
|
claims = new Claim({ fs: FileSystemClaim });
|
|
9
10
|
toInput(element, options) {
|
|
10
11
|
return {
|
|
11
12
|
document: elementToDocument(element),
|
|
12
|
-
|
|
13
|
+
fonts: options?.fonts,
|
|
14
|
+
encrypt: options?.encrypt,
|
|
13
15
|
};
|
|
14
16
|
}
|
|
15
17
|
async run(input) {
|
|
@@ -17,7 +19,11 @@ export class RenderPDFActivity extends SyncActivity {
|
|
|
17
19
|
await registerFonts(input.fonts);
|
|
18
20
|
const element = await documentToElement(input.document);
|
|
19
21
|
const pdf = await renderToBuffer(element);
|
|
20
|
-
|
|
22
|
+
const original = await this.claims.fs.write(`pdf/${this.id}.pdf`, pdf);
|
|
23
|
+
if (!input.encrypt)
|
|
24
|
+
return original;
|
|
25
|
+
const encrypted = await this.claims.fs.write(`pdf/${this.id}-encrypted.pdf`, encryptPDF(pdf, input.encrypt));
|
|
26
|
+
return [original, encrypted];
|
|
21
27
|
}
|
|
22
28
|
toOutput(output) {
|
|
23
29
|
return output;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RenderPDFActivity.js","sourceRoot":"","sources":["../../src/activities/RenderPDFActivity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAGnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAA;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAA;AACrE,OAAO,EAAE,aAAa,EAAc,MAAM,8BAA8B,CAAA;
|
|
1
|
+
{"version":3,"file":"RenderPDFActivity.js","sourceRoot":"","sources":["../../src/activities/RenderPDFActivity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAGnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAA;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAA;AACrE,OAAO,EAAE,aAAa,EAAc,MAAM,8BAA8B,CAAA;AACxE,OAAO,EAAE,UAAU,EAA0B,MAAM,yBAAyB,CAAA;AAY5E,MAAM,OAAO,iBAAkB,SAAQ,YAKtC;IACkB,MAAM,GAAG,IAAI,KAAK,CAAC,EAAE,EAAE,EAAE,eAAe,EAAE,CAAC,CAAA;IAErD,OAAO,CACZ,OAAqB,EACrB,OAA0B;QAE1B,OAAO;YACL,QAAQ,EAAE,iBAAiB,CAAC,OAAO,CAAC;YACpC,KAAK,EAAE,OAAO,EAAE,KAAK;YACrB,OAAO,EAAE,OAAO,EAAE,OAAO;SAC1B,CAAA;IACH,CAAC;IAEM,KAAK,CAAC,GAAG,CAAC,KAAqB;QACpC,IAAI,KAAK,CAAC,KAAK;YAAE,MAAM,aAAa,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QAEjD,MAAM,OAAO,GAAG,MAAM,iBAAiB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;QAEvD,MAAM,GAAG,GAAG,MAAM,cAAc,CAAC,OAAO,CAAC,CAAA;QAEzC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,CAAA;QAEtE,IAAI,CAAC,KAAK,CAAC,OAAO;YAAE,OAAO,QAAQ,CAAA;QAEnC,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAC1C,OAAO,IAAI,CAAC,EAAE,gBAAgB,EAC9B,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,OAAO,CAAC,CAC/B,CAAA;QAED,OAAO,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;IAC9B,CAAC;IAEM,QAAQ,CACb,MAAiC;QAEjC,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AAcD,MAAM,CAAC,KAAK,UAAU,MAAM,CAC1B,OAAqB,EACrB,OAA0B;IAE1B,OAAO,MAAM,OAAO,CAAC,UAAU,CAAC,iBAAiB,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;AACtE,CAAC"}
|
package/dist/pdf.d.ts
CHANGED
package/dist/pdf.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pdf.d.ts","sourceRoot":"","sources":["../src/pdf.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAA;AACjD,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA"}
|
|
1
|
+
{"version":3,"file":"pdf.d.ts","sourceRoot":"","sources":["../src/pdf.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAA;AACjD,cAAc,iBAAiB,CAAA;AAC/B,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,KAAK,iBAAiB,GACvB,MAAM,wBAAwB,CAAA;AAC/B,cAAc,kBAAkB,CAAA"}
|
package/dist/pdf.js
CHANGED
package/dist/pdf.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pdf.js","sourceRoot":"","sources":["../src/pdf.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAA;AACjD,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA"}
|
|
1
|
+
{"version":3,"file":"pdf.js","sourceRoot":"","sources":["../src/pdf.ts"],"names":[],"mappings":"AAAA,cAAc,mCAAmC,CAAA;AACjD,cAAc,iBAAiB,CAAA;AAC/B,OAAO,EACL,eAAe,EACf,iBAAiB,GAElB,MAAM,wBAAwB,CAAA;AAC/B,cAAc,kBAAkB,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare enum ProtectionFlags {
|
|
2
|
+
Print = 4,
|
|
3
|
+
Modify = 8,
|
|
4
|
+
CopyAndExtract = 16,
|
|
5
|
+
AnnotateAndFill = 32,
|
|
6
|
+
FillForms = 256,
|
|
7
|
+
ExtractForAccessibility = 512,
|
|
8
|
+
Assemble = 1024,
|
|
9
|
+
PrintHighResolution = 2048
|
|
10
|
+
}
|
|
11
|
+
export declare const ProtectionPresets: {
|
|
12
|
+
readonly ReadOnly: number;
|
|
13
|
+
readonly All: number;
|
|
14
|
+
};
|
|
15
|
+
type Password = string | {
|
|
16
|
+
user: string;
|
|
17
|
+
owner: string;
|
|
18
|
+
};
|
|
19
|
+
export type EncryptPDFOptions = {
|
|
20
|
+
password: Password;
|
|
21
|
+
protection?: ProtectionFlags;
|
|
22
|
+
};
|
|
23
|
+
export declare function encryptPDF(input: Buffer, options: EncryptPDFOptions): Buffer;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=encrypt-pdf.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encrypt-pdf.d.ts","sourceRoot":"","sources":["../../src/tools/encrypt-pdf.ts"],"names":[],"mappings":"AAGA,oBAAY,eAAe;IACzB,KAAK,IAAI;IACT,MAAM,IAAI;IACV,cAAc,KAAK;IACnB,eAAe,KAAK;IACpB,SAAS,MAAM;IACf,uBAAuB,MAAM;IAC7B,QAAQ,OAAO;IACf,mBAAmB,OAAO;CAC3B;AAED,eAAO,MAAM,iBAAiB;;;CAcpB,CAAA;AAEV,KAAK,QAAQ,GACT,MAAM,GACN;IACE,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAEL,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,QAAQ,CAAA;IAClB,UAAU,CAAC,EAAE,eAAe,CAAA;CAC7B,CAAA;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,MAAM,CAmB5E"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/* eslint-disable cspell/spellchecker */
|
|
2
|
+
import muhammara from 'muhammara';
|
|
3
|
+
export var ProtectionFlags;
|
|
4
|
+
(function (ProtectionFlags) {
|
|
5
|
+
ProtectionFlags[ProtectionFlags["Print"] = 4] = "Print";
|
|
6
|
+
ProtectionFlags[ProtectionFlags["Modify"] = 8] = "Modify";
|
|
7
|
+
ProtectionFlags[ProtectionFlags["CopyAndExtract"] = 16] = "CopyAndExtract";
|
|
8
|
+
ProtectionFlags[ProtectionFlags["AnnotateAndFill"] = 32] = "AnnotateAndFill";
|
|
9
|
+
ProtectionFlags[ProtectionFlags["FillForms"] = 256] = "FillForms";
|
|
10
|
+
ProtectionFlags[ProtectionFlags["ExtractForAccessibility"] = 512] = "ExtractForAccessibility";
|
|
11
|
+
ProtectionFlags[ProtectionFlags["Assemble"] = 1024] = "Assemble";
|
|
12
|
+
ProtectionFlags[ProtectionFlags["PrintHighResolution"] = 2048] = "PrintHighResolution";
|
|
13
|
+
})(ProtectionFlags || (ProtectionFlags = {}));
|
|
14
|
+
export const ProtectionPresets = {
|
|
15
|
+
ReadOnly: ProtectionFlags.Print |
|
|
16
|
+
ProtectionFlags.PrintHighResolution |
|
|
17
|
+
ProtectionFlags.ExtractForAccessibility,
|
|
18
|
+
All: ProtectionFlags.Print |
|
|
19
|
+
ProtectionFlags.Modify |
|
|
20
|
+
ProtectionFlags.CopyAndExtract |
|
|
21
|
+
ProtectionFlags.AnnotateAndFill |
|
|
22
|
+
ProtectionFlags.FillForms |
|
|
23
|
+
ProtectionFlags.ExtractForAccessibility |
|
|
24
|
+
ProtectionFlags.Assemble |
|
|
25
|
+
ProtectionFlags.PrintHighResolution,
|
|
26
|
+
};
|
|
27
|
+
export function encryptPDF(input, options) {
|
|
28
|
+
const output = new muhammara.PDFWStreamForBuffer();
|
|
29
|
+
const pdfPassword = {};
|
|
30
|
+
if (typeof options.password === 'string')
|
|
31
|
+
pdfPassword.userPassword = options.password;
|
|
32
|
+
if (typeof options.password === 'object') {
|
|
33
|
+
pdfPassword.userPassword = options.password.user;
|
|
34
|
+
pdfPassword.ownerPassword = options.password.owner;
|
|
35
|
+
}
|
|
36
|
+
muhammara.recrypt(new muhammara.PDFRStreamForBuffer(input), output, {
|
|
37
|
+
...pdfPassword,
|
|
38
|
+
userProtectionFlag: options.protection,
|
|
39
|
+
});
|
|
40
|
+
return output.buffer;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=encrypt-pdf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encrypt-pdf.js","sourceRoot":"","sources":["../../src/tools/encrypt-pdf.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,OAAO,SAAS,MAAM,WAAW,CAAA;AAEjC,MAAM,CAAN,IAAY,eASX;AATD,WAAY,eAAe;IACzB,uDAAS,CAAA;IACT,yDAAU,CAAA;IACV,0EAAmB,CAAA;IACnB,4EAAoB,CAAA;IACpB,iEAAe,CAAA;IACf,6FAA6B,CAAA;IAC7B,gEAAe,CAAA;IACf,sFAA0B,CAAA;AAC5B,CAAC,EATW,eAAe,KAAf,eAAe,QAS1B;AAED,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,QAAQ,EACN,eAAe,CAAC,KAAK;QACrB,eAAe,CAAC,mBAAmB;QACnC,eAAe,CAAC,uBAAuB;IACzC,GAAG,EACD,eAAe,CAAC,KAAK;QACrB,eAAe,CAAC,MAAM;QACtB,eAAe,CAAC,cAAc;QAC9B,eAAe,CAAC,eAAe;QAC/B,eAAe,CAAC,SAAS;QACzB,eAAe,CAAC,uBAAuB;QACvC,eAAe,CAAC,QAAQ;QACxB,eAAe,CAAC,mBAAmB;CAC7B,CAAA;AAcV,MAAM,UAAU,UAAU,CAAC,KAAa,EAAE,OAA0B;IAClE,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,mBAAmB,EAAE,CAAA;IAElD,MAAM,WAAW,GAA2B,EAAE,CAAA;IAE9C,IAAI,OAAO,OAAO,CAAC,QAAQ,KAAK,QAAQ;QACtC,WAAW,CAAC,YAAY,GAAG,OAAO,CAAC,QAAQ,CAAA;IAE7C,IAAI,OAAO,OAAO,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;QACzC,WAAW,CAAC,YAAY,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAA;QAChD,WAAW,CAAC,aAAa,GAAG,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAA;IACpD,CAAC;IAED,SAAS,CAAC,OAAO,CAAC,IAAI,SAAS,CAAC,mBAAmB,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE;QAClE,GAAG,WAAW;QACd,kBAAkB,EAAE,OAAO,CAAC,UAAU;KACvC,CAAC,CAAA;IAEF,OAAO,MAAM,CAAC,MAAM,CAAA;AACtB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@t4h.framework/pdf",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Declarative PDF rendering module for the T4H Framework",
|
|
5
5
|
"homepage": "https://github.com/tech4humans-brasil/framework/tree/main/packages/pdf",
|
|
6
6
|
"bugs": "https://github.com/tech4humans-brasil/framework/issues",
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@react-pdf/renderer": "^4.5.1",
|
|
51
|
+
"muhammara": "^6.0.5",
|
|
51
52
|
"react": "^19.2.8"
|
|
52
53
|
}
|
|
53
54
|
}
|