pdf-lib-extended 1.0.22 → 1.0.24

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.22",
3
+ "version": "1.0.24",
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": {
@@ -481,7 +481,7 @@ class PDFLibExtended {
481
481
  };
482
482
 
483
483
  // Always move to paragraph start (left edge of range)
484
- this.getCurrentPage().moveTo(defaultOptions.range.left, pdf.getCurrentPage().getY());
484
+ this.getCurrentPage().moveTo(defaultOptions.range.left, this.getCurrentPage().getY());
485
485
 
486
486
  const maxWidth = defaultOptions.range.right - defaultOptions.range.left;
487
487
 
@@ -509,7 +509,7 @@ class PDFLibExtended {
509
509
  range: defaultOptions.range
510
510
  });
511
511
  this.nextLine(defaultOptions.padding);
512
- this.getCurrentPage().moveTo(defaultOptions.range.left, pdf.getCurrentPage().getY());
512
+ this.getCurrentPage().moveTo(defaultOptions.range.left, this.getCurrentPage().getY());
513
513
  currentLine = tok; // start new line with the token (no leading space)
514
514
  currentWidth = this.getCurrentFont().widthOfTextAtSize(tok, defaultOptions.size);
515
515
  } else {
@@ -560,6 +560,7 @@ class PDFLibExtended {
560
560
  align: "left",
561
561
  newLine: true,
562
562
  size: this.getTextSize(),
563
+ backgroundColor: null,
563
564
  color: this.getColor(),
564
565
  lineThickness: 1,
565
566
  padding: 4,
@@ -568,10 +569,35 @@ class PDFLibExtended {
568
569
  };
569
570
  let page = this.getCurrentPage();
570
571
  page.moveTo(x, y);
572
+
573
+ /*** TEXT ***/
571
574
  let change = page.getY();
572
575
  this.drawParagraph(text, {range: {left: x, right: x + width}, align: defaultOptions.align, size: defaultOptions.size, color: defaultOptions.color});
573
576
  change -= page.getY() - defaultOptions.size;
574
577
 
578
+ /*** BACKGROUND ***/
579
+ if(backgroundColor !== null){
580
+ page.drawRectangle({
581
+ x: x,
582
+ y: y,
583
+ width: width,
584
+ height: (
585
+ (defaultOptions.height)
586
+ ?
587
+ defaultOptions.height
588
+ :
589
+ change - defaultOptions.padding
590
+ ),
591
+ color: defaultOptions.backgroundColor
592
+ });
593
+ }
594
+
595
+ /*** TEXT ***/
596
+ page.moveTo(x, y);
597
+ change = page.getY();
598
+ this.drawParagraph(text, {range: {left: x, right: x + width}, align: defaultOptions.align, size: defaultOptions.size, color: defaultOptions.color});
599
+ change -= page.getY() - defaultOptions.size;
600
+
575
601
  y += defaultOptions.size;
576
602
 
577
603
  /*** BORDERS ***/
@@ -652,7 +678,9 @@ class PDFLibExtended {
652
678
  align: "center",
653
679
  border: true,
654
680
  size: this.getTextSize(),
681
+ backgroundColor: null,
655
682
  color: this.getColor(),
683
+ lineThickness: 1,
656
684
  ...options
657
685
  };
658
686
  if (options.range) this.getCurrentPage().moveTo(defaultOptions.range.left, this.getCurrentPage().getY());
@@ -670,8 +698,10 @@ class PDFLibExtended {
670
698
  border: defaultOptions.border,
671
699
  align: defaultOptions.align,
672
700
  size: defaultOptions.size + defaultOptions.headerDifference,
701
+ backgroundColor: defaultOptions.backgroundColor,
673
702
  color: defaultOptions.color,
674
- newLine: (i === header.length - 1) ? true : false
703
+ newLine: (i === header.length - 1) ? true : false,
704
+ lineThickness: defaultOptions.lineThickness
675
705
  });
676
706
  });
677
707
  }
@@ -685,8 +715,10 @@ class PDFLibExtended {
685
715
  border: defaultOptions.border,
686
716
  align: defaultOptions.align,
687
717
  size: defaultOptions.size + defaultOptions.headerDifference,
718
+ backgroundColor: defaultOptions.backgroundColor,
688
719
  color: defaultOptions.color,
689
- newLine: (i === header.length - 1) ? true : false
720
+ newLine: (i === header.length - 1) ? true : false,
721
+ lineThickness: defaultOptions.lineThickness
690
722
  });
691
723
  });
692
724
  });