@broadpaper/pdf 0.2.0 → 0.3.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/README.md +55 -0
- package/dist/{chunk-PFCVDSUU.js → chunk-AAE2MQRQ.js} +19 -6
- package/dist/{chunk-PFCVDSUU.js.map → chunk-AAE2MQRQ.js.map} +1 -1
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +12 -2
- package/dist/index.js +1 -1
- package/dist/runtime.global.js +4 -4
- package/package.json +25 -5
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# @broadpaper/pdf
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@broadpaper/pdf)
|
|
4
|
+
[](https://www.broadpaper.com/legal/terms/)
|
|
5
|
+
[](https://www.broadpaper.com/docs/guide/licensing/)
|
|
6
|
+
|
|
7
|
+
Chromium-backed PDF generation for BroadPaper, via Playwright. The fidelity reference.
|
|
8
|
+
|
|
9
|
+
Part of [**BroadPaper**](https://www.broadpaper.com/developers/) — an embeddable visual report designer and PDF renderer.
|
|
10
|
+
Your users design the report in your application; BroadPaper owns the layout, the branding,
|
|
11
|
+
the pagination and the output.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @broadpaper/pdf
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Renders through a real browser. This is the backend to reach for when you need Chromium's
|
|
20
|
+
exact typesetting, or when you are comparing output against what a browser would print;
|
|
21
|
+
[`@broadpaper/forme`](https://www.npmjs.com/package/@broadpaper/forme) is the one to deploy,
|
|
22
|
+
because it needs no browser on the server.
|
|
23
|
+
|
|
24
|
+
Playwright is a peer dependency, so installing this package does not drag a browser download
|
|
25
|
+
into an application that only wanted the designer.
|
|
26
|
+
|
|
27
|
+
## Licensing
|
|
28
|
+
|
|
29
|
+
BroadPaper is **free to evaluate, with no trial clock and nothing behind a feature gate**.
|
|
30
|
+
Install it, use every feature and evaluate it against your real data for as long as you like.
|
|
31
|
+
Production use needs a licence.
|
|
32
|
+
|
|
33
|
+
In the software, the only difference without a licence is that generated PDFs carry an
|
|
34
|
+
evaluation mark, and a licence removes it. Contractually, the licence is also what permits
|
|
35
|
+
production use. No seats, no activation, no machine binding, no telemetry, and no call home at
|
|
36
|
+
any point.
|
|
37
|
+
|
|
38
|
+
- [How licensing works](https://www.broadpaper.com/docs/guide/licensing/)
|
|
39
|
+
- [Pricing](https://www.broadpaper.com/developers/pricing/)
|
|
40
|
+
- [Licence agreement](https://www.broadpaper.com/legal/terms/)
|
|
41
|
+
|
|
42
|
+
## Documentation
|
|
43
|
+
|
|
44
|
+
- [The Chromium backend](https://www.broadpaper.com/docs/guide/pdf)
|
|
45
|
+
- [Browserless PDF](https://www.broadpaper.com/docs/guide/browserless-pdf)
|
|
46
|
+
- [Full documentation](https://www.broadpaper.com/docs/)
|
|
47
|
+
|
|
48
|
+
## Support
|
|
49
|
+
|
|
50
|
+
Paid licences include email support at [support@broadpaper.com](mailto:support@broadpaper.com).
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
Copyright © 2026 Codingbadger Creative Limited. See [LICENSE](./LICENSE) in this package, and
|
|
55
|
+
[THIRD-PARTY-NOTICES.md](./THIRD-PARTY-NOTICES.md) for the components it ships with.
|
|
@@ -865,11 +865,25 @@ import { dirname, join } from "path";
|
|
|
865
865
|
// src/server/watermark.ts
|
|
866
866
|
async function stampWatermark(doc, spec) {
|
|
867
867
|
const { StandardFonts, degrees, rgb } = await import("pdf-lib");
|
|
868
|
-
const font = await doc.embedFont(StandardFonts.HelveticaBold);
|
|
868
|
+
const font = await doc.embedFont((spec.placement ?? "center") === "bottom" ? StandardFonts.Helvetica : StandardFonts.HelveticaBold);
|
|
869
869
|
const color = hexToRgb(spec.color);
|
|
870
870
|
const radians = spec.angle * Math.PI / 180;
|
|
871
871
|
const width = font.widthOfTextAtSize(spec.text, spec.fontSize);
|
|
872
872
|
const height = font.heightAtSize(spec.fontSize);
|
|
873
|
+
if ((spec.placement ?? "center") === "bottom") {
|
|
874
|
+
for (const page of doc.getPages()) {
|
|
875
|
+
const { width: pw } = page.getSize();
|
|
876
|
+
page.drawText(spec.text, {
|
|
877
|
+
x: (pw - width) / 2,
|
|
878
|
+
y: spec.fontSize * 1.2,
|
|
879
|
+
size: spec.fontSize,
|
|
880
|
+
font,
|
|
881
|
+
color: rgb(color.r, color.g, color.b),
|
|
882
|
+
opacity: spec.opacity
|
|
883
|
+
});
|
|
884
|
+
}
|
|
885
|
+
return;
|
|
886
|
+
}
|
|
873
887
|
for (const page of doc.getPages()) {
|
|
874
888
|
const { width: pw, height: ph } = page.getSize();
|
|
875
889
|
const x = pw / 2 - Math.cos(radians) * width / 2 + Math.sin(radians) * height / 2;
|
|
@@ -974,7 +988,7 @@ var PdfRenderer = class {
|
|
|
974
988
|
outline: opts.outline ?? true
|
|
975
989
|
});
|
|
976
990
|
const license = await resolveLicenseStatus(opts.license !== void 0 ? { license: opts.license } : {});
|
|
977
|
-
const finished = await applyMetadata(pdf, opts.metadata, opts.now, license);
|
|
991
|
+
const finished = await applyMetadata(pdf, opts.metadata, opts.now, license, opts.watermark);
|
|
978
992
|
return { pdf: finished, pages: result.pages, warnings: result.warnings, durationMs: Date.now() - started };
|
|
979
993
|
} catch (e) {
|
|
980
994
|
if (e instanceof PdfRenderError) throw e;
|
|
@@ -984,13 +998,12 @@ var PdfRenderer = class {
|
|
|
984
998
|
}
|
|
985
999
|
}
|
|
986
1000
|
};
|
|
987
|
-
async function applyMetadata(pdf, meta, now, license) {
|
|
1001
|
+
async function applyMetadata(pdf, meta, now, license, extraWatermark) {
|
|
988
1002
|
const { PDFDocument } = await import("pdf-lib");
|
|
989
1003
|
const status = license ?? await resolveLicenseStatus();
|
|
990
1004
|
const doc = await PDFDocument.load(pdf, { updateMetadata: false });
|
|
991
1005
|
const when = meta?.creationDate ?? now ?? /* @__PURE__ */ new Date();
|
|
992
|
-
const mark
|
|
993
|
-
if (mark) await stampWatermark(doc, mark);
|
|
1006
|
+
for (const mark of [watermarkFor(status), extraWatermark]) if (mark) await stampWatermark(doc, mark);
|
|
994
1007
|
doc.setProducer(producerString(status));
|
|
995
1008
|
doc.setCreator("BroadPaper");
|
|
996
1009
|
doc.setCreationDate(when);
|
|
@@ -1172,4 +1185,4 @@ export {
|
|
|
1172
1185
|
@noble/ed25519/index.js:
|
|
1173
1186
|
(*! noble-ed25519 - MIT License (c) 2019 Paul Miller (paulmillr.com) *)
|
|
1174
1187
|
*/
|
|
1175
|
-
//# sourceMappingURL=chunk-
|
|
1188
|
+
//# sourceMappingURL=chunk-AAE2MQRQ.js.map
|