pdf-lib-extended 1.0.46 → 1.0.48

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.46",
3
+ "version": "1.0.48",
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": {
@@ -532,6 +532,7 @@ class PDFLibExtended {
532
532
 
533
533
  let currentLine = "";
534
534
  let currentWidth = 0;
535
+ let biggestWidth = 0;
535
536
  let totalHeight = defaultOptions.size;
536
537
 
537
538
  tokens.forEach((tok, i) => {
@@ -558,27 +559,30 @@ class PDFLibExtended {
558
559
  this.getCurrentPage().moveTo(defaultOptions.range.left, this.getCurrentPage().getY());
559
560
  currentLine = tok; // start new line with the token (no leading space)
560
561
  currentWidth = this.getCurrentFont().widthOfTextAtSize(tok, defaultOptions.size);
562
+ if(currentWidth > biggestWidth) biggestWidth = currentWidth;
561
563
  } else {
562
564
  // Safe to add to this line
563
565
  currentLine += piece;
564
566
  currentWidth += pieceWidth;
567
+ if(currentWidth > biggestWidth) biggestWidth = currentWidth;
565
568
  }
566
569
 
567
570
  // Last token: flush
568
571
  if (i === tokens.length - 1 && currentLine) {
569
- this.drawText(currentLine, {
570
- size: defaultOptions.size,
571
- color: defaultOptions.color,
572
- opacity: defaultOptions.opacity,
573
- align: defaultOptions.align,
574
- range: defaultOptions.range,
575
- textDecoration: defaultOptions.textDecoration
576
- });
572
+ this.drawText(currentLine, {
573
+ size: defaultOptions.size,
574
+ color: defaultOptions.color,
575
+ opacity: defaultOptions.opacity,
576
+ align: defaultOptions.align,
577
+ range: defaultOptions.range,
578
+ textDecoration: defaultOptions.textDecoration
579
+ });
577
580
  }
578
581
  });
579
582
 
580
583
  return {
581
- height: totalHeight
584
+ height: totalHeight,
585
+ width: biggestWidth
582
586
  };
583
587
  }
584
588
 
@@ -639,9 +643,9 @@ class PDFLibExtended {
639
643
  if(defaultOptions.border){
640
644
  page.drawRectangle({
641
645
  x: x,
642
- y: y - ((defaultOptions.height) ? defaultOptions.height : drawParagraphResponse.height) + defaultOptions.size - defaultOptions.padding,
646
+ y: y - ((defaultOptions.height) ? defaultOptions.height : drawParagraphResponse.height) + defaultOptions.size + defaultOptions.padding,
643
647
  width: width,
644
- height: (defaultOptions.height) ? defaultOptions.height : drawParagraphResponse.height,
648
+ height: (defaultOptions.height) ? defaultOptions.height : drawParagraphResponse.height + defaultOptions.padding,
645
649
  color: defaultOptions.backgroundColor,
646
650
  borderWidth: defaultOptions.lineThickness,
647
651
  borderColor: defaultOptions.borderColor,
@@ -650,9 +654,9 @@ class PDFLibExtended {
650
654
  }else{
651
655
  page.drawRectangle({
652
656
  x: x,
653
- y: y - ((defaultOptions.height) ? defaultOptions.height : drawParagraphResponse.height) + defaultOptions.size - defaultOptions.padding,
657
+ y: y - ((defaultOptions.height) ? defaultOptions.height : drawParagraphResponse.height) + defaultOptions.size + defaultOptions.padding,
654
658
  width: width,
655
- height: (defaultOptions.height) ? defaultOptions.height : drawParagraphResponse.height,
659
+ height: (defaultOptions.height) ? defaultOptions.height : drawParagraphResponse.height + defaultOptions.padding,
656
660
  color: defaultOptions.backgroundColor,
657
661
  });
658
662
  }