GithubHelp home page GithubHelp logo

Comments (5)

cajuncoding avatar cajuncoding commented on June 16, 2024

I'm guessing that you mean to ask about how to use custom fonts in your XslFO Markup so they show up in the PDF; because embedding them in the PDF is a different topic and all fonts used are embedded by default in the output PDF as described here in the documentation.

Per the Apache FOP documentation you can register fonts (custom fonts) with Apache FOP for reference within your XslFO markup:
https://xmlgraphics.apache.org/fop/2.1/fonts.html#register

In addition there are more details here where they provide all configuration elements, whereby you can set the base path via font-base param for all Fonts paths to be relative to when loading/registering.

So with the configuration of those elements then you can register any font you like with ApachFOP when it loads.

Specifically in ApacheFOP.Serverless, the configuration xml file is loaded automatically from a resource file that is deployed with the Java Azure Function via the resources folder; you'll find it in the project path: /src/main/resources/apache-fop-config.xml

This file is loaded by the framework automatically and provided to ApacheFOP upon initialization.

So, Ideally we could drop in custom Font files into the resource folder as src/main/resource/{fontfile.ttf}, and then configure that path correctly in the apache-fop-config.xml file so it is found by ApacheFOP per the documentation.

_EDIT: The resources are deployed embedded in the JAR file, not to the filesystem, and after fiddling with Maven I realized that build time copying won't work... but runtime resolving might . . . _

Thus far I've not tried/validated this myself, so let me know how you get along with this . . . eventually when I get some time (may not be this week) I can try to test/validate with an example -- but the crux will just be determining what the full file path to font files would be after being deployed to Azure Functions and/or copying them out somewhere?

Good Luck!

from apachefop.serverless.

cajuncoding avatar cajuncoding commented on June 16, 2024

@MichaelYabko

Ok, so getting the custom fonts to work definitely wasn't as straightforward as I hoped, but with a little more help now it is 🚀

I haven't had a need for non-standard fonts yet, but it's something I wanted to get working anyway as it's definitely a critical feature.

Initially I thought that some form of the auto-detect would work -- and it did, but with the risk of access permission issues, etc. once deployed to the Azure Functions service I ended up identifying a more robust approach . . . by providing ApacheFOP with a custom ResourceResolver that now dynamically resolves requests from Java resources that are easily deployed within the JAR file.

This makes adding fonts, configuring them, and deploying the package a breeze 🙌

I've pushed the latest v1.2 (with readme updates)... which now supports a much easier way to include your TTF/OTF/etc. custom font files, and easily register them in configuration.

More details are now in the readme here: https://github.com/cajuncoding/ApacheFOP.Serverless#custom-fonts-via-resource-files

It's definitely working, here's a sample from my personal deployment in Azure via Postman:
image

from apachefop.serverless.

MichaelYabko avatar MichaelYabko commented on June 16, 2024

This is really cool @cajuncoding. One other thing that we also found works was to include the fonts in the config as a url. Then we setup an azure storage link for each of the fonts. Gonna try this out shortly.

Thanks 👍

from apachefop.serverless.

MichaelYabko avatar MichaelYabko commented on June 16, 2024

works great :-)

from apachefop.serverless.

cajuncoding avatar cajuncoding commented on June 16, 2024

Yes, that's correct, I can now confirm that if you have font file directly downloadable anonymously by url then the original/default resource resolver will work. I've now learned that It is the same resolver used for all external resources when Apache FOP processes it's configuration as well as when rendering the markup (e.g. images)!

Though it may not be impactful there could definitely be a performance impact with that approach, that would be minimized by embedding them with the JAR. 🚀

from apachefop.serverless.

Related Issues (7)

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.