pdf-lib-extended 1.0.4 → 1.0.6
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 +8 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdf-lib-extended",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
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
|
@@ -709,6 +709,7 @@ class PDFLibExtended {
|
|
|
709
709
|
align: "left",
|
|
710
710
|
color: this.getColor(),
|
|
711
711
|
size: this.getTextSize(),
|
|
712
|
+
indent: false,
|
|
712
713
|
...options,
|
|
713
714
|
}
|
|
714
715
|
if (defaultOptions.range && !parser) this.getCurrentPage().moveTo(defaultOptions.range.left, this.getCurrentPage().getY());
|
|
@@ -776,6 +777,11 @@ class PDFLibExtended {
|
|
|
776
777
|
/*** DRAW TEXT ***/
|
|
777
778
|
let splitText = text.data.split(" ");
|
|
778
779
|
splitText.forEach(string => {
|
|
780
|
+
if(defaultOptions.indent){
|
|
781
|
+
this.getCurrentPage().moveRight(30);
|
|
782
|
+
defaultOptions.indent = false;
|
|
783
|
+
}
|
|
784
|
+
|
|
779
785
|
string += " ";
|
|
780
786
|
let wordWidth = this.getCurrentFont().widthOfTextAtSize(string, defaultOptions.size);
|
|
781
787
|
if(wordWidth + this.getCurrentPage().getX() >= maxWidth){
|
|
@@ -888,10 +894,10 @@ class PDFLibExtended {
|
|
|
888
894
|
* @param {base64} base64Image
|
|
889
895
|
* @param {number} imageScale
|
|
890
896
|
*/
|
|
891
|
-
|
|
897
|
+
addImage(x, y, base64Image, imageScale = 1) {
|
|
892
898
|
if (base64Image.includes(",")) base64Image = base64Image.split(",")[1];
|
|
893
899
|
let imageBytes = Uint8Array.from(atob(base64Image), c => c.charCodeAt(0));
|
|
894
|
-
let embeddedImage =
|
|
900
|
+
let embeddedImage = this.getPDF().embedPng(imageBytes);
|
|
895
901
|
let { width, height } = embeddedImage.scale(imageScale);
|
|
896
902
|
this.getCurrentPage().drawImage(embeddedImage, {
|
|
897
903
|
x: x,
|