Skip to content

Commit

Permalink
better html template
Browse files Browse the repository at this point in the history
  • Loading branch information
paulocoutinhox committed Aug 21, 2024
1 parent 80e85b3 commit 9e03240
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
17 changes: 6 additions & 11 deletions extras/wasm/template/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
return H(F64, 2, [-1, -1])((w, h) => FPDF.GetPageSizeByIndex(this.wasmData.wasm, i, w, h)).map(v => parseInt(v) * s);
}

// use custom read mechanism to load only necessary parts of the pdf
getRender(i = 0, w, h) {
const flag = FPDF.REVERSE_BYTE_ORDER | FPDF.ANNOT;
const heap = Module.wasmExports.malloc(w * h * C);
Expand All @@ -173,6 +174,7 @@
return heap;
}

// optimized page rendering by reading only required parts
getPageRender(n = 0, w, h) {
let pageRenderPtr = this.getRender(n, w, h);
let pageRenderData = [];
Expand Down Expand Up @@ -205,25 +207,18 @@
switch (lastError) {
case FPDF.LAST_ERROR.SUCCESS:
return "success";
break;
case FPDF.LAST_ERROR.UNKNOWN:
return "unknown error";
break;
case FPDF.LAST_ERROR.FILE:
return "file not found or could not be opened";
break;
case FPDF.LAST_ERROR.FORMAT:
return "file not in PDF format or corrupted";
break;
case FPDF.LAST_ERROR.PASSWORD:
return "password required or incorrect password";
break;
case FPDF.LAST_ERROR.SECURITY:
return "unsupported security scheme";
break;
case FPDF.LAST_ERROR.PAGE:
return "page not found or content error";
break;
default:
return "unknown error";
}
Expand Down Expand Up @@ -372,7 +367,7 @@

FPDF.Init();

// load document to memory
// load document partially to memory
console.log('Loading data to buffer...');

let wasmBuffer = Module.wasmExports.malloc(fileSize);
Expand All @@ -391,7 +386,7 @@
console.log("Load document state: " + lastError);

// count page
console.log('Couting pages...');
console.log('Counting pages...');

let pages = FPDF.GetPageCount(doc.processor.wasmData.wasm);
console.log('Pages: ' + pages);
Expand Down Expand Up @@ -478,8 +473,8 @@

console.log('Finished');
} catch (error) {
changeButton('Error while process PDF', 'danger');
console.log('Error while process PDF: ' + error.message);
changeButton('Error while processing PDF', 'danger');
console.log('Error while processing PDF: ' + error.message);
}
}

Expand Down
2 changes: 2 additions & 0 deletions modules/wasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,8 @@ def run_task_generate():
f"EXPORTED_FUNCTIONS={complete_functions_list}",
"-s",
'EXPORTED_RUNTIME_METHODS=\'["ccall", "cwrap", "wasmExports"]\'',
"-s",
"EXTRA_EXPORTED_RUNTIME_METHODS=['addFunction']",
"custom.cpp",
lib_file_out,
"-I{0}".format(include_dir),
Expand Down

0 comments on commit 9e03240

Please sign in to comment.