-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to load the custom font in pdfium.wasm #163
Comments
Any solutions to resolve this issue? |
Kindly provide solutions to resolve this issue? |
Is there any update on this? |
@jerbob92, any idea how to fix this issue? |
@bblanchon don't really think this should be asked for in this project, but font loading on the WASM version doesn't work very different from the normal version, the only difference is that in WASM you don't have the system/OS fonts by default, so pdfium isn't able to resolve non-embedded fonts by default. This can be solved in 2 ways:
How you put fonts in there depends on how you run the WASM, assuming this is the normal Emscripten version: Something like this should put a font filedata in
|
Hi @bblanchon, @jerbob92 , As per your suggestion, we have tried providing the font path and published a sample on GitHub at the following location: https://github.com/KameshRajendran/pdfiumissue You can find the published link here : https://kameshrajendran.github.io/pdfiumissue/ Document : example.pdf
We attempted to add custom fonts using the following code snippet, which is also included in the provided link
You can find the complete code snippet here: https://github.com/KameshRajendran/pdfiumissue/blob/main/index.html#L481C13-L490C53 Additionally, we initialized InitLibraryWithConfig as shown below, which is also documented in the link:
You can find the complete code snippet here: https://github.com/KameshRajendran/pdfiumissue/blob/main/index.html#L952 Despite these efforts, we are still unable to display text with custom fonts correctly. Could you please review our code and provide a solution to resolve this issue? Note: This issue is affecting our production site, impacting a significant number of customers. Thank you. |
@KameshRajendran This is not as per my suggestion.
You're also not putting the files itself in the virtual storage. So pdfium has no way to load your font.
I don't get what you're trying to achieve with comments like this. It only makes me not want to help you anymore. |
Hi @jerbob92 , I apologize if my previous comment came across as inappropriate or unhelpful. That was not my intention. I wanted to convey the urgency of the issue affecting our production site and a significant number of customers. I appreciate your assistance and understand the importance of clear and respectful communication. Thank you for your understanding. |
Hi @jerbob92 , We have configured the font file locations for our implementation and made modifications to the samples as described below: The sample are committed in the below repository : Publish Sample link for that: We encountered this issue and have been unable to find a proper solution. Could you please provide your guidance on how to resolve this? |
@Tamilselvan-Durairaj thats a url, not a path, it has to be a path at which the font files are available in the virtual webassembly filesystem. Pdfium does not support loading fonts from a url. Also, the way you are making the config and passing it to pdfium looks pretty shady... The commented out |
@Tamilselvan-Durairaj are you sure you are actually using this project? Your source mentions https://github.com/paulocoutinhox/pdfium-lib |
@bblanchon I have discovered that you can preload files in the compiled wasm. I actually did that and could render the example PDF from this issue fine with the wasm. According to the pdfium source the base fonts are:
We could also make a folder with just these fonts and then compile them into /usr/share/fonts in the wasm. I think the only question would be if this is actually allowed. |
Hi @jerbob92 , Thank you for your support. Following your suggestion, we generated the file, and it has worked perfectly. Once again, We appreciate your valuable guidance in achieving this. Thanks You. |
@Tamilselvan-Durairaj yes, the way to do is with the method that I have given before. Either by putting fonts in one of the predefined font folders using the virtual filesystem, or by giving a custom font folder with If you use |
Hi @jerbob92 , By your guidelines we have modified that, font files can be load from the script file by the given function fetch(scriptdirectory+ "/" + "Fonts/arial.ttf").then(function (response) {
if (response.ok) {
return response.arrayBuffer();
}
}).then(function (value) {
if(value){
var name = "/usr/share/fonts/" + "arial.ttf";
PDFiumModule.FS.createPath("/", "/usr/share/fonts/", true, true);
PDFiumModule.FS.createDataFile(name, null, new Int8Array(value), true, true, true);
}
}); Now we can able to load the font files to pdfium from the script file. It does not increase wasm file size. |
We retrieve the PDF image using pdfium.wasm on the client-side. However, in this scenario, custom fonts such as Turkish characters are not visible in the images. Please provide a solution to ensure that the correct fonts are retrieved from the pdfium.wasm file.
Please provide solution to set the custom font and get the correct image .
The text was updated successfully, but these errors were encountered: