pdf-lib-extended 1.0.20 → 1.0.21

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pdf-lib-extended",
3
- "version": "1.0.20",
3
+ "version": "1.0.21",
4
4
  "description": "This project extends the capabilities of the pdf-lib JavaScript library by providing a set of helper functions that simplify common PDF manipulation tasks. It includes utilities for drawing and formatting text, images, and shapes within PDF documents, allowing for more advanced customization and automation. The class-based architecture, designed as a toolkit, ensures that developers can easily integrate these enhanced features into their existing workflows. With this extension, users can streamline the creation of dynamic and complex PDFs with minimal effort.",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -464,15 +464,15 @@ class PDFLibExtended {
464
464
  * @param {import('pdf-lib').RGB} options.color - The color of the text
465
465
  * @param {number} options.opacity - The opacity of the text
466
466
  */
467
- drawParagraph(pdf, text, options = {}) {
467
+ drawParagraph(text, options = {}) {
468
468
  const defaultOptions = {
469
469
  align: "left",
470
470
  range: {
471
- left: pdf.getMargin().left,
472
- right: pdf.getCurrentPage().getWidth() - pdf.getMargin().right
471
+ left: this.getMargin().left,
472
+ right: this.getCurrentPage().getWidth() - this.getMargin().right
473
473
  },
474
- size: pdf.getTextSize(),
475
- color: pdf.getColor(),
474
+ size: this.getTextSize(),
475
+ color: this.getColor(),
476
476
  opacity: 1,
477
477
  padding: 0, // extra spacing between lines
478
478
  wordWrap: true,
@@ -481,7 +481,7 @@ class PDFLibExtended {
481
481
  };
482
482
 
483
483
  // Always move to paragraph start (left edge of range)
484
- pdf.getCurrentPage().moveTo(defaultOptions.range.left, pdf.getCurrentPage().getY());
484
+ this.getCurrentPage().moveTo(defaultOptions.range.left, pdf.getCurrentPage().getY());
485
485
 
486
486
  const maxWidth = defaultOptions.range.right - defaultOptions.range.left;
487
487
 
@@ -497,21 +497,21 @@ class PDFLibExtended {
497
497
  const piece = needsSpace ? (" " + tok) : tok;
498
498
 
499
499
  // Measure exactly what we plan to add
500
- const pieceWidth = pdf.getCurrentFont().widthOfTextAtSize(piece, defaultOptions.size);
500
+ const pieceWidth = this.getCurrentFont().widthOfTextAtSize(piece, defaultOptions.size);
501
501
 
502
502
  // If this piece would overflow, draw current line and move down
503
503
  if (currentLine && (currentWidth + pieceWidth > maxWidth)) {
504
- pdf.drawText(currentLine, {
504
+ this.drawText(currentLine, {
505
505
  size: defaultOptions.size,
506
506
  color: defaultOptions.color,
507
507
  opacity: defaultOptions.opacity,
508
508
  align: defaultOptions.align,
509
509
  range: defaultOptions.range
510
510
  });
511
- pdf.nextLine(defaultOptions.padding);
512
- pdf.getCurrentPage().moveTo(defaultOptions.range.left, pdf.getCurrentPage().getY());
511
+ this.nextLine(defaultOptions.padding);
512
+ this.getCurrentPage().moveTo(defaultOptions.range.left, pdf.getCurrentPage().getY());
513
513
  currentLine = tok; // start new line with the token (no leading space)
514
- currentWidth = pdf.getCurrentFont().widthOfTextAtSize(tok, defaultOptions.size);
514
+ currentWidth = this.getCurrentFont().widthOfTextAtSize(tok, defaultOptions.size);
515
515
  } else {
516
516
  // Safe to add to this line
517
517
  currentLine += piece;
@@ -520,7 +520,7 @@ class PDFLibExtended {
520
520
 
521
521
  // Last token: flush
522
522
  if (i === tokens.length - 1 && currentLine) {
523
- pdf.drawText(currentLine, {
523
+ this.drawText(currentLine, {
524
524
  size: defaultOptions.size,
525
525
  color: defaultOptions.color,
526
526
  opacity: defaultOptions.opacity,