pdf-lib-extended 1.0.3 → 1.0.4

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.3",
3
+ "version": "1.0.4",
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": {
@@ -702,7 +702,6 @@ class PDFLibExtended {
702
702
  let nodes = doc.childNodes;
703
703
  let defaultOptions = {
704
704
  margin: 8,
705
- indent: 0, // New indent option for the first line
706
705
  range: {
707
706
  left: this.getMargin().left,
708
707
  right: this.getCurrentPage().getWidth() - this.getMargin().right
@@ -712,16 +711,16 @@ class PDFLibExtended {
712
711
  size: this.getTextSize(),
713
712
  ...options,
714
713
  }
715
- if (defaultOptions.range && !parser) this.getCurrentPage().moveTo(defaultOptions.range.left + defaultOptions.indent, this.getCurrentPage().getY());
714
+ if (defaultOptions.range && !parser) this.getCurrentPage().moveTo(defaultOptions.range.left, this.getCurrentPage().getY());
716
715
  let maxWidth = defaultOptions.range.right;
717
-
716
+
718
717
  if(nodes.length > 0){
719
718
  for(let node of nodes){
720
719
  if(node.nodeType === Node.ELEMENT_NODE){
721
720
  this.addNode(node.nodeName);
722
721
  switch (node.nodeName) {
723
722
  case "P":
724
- this.getCurrentPage().moveTo(defaultOptions.range.left + defaultOptions.indent, this.getCurrentPage().getY() - defaultOptions.margin);
723
+ this.getCurrentPage().moveTo(defaultOptions.range.left, this.getCurrentPage().getY() - defaultOptions.margin);
725
724
  this.nextLine();
726
725
  this.getCurrentPage().moveTo(defaultOptions.range.left, this.getCurrentPage().getY());
727
726
  break;
@@ -739,8 +738,8 @@ class PDFLibExtended {
739
738
  this.nextLine();
740
739
  this.getCurrentPage().moveTo(defaultOptions.range.left, this.getCurrentPage().getY());
741
740
  this.getCurrentPage().moveRight(this.getCurrentNodes().filter(value => value === "UL").length * this.getMargin().left);
742
- this.drawText("\u2022 ", { size: defaultOptions.size, color: defaultOptions.color });
743
- this.getCurrentPage().moveRight(this.getCurrentFont().widthOfTextAtSize("\u2022 ", defaultOptions.size));
741
+ this.drawText(" ", { size: defaultOptions.size, color: defaultOptions.color });
742
+ this.getCurrentPage().moveRight(this.getCurrentFont().widthOfTextAtSize(" ", defaultOptions.size));
744
743
  break;
745
744
  case "TABLE":
746
745
  let tableHead = [];
@@ -767,28 +766,21 @@ class PDFLibExtended {
767
766
  break;
768
767
  }
769
768
  }
770
-
769
+
771
770
  if(node.nodeName === "TABLE") break;
772
-
771
+
773
772
  this.htmlParser(node, parser, defaultOptions);
774
773
  }
775
774
  }else{
776
775
  if(text.data){
777
776
  /*** DRAW TEXT ***/
778
777
  let splitText = text.data.split(" ");
779
- let isFirstWord = true;
780
778
  splitText.forEach(string => {
781
779
  string += " ";
782
780
  let wordWidth = this.getCurrentFont().widthOfTextAtSize(string, defaultOptions.size);
783
781
  if(wordWidth + this.getCurrentPage().getX() >= maxWidth){
784
782
  this.nextLine();
785
783
  this.getCurrentPage().moveTo(defaultOptions.range.left, this.getCurrentPage().getY());
786
- isFirstWord = false;
787
- }
788
- // Apply indent only for the first line
789
- if(isFirstWord && defaultOptions.indent > 0) {
790
- this.getCurrentPage().moveRight(defaultOptions.indent);
791
- isFirstWord = false;
792
784
  }
793
785
  this.drawText(string, {
794
786
  size: defaultOptions.size,
@@ -796,14 +788,14 @@ class PDFLibExtended {
796
788
  });
797
789
  this.getCurrentPage().moveRight(this.getCurrentFont().widthOfTextAtSize(string, defaultOptions.size));
798
790
  });
799
-
791
+
800
792
  /*** REMOVE STYLINGS ***/
801
793
  this.checkParentHTML(text);
802
794
  }
803
795
  return;
804
796
  }
805
797
  }
806
-
798
+
807
799
  /**
808
800
  *
809
801
  * @param {string} text