pdf-lib-extended 1.0.45 → 1.0.47

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.45",
3
+ "version": "1.0.47",
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": {
@@ -377,7 +377,7 @@ class PDFLibExtended {
377
377
  * @returns {object} - An object containing the added space, the new X position, and the new Y position
378
378
  */
379
379
  nextLine(padding = null) {
380
- const addedSpace = 0;
380
+ let addedSpace = 0;
381
381
  if(padding && !isNaN(Number(padding))) {
382
382
  addedSpace += Number(padding);
383
383
  }else{
@@ -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