pdf-lib-extended 1.0.3 → 1.0.5
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 +1 -1
- package/src/PDFLibExtended.js +15 -17
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdf-lib-extended",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
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": {
|
package/src/PDFLibExtended.js
CHANGED
|
@@ -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
|
|
@@ -710,18 +709,19 @@ class PDFLibExtended {
|
|
|
710
709
|
align: "left",
|
|
711
710
|
color: this.getColor(),
|
|
712
711
|
size: this.getTextSize(),
|
|
712
|
+
indent: false,
|
|
713
713
|
...options,
|
|
714
714
|
}
|
|
715
|
-
if (defaultOptions.range && !parser) this.getCurrentPage().moveTo(defaultOptions.range.left
|
|
715
|
+
if (defaultOptions.range && !parser) this.getCurrentPage().moveTo(defaultOptions.range.left, this.getCurrentPage().getY());
|
|
716
716
|
let maxWidth = defaultOptions.range.right;
|
|
717
|
-
|
|
717
|
+
|
|
718
718
|
if(nodes.length > 0){
|
|
719
719
|
for(let node of nodes){
|
|
720
720
|
if(node.nodeType === Node.ELEMENT_NODE){
|
|
721
721
|
this.addNode(node.nodeName);
|
|
722
722
|
switch (node.nodeName) {
|
|
723
723
|
case "P":
|
|
724
|
-
this.getCurrentPage().moveTo(defaultOptions.range.left
|
|
724
|
+
this.getCurrentPage().moveTo(defaultOptions.range.left, this.getCurrentPage().getY() - defaultOptions.margin);
|
|
725
725
|
this.nextLine();
|
|
726
726
|
this.getCurrentPage().moveTo(defaultOptions.range.left, this.getCurrentPage().getY());
|
|
727
727
|
break;
|
|
@@ -739,8 +739,8 @@ class PDFLibExtended {
|
|
|
739
739
|
this.nextLine();
|
|
740
740
|
this.getCurrentPage().moveTo(defaultOptions.range.left, this.getCurrentPage().getY());
|
|
741
741
|
this.getCurrentPage().moveRight(this.getCurrentNodes().filter(value => value === "UL").length * this.getMargin().left);
|
|
742
|
-
this.drawText("
|
|
743
|
-
this.getCurrentPage().moveRight(this.getCurrentFont().widthOfTextAtSize("
|
|
742
|
+
this.drawText("• ", { size: defaultOptions.size, color: defaultOptions.color });
|
|
743
|
+
this.getCurrentPage().moveRight(this.getCurrentFont().widthOfTextAtSize("• ", defaultOptions.size));
|
|
744
744
|
break;
|
|
745
745
|
case "TABLE":
|
|
746
746
|
let tableHead = [];
|
|
@@ -767,28 +767,26 @@ class PDFLibExtended {
|
|
|
767
767
|
break;
|
|
768
768
|
}
|
|
769
769
|
}
|
|
770
|
-
|
|
770
|
+
|
|
771
771
|
if(node.nodeName === "TABLE") break;
|
|
772
|
-
|
|
772
|
+
|
|
773
773
|
this.htmlParser(node, parser, defaultOptions);
|
|
774
774
|
}
|
|
775
775
|
}else{
|
|
776
776
|
if(text.data){
|
|
777
777
|
/*** DRAW TEXT ***/
|
|
778
778
|
let splitText = text.data.split(" ");
|
|
779
|
-
let isFirstWord = true;
|
|
780
779
|
splitText.forEach(string => {
|
|
780
|
+
if(defaultOptions.indent){
|
|
781
|
+
this.getCurrentPage().moveRight(30);
|
|
782
|
+
defaultOptions.indent = false;
|
|
783
|
+
}
|
|
784
|
+
|
|
781
785
|
string += " ";
|
|
782
786
|
let wordWidth = this.getCurrentFont().widthOfTextAtSize(string, defaultOptions.size);
|
|
783
787
|
if(wordWidth + this.getCurrentPage().getX() >= maxWidth){
|
|
784
788
|
this.nextLine();
|
|
785
789
|
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
790
|
}
|
|
793
791
|
this.drawText(string, {
|
|
794
792
|
size: defaultOptions.size,
|
|
@@ -796,14 +794,14 @@ class PDFLibExtended {
|
|
|
796
794
|
});
|
|
797
795
|
this.getCurrentPage().moveRight(this.getCurrentFont().widthOfTextAtSize(string, defaultOptions.size));
|
|
798
796
|
});
|
|
799
|
-
|
|
797
|
+
|
|
800
798
|
/*** REMOVE STYLINGS ***/
|
|
801
799
|
this.checkParentHTML(text);
|
|
802
800
|
}
|
|
803
801
|
return;
|
|
804
802
|
}
|
|
805
803
|
}
|
|
806
|
-
|
|
804
|
+
|
|
807
805
|
/**
|
|
808
806
|
*
|
|
809
807
|
* @param {string} text
|