@broadpaper/pdf 0.2.1 → 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 CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  Chromium-backed PDF generation for BroadPaper, via Playwright. The fidelity reference.
8
8
 
9
- Part of [**BroadPaper**](https://www.broadpaper.com) — an embeddable visual report designer and PDF renderer.
9
+ Part of [**BroadPaper**](https://www.broadpaper.com/developers/) — an embeddable visual report designer and PDF renderer.
10
10
  Your users design the report in your application; BroadPaper owns the layout, the branding,
11
11
  the pagination and the output.
12
12
 
@@ -27,14 +27,16 @@ into an application that only wanted the designer.
27
27
  ## Licensing
28
28
 
29
29
  BroadPaper is **free to evaluate, with no trial clock and nothing behind a feature gate**.
30
- Install it, use every feature, run it against your real data, in production if you like.
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.
31
32
 
32
- The only difference without a licence is that generated PDFs carry an evaluation mark. A
33
- licence removes it — that is the entire commercial mechanism. No seats, no activation, no
34
- machine binding, no telemetry, and no call home at any point.
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.
35
37
 
36
38
  - [How licensing works](https://www.broadpaper.com/docs/guide/licensing/)
37
- - [Pricing](https://www.broadpaper.com/pricing/)
39
+ - [Pricing](https://www.broadpaper.com/developers/pricing/)
38
40
  - [Licence agreement](https://www.broadpaper.com/legal/terms/)
39
41
 
40
42
  ## Documentation
@@ -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 = watermarkFor(status);
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-PFCVDSUU.js.map
1188
+ //# sourceMappingURL=chunk-AAE2MQRQ.js.map