pdf-lib-extended 1.0.16 → 1.0.19

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.16",
3
+ "version": "1.0.19",
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": {
@@ -513,6 +513,8 @@ class PDFLibExtended {
513
513
 
514
514
  if(defaultOptions.wordWrap){
515
515
  currentLine += string + " ";
516
+ }else{
517
+ currentLine += string;
516
518
  }
517
519
  currentWidth += wordWidth;
518
520
 
@@ -904,16 +906,27 @@ class PDFLibExtended {
904
906
  * @param {base64} base64Image
905
907
  * @param {number} imageScale
906
908
  */
907
- async addImage(x, y, base64Image, imageScale = 1) {
909
+ async addImage(x, y, base64Image, imageScale = 1, options = {}) {
910
+ let defaultOptions = {
911
+ width: null,
912
+ height: null,
913
+ borderWidth: 2,
914
+ ...options
915
+ };
916
+
908
917
  if (base64Image.includes(",")) base64Image = base64Image.split(",")[1];
909
918
  let imageBytes = Uint8Array.from(atob(base64Image), c => c.charCodeAt(0));
910
919
  let embeddedImage = await this.getPDF().embedPng(imageBytes);
911
- let { width, height } = embeddedImage.scale(imageScale);
920
+ if(defaultOptions.width == null && defaultOptions.height == null){
921
+ let { width, height } = embeddedImage.scale(imageScale);
922
+ defaultOptions.width = width;
923
+ defaultOptions.height = height;
924
+ }
912
925
  this.getCurrentPage().drawImage(embeddedImage, {
913
926
  x: x,
914
927
  y: y,
915
- width: width,
916
- height: height,
928
+ width: defaultOptions.width,
929
+ height: defaultOptions.height,
917
930
  });
918
931
  }
919
932