pdf-lib-extended 1.0.1 → 1.0.3

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,8 +1,12 @@
1
1
  {
2
2
  "name": "pdf-lib-extended",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
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
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/JalenLT/pdf-lib-extended.git"
9
+ },
6
10
  "type": "module",
7
11
  "keywords": [
8
12
  "pdf",
@@ -26,6 +30,10 @@
26
30
  },
27
31
  "author": "JalenLT",
28
32
  "license": "ISC",
33
+ "bugs": {
34
+ "url": "https://github.com/JalenLT/pdf-lib-extended/issues"
35
+ },
36
+ "homepage": "https://github.com/JalenLT/pdf-lib-extended#readme",
29
37
  "dependencies": {
30
38
  "pdf-lib": "^1.17.1"
31
39
  }
@@ -702,6 +702,7 @@ 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
705
706
  range: {
706
707
  left: this.getMargin().left,
707
708
  right: this.getCurrentPage().getWidth() - this.getMargin().right
@@ -711,16 +712,16 @@ class PDFLibExtended {
711
712
  size: this.getTextSize(),
712
713
  ...options,
713
714
  }
714
- if (defaultOptions.range && !parser) this.getCurrentPage().moveTo(defaultOptions.range.left, this.getCurrentPage().getY());
715
+ if (defaultOptions.range && !parser) this.getCurrentPage().moveTo(defaultOptions.range.left + defaultOptions.indent, this.getCurrentPage().getY());
715
716
  let maxWidth = defaultOptions.range.right;
716
-
717
+
717
718
  if(nodes.length > 0){
718
719
  for(let node of nodes){
719
720
  if(node.nodeType === Node.ELEMENT_NODE){
720
721
  this.addNode(node.nodeName);
721
722
  switch (node.nodeName) {
722
723
  case "P":
723
- this.getCurrentPage().moveTo(defaultOptions.range.left, this.getCurrentPage().getY() - defaultOptions.margin);
724
+ this.getCurrentPage().moveTo(defaultOptions.range.left + defaultOptions.indent, this.getCurrentPage().getY() - defaultOptions.margin);
724
725
  this.nextLine();
725
726
  this.getCurrentPage().moveTo(defaultOptions.range.left, this.getCurrentPage().getY());
726
727
  break;
@@ -738,8 +739,8 @@ class PDFLibExtended {
738
739
  this.nextLine();
739
740
  this.getCurrentPage().moveTo(defaultOptions.range.left, this.getCurrentPage().getY());
740
741
  this.getCurrentPage().moveRight(this.getCurrentNodes().filter(value => value === "UL").length * this.getMargin().left);
741
- this.drawText(" ", { size: defaultOptions.size, color: defaultOptions.color });
742
- this.getCurrentPage().moveRight(this.getCurrentFont().widthOfTextAtSize(" ", defaultOptions.size));
742
+ this.drawText("\u2022 ", { size: defaultOptions.size, color: defaultOptions.color });
743
+ this.getCurrentPage().moveRight(this.getCurrentFont().widthOfTextAtSize("\u2022 ", defaultOptions.size));
743
744
  break;
744
745
  case "TABLE":
745
746
  let tableHead = [];
@@ -766,21 +767,28 @@ class PDFLibExtended {
766
767
  break;
767
768
  }
768
769
  }
769
-
770
+
770
771
  if(node.nodeName === "TABLE") break;
771
-
772
+
772
773
  this.htmlParser(node, parser, defaultOptions);
773
774
  }
774
775
  }else{
775
776
  if(text.data){
776
777
  /*** DRAW TEXT ***/
777
778
  let splitText = text.data.split(" ");
779
+ let isFirstWord = true;
778
780
  splitText.forEach(string => {
779
781
  string += " ";
780
782
  let wordWidth = this.getCurrentFont().widthOfTextAtSize(string, defaultOptions.size);
781
783
  if(wordWidth + this.getCurrentPage().getX() >= maxWidth){
782
784
  this.nextLine();
783
785
  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;
784
792
  }
785
793
  this.drawText(string, {
786
794
  size: defaultOptions.size,
@@ -788,14 +796,14 @@ class PDFLibExtended {
788
796
  });
789
797
  this.getCurrentPage().moveRight(this.getCurrentFont().widthOfTextAtSize(string, defaultOptions.size));
790
798
  });
791
-
799
+
792
800
  /*** REMOVE STYLINGS ***/
793
801
  this.checkParentHTML(text);
794
802
  }
795
803
  return;
796
804
  }
797
805
  }
798
-
806
+
799
807
  /**
800
808
  *
801
809
  * @param {string} text