pdf-lib-extended 1.0.12 → 1.0.15

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.12",
3
+ "version": "1.0.15",
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": {
@@ -474,6 +474,9 @@ class PDFLibExtended {
474
474
  size: this.getTextSize(),
475
475
  color: this.getColor(),
476
476
  opacity: 1,
477
+ padding: 0,
478
+ wordWrap: true,
479
+ characterWrap: false,
477
480
  ...options
478
481
  };
479
482
  if(options.range) this.getCurrentPage().moveTo(defaultOptions.range.left, this.getCurrentPage().getY());
@@ -482,7 +485,11 @@ class PDFLibExtended {
482
485
  let currentWidth = 0;
483
486
  let currentLine = "";
484
487
 
485
- text = text.split(" ");
488
+ if(wordWrap){
489
+ text = text.split(" ");
490
+ }else{
491
+ text = text.split("");
492
+ }
486
493
 
487
494
  text.forEach((string, i) => {
488
495
  let wordWidth = this.getCurrentFont().widthOfTextAtSize(string, defaultOptions.size);
@@ -498,13 +505,15 @@ class PDFLibExtended {
498
505
  });
499
506
 
500
507
  // Move to the next line
501
- this.nextLine();
508
+ this.nextLine(defaultOptions.padding);
502
509
  this.getCurrentPage().moveTo(defaultOptions.range.left, this.getCurrentPage().getY());
503
510
  currentLine = "";
504
511
  currentWidth = 0;
505
512
  }
506
513
 
507
- currentLine += string + " ";
514
+ if(wordWrap){
515
+ currentLine += string + " ";
516
+ }
508
517
  currentWidth += wordWidth;
509
518
 
510
519
  // If it's the last word, draw the remaining line
@@ -608,7 +617,7 @@ class PDFLibExtended {
608
617
  }
609
618
 
610
619
  if(defaultOptions.newLine){
611
- this.nextLine();
620
+ this.nextLine(defaultOptions.padding);
612
621
  page.moveTo(page.getX(), y - Number(defaultOptions.height) - change - defaultOptions.size - defaultOptions.padding);
613
622
  }
614
623
  else page.moveTo(x + width + defaultOptions.padding, y - defaultOptions.size);
@@ -710,6 +719,7 @@ class PDFLibExtended {
710
719
  color: this.getColor(),
711
720
  size: this.getTextSize(),
712
721
  indent: false,
722
+ padding: 0,
713
723
  ...options,
714
724
  }
715
725
  if (defaultOptions.range && !parser) this.getCurrentPage().moveTo(defaultOptions.range.left, this.getCurrentPage().getY());
@@ -722,7 +732,7 @@ class PDFLibExtended {
722
732
  switch (node.nodeName) {
723
733
  case "P":
724
734
  this.getCurrentPage().moveTo(defaultOptions.range.left, this.getCurrentPage().getY() - defaultOptions.margin);
725
- this.nextLine();
735
+ this.nextLine(defaultOptions.padding);
726
736
  this.getCurrentPage().moveTo(defaultOptions.range.left, this.getCurrentPage().getY());
727
737
  break;
728
738
  case "STRONG":
@@ -736,7 +746,7 @@ class PDFLibExtended {
736
746
  case "UL":
737
747
  break;
738
748
  case "LI":
739
- this.nextLine();
749
+ this.nextLine(defaultOptions.padding);
740
750
  this.getCurrentPage().moveTo(defaultOptions.range.left, this.getCurrentPage().getY());
741
751
  this.getCurrentPage().moveRight(this.getCurrentNodes().filter(value => value === "UL").length * this.getMargin().left);
742
752
  this.drawText("• ", { size: defaultOptions.size, color: defaultOptions.color });
@@ -755,7 +765,7 @@ class PDFLibExtended {
755
765
  });
756
766
  tableData.push(tableRow);
757
767
  });
758
- this.nextLine();
768
+ this.nextLine(defaultOptions.padding);
759
769
  this.getCurrentPage().moveTo(defaultOptions.range.left, this.getCurrentPage().getY());
760
770
  this.drawTable(tableHead, tableData, {
761
771
  range: {left: defaultOptions.range.left, right: defaultOptions.range.right},
@@ -785,7 +795,7 @@ class PDFLibExtended {
785
795
  string += " ";
786
796
  let wordWidth = this.getCurrentFont().widthOfTextAtSize(string, defaultOptions.size);
787
797
  if(wordWidth + this.getCurrentPage().getX() >= maxWidth){
788
- this.nextLine();
798
+ this.nextLine(defaultOptions.padding);
789
799
  this.getCurrentPage().moveTo(defaultOptions.range.left, this.getCurrentPage().getY());
790
800
  }
791
801
  this.drawText(string, {