Giter Club home page Giter Club logo

Comments (12)

jerbob92 avatar jerbob92 commented on August 22, 2024 2

That is not possible right now.
It might be possible when fpdf_sysfontinfo.h is implemented, but I do not know for sure, it might be that pdfium will always load the embedded font when it's available.

I would have to look into it, will let you know!

from go-pdfium.

jerbob92 avatar jerbob92 commented on August 22, 2024 1

WASM uses a linux-like build, so the font folders the same as the Linux build:

  • /usr/share/fonts
  • /usr/share/X11/fonts/Type1
  • /usr/share/X11/fonts/TTF
  • /usr/local/share/fonts

If you provide your own FSConfig in the initialization, make sure that the font folder is mounted into the available folders for pdfium.

from go-pdfium.

jerbob92 avatar jerbob92 commented on August 22, 2024

pdfium looks in a few different folders for fonts (depending on your OS):
https://pdfium.googlesource.com/pdfium/+/refs/heads/main/core/fxge/linux/fx_linux_impl.cpp#169
https://pdfium.googlesource.com/pdfium/+/refs/heads/main/core/fxge/apple/fx_apple_platform.cpp#148

You can also give extra paths in go-pdfium to look for fonts when initializing the library:
https://github.com/klippa-app/go-pdfium/blob/main/pdfium.go#L10

Generally it should be enough to have a default set of fonts, but I did notice it might help to install msttcorefonts to get some Windows fonts because some PDF renderers do not embed fonts and expect the Windows fonts to always be available.

from go-pdfium.

nonchan7720 avatar nonchan7720 commented on August 22, 2024

@jerbob92
Thank you for your reply.
I am using Wasm, is it the same?

from go-pdfium.

nonchan7720 avatar nonchan7720 commented on August 22, 2024

Thank you very much!

How should alternative fonts be specified? 🙇‍♂️

from go-pdfium.

jerbob92 avatar jerbob92 commented on August 22, 2024

pdfium doesn't expose an easy method to control that, the only way to do it is by implementing fpdf_sysfontinfo.h, which is one of the few things that this library did not implement (yet), due to the complicated nature of those methods. Those methods basically allow you to build your own font mapper.

I might look into adding support for this later, but generally PDF's should not use fonts that aren't widely installed on machines as it will cause render issues, that's why PDF's embed fonts if they are not installed by default on machines.

If a font isn't embedded, it first tries to search in the specified folders for the requested font. Afaik pdfium tries to fall back to Arial when it can't find the requested font.

Could you try to check which font the PDF is trying to load?

from go-pdfium.

nonchan7720 avatar nonchan7720 commented on August 22, 2024

I have to process PDFs that are given to me by another user, and in some cases the PDFs use commercial fonts, and I would like to use an alternative font.

from go-pdfium.

jerbob92 avatar jerbob92 commented on August 22, 2024

@nonchan7720 so you mean that these PDF's have the font embedded but you want to replace them anyway?

from go-pdfium.

nonchan7720 avatar nonchan7720 commented on August 22, 2024

Yes, it is.

from go-pdfium.

nonchan7720 avatar nonchan7720 commented on August 22, 2024

I look forward to the day when we can get good information!

from go-pdfium.

jerbob92 avatar jerbob92 commented on August 22, 2024

I did some tests and got a nice starting point (in the CGO implementation) with the implementation of fpdf_sysfontinfo.h. However, I have sad news for you. Pdfium only calls the custom font mapper when it renders a font that is not embedded inside the PDF.

I will probably complete the implementation (for WASM too) while I'm at it, but it won't be useful for you I'm afraid.
You could try to ask here for pdfium to add a feature to also use the custom font mapper for embedded fonts.

from go-pdfium.

jerbob92 avatar jerbob92 commented on August 22, 2024

I will close this issue for now.

from go-pdfium.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.