Skip to content

Commit

Permalink
Merge pull request #105 from LibreSign/chore/use-cache-to-load-async-…
Browse files Browse the repository at this point in the history
…reader

chore: use asyncReader dynamic
  • Loading branch information
vitormattos authored Oct 28, 2024
2 parents de4be38 + 28e1dea commit b6f6f15
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@libresign/vue-pdf-editor",
"description": "vue2 pdf editor component",
"version": "1.3.4",
"version": "1.3.5",
"author": "LibreCode",
"private": false,
"main": "dist/vue-pdf-editor.umd.js",
Expand Down
12 changes: 11 additions & 1 deletion src/utils/PDF.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { readAsArrayBuffer } from './asyncReader.js'
import { fetchFont } from './prepareAssets.js'
import { noop } from './helper.js'
import * as PDFLib from '@cantoo/pdf-lib'
Expand Down Expand Up @@ -37,6 +36,16 @@ export async function makeTextPDF({
});
}

let readAsArrayBuffer = null;

async function loadReadAsArrayBuffer() {
if (!readAsArrayBuffer) {
const asyncReaderModule = await import('./asyncReader.js');
readAsArrayBuffer = asyncReaderModule.readAsArrayBuffer;
}
return readAsArrayBuffer;
}

/**
*
* @param pdfFile
Expand All @@ -46,6 +55,7 @@ export async function makeTextPDF({
* @param callback
*/
export async function save(pdfFile, objects, name, isUpload = false, callback) {
const readAsArrayBuffer = await loadReadAsArrayBuffer();
let pdfDoc
try {
pdfDoc = await PDFLib.PDFDocument.load(await readAsArrayBuffer(pdfFile))
Expand Down

0 comments on commit b6f6f15

Please sign in to comment.