paulocoutinhox / pdfium-lib

PDFium - Project to compile PDFium library to multiple platforms.

Home Page:https://pdfviewer.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add an alternative wasm in release use the the `MODULARIZE` option when build?

Priestch opened this issue · comments

I found it's not easy to custom the path of pdfium.wasm, although Module["locateFile"] make that possible, but Module must live in the global scope, it take some time to make it work when using common bundle tools.
I suggest to add an alternative wasm in release use the the MODULARIZE option when build, it will be easier when integrate.
Related doc.

Hi,

I think that @CetinSert can help you better because he is expert in WASM.

Thanks.

@Priestch – why do you need a custom path?

Is something hard-coded in the current build? I was able to load it just fine with relative URLs from any domain / directory.

Do you want to hide the name pdfium.wasm from showing up in the DevTools / Network tab o_O? If yes, why!?

@CetinSert I want to custom onRuntimeInitialized and locateFile.
Custom locateFile to hide details between different projects, but until now I realize that seems impossible, and custom onRuntimeInitialized to make sure the wasm file is ready when try to process pdf document.

@paulo-coutinho It depends on the global Module variable.

it take some time to make it work when using common bundle tools.

when use the MODULARIZE, it will use a function to create the Module object, and can be customed like this.

const Module = createModule({onRuntimeInitialized() {...}})

I think MODULARIZE should be the default option, As @Priestch specified, it can prevent the global variable pollution, it will be problematic if one page needs to use multiple WASM library, like if you build a web page that can open different kinds of files, like pdf, zip and so on, it's highly possible that you need to load a lot of wasm library. Without relying on the global variable Module would be much helpful. Also it would be useful for lazy loading WASM files. Like

import { createPdifumModule } from 'pdfium.js'
import { createEpubModule } from 'epub.js',

function whenUserSelectFile() {
   if (isEpub) {
   // It will be more helpful if user want to support caching wasm file, for example, they can save 
  // wasmBinary into indexeddb, next time they can use it as fallback if network request is down
   // then they can do
   // const wasmBinary = await loadPdifumWasmBinary();
   // const module = await createPdfiumModule({wasmBinaray});
    const module = await createPdifumModule();
   } else if (isPdf) {
    const module = await createPdifumModule();
   }
}

input.addEventListener('input', whenUserSelectFile);

Hi,

I will refactor all and remake a lot of things in this project. And when i start it, i will change this too.

Im only finishing another open source project that is a requirement for me.

Stay tuned here and feel free to donate to help project development.

Thanks.

Hi,

All problems was fixed in new release.

You can check here:
https://github.com/paulocoutinhox/pdfium-lib/releases/tag/5407

The demo is here:
https://pdfviewer.github.io/

I will see this problem to change to module.

Feel free to donate to help project development.

Thanks.

This was done in latest PR.

After it built with success, i will merge.

Hi,

Everything was done on latest release.

Feel free to donate to help project development.

Thanks.