pdf-lib-extended 1.0.17 → 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 +1 -1
- package/src/PDFLibExtended.js +15 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdf-lib-extended",
|
|
3
|
-
"version": "1.0.
|
|
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": {
|
package/src/PDFLibExtended.js
CHANGED
|
@@ -906,16 +906,27 @@ class PDFLibExtended {
|
|
|
906
906
|
* @param {base64} base64Image
|
|
907
907
|
* @param {number} imageScale
|
|
908
908
|
*/
|
|
909
|
-
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
|
+
|
|
910
917
|
if (base64Image.includes(",")) base64Image = base64Image.split(",")[1];
|
|
911
918
|
let imageBytes = Uint8Array.from(atob(base64Image), c => c.charCodeAt(0));
|
|
912
919
|
let embeddedImage = await this.getPDF().embedPng(imageBytes);
|
|
913
|
-
|
|
920
|
+
if(defaultOptions.width == null && defaultOptions.height == null){
|
|
921
|
+
let { width, height } = embeddedImage.scale(imageScale);
|
|
922
|
+
defaultOptions.width = width;
|
|
923
|
+
defaultOptions.height = height;
|
|
924
|
+
}
|
|
914
925
|
this.getCurrentPage().drawImage(embeddedImage, {
|
|
915
926
|
x: x,
|
|
916
927
|
y: y,
|
|
917
|
-
width: width,
|
|
918
|
-
height: height,
|
|
928
|
+
width: defaultOptions.width,
|
|
929
|
+
height: defaultOptions.height,
|
|
919
930
|
});
|
|
920
931
|
}
|
|
921
932
|
|