~ireas/public-inbox

2 2

Wasm and Genpdf

Details
Message ID
<20210722004743.05DD49C38B@mail.libredu.org>
DKIM signature
pass
Download raw message
Hi. Thank you for your all works with genpdf. It looks great.

My problem is, i am using creating pdf for my wasm project. So, there is no filesystem. I can download the ttf's files from my server but i don't know how to use it with from_files() method. Is there any way to use fonts without filesystem?

Thank you.
Details
Message ID
<20210722074208.GA1168@ireas.org>
In-Reply-To
<20210722004743.05DD49C38B@mail.libredu.org> (view parent)
DKIM signature
pass
Download raw message
On 2021-07-22 03:47:43, eribol@libredu.org wrote:
> My problem is, i am using creating pdf for my wasm project. So, there
> is no filesystem. I can download the ttf's files from my server but i
> don't know how to use it with from_files() method. Is there any way to
> use fonts without filesystem?

Yes.  The fonts::from_files function is just a shorthand for calling
FontData::load for all four font styles.  Instead of FontData::load
(which takes a path), you can use FontData::new (which takes the raw
font data).  So this gives you two options:  Either you include the font
data in your binary using include_bytes!, or you download the font from
the network.  You can then manually construct a FontFamily instance
using FontData::new.

wasm-card [0] is a project that already uses genpdf from WASM.  It uses
the include_bytes! approach [1].

[0] https://codeberg.org/jelemux/wasm-card
[1] https://codeberg.org/jelemux/wasm-card/src/branch/main/src/model/vcard.rs#L301

Please let me know if anything is unclear or does not work properly.

Best,
Robin
Details
Message ID
<20210722221143.8CDE19C38B@mail.libredu.org>
In-Reply-To
<20210722074208.GA1168@ireas.org> (view parent)
DKIM signature
pass
Download raw message
Robin Krahl <robin.krahl@ireas.org> wrote:

> On 2021-07-22 03:47:43, eribol@libredu.org wrote:
> > My problem is, i am using creating pdf for my wasm project. So, there
> > is no filesystem. I can download the ttf's files from my server but i
> > don't know how to use it with from_files() method. Is there any way to
> > use fonts without filesystem?
> 
> Yes.  The fonts::from_files function is just a shorthand for calling
> FontData::load for all four font styles.  Instead of FontData::load
> (which takes a path), you can use FontData::new (which takes the raw
> font data).  So this gives you two options:  Either you include the font
> data in your binary using include_bytes!, or you download the font from
> the network.  You can then manually construct a FontFamily instance
> using FontData::new.
> 
> wasm-card [0] is a project that already uses genpdf from WASM.  It uses
> the include_bytes! approach [1].
> 
> [0] https://codeberg.org/jelemux/wasm-card
> [1] https://codeberg.org/jelemux/wasm-card/src/branch/main/src/model/vcard.rs#L301
> 
> Please let me know if anything is unclear or does not work properly.
> 
> Best,
> Robin
Thank you so much. It worked for now. Only thing i need, open pdf on Blob url whch its not about genpdf. Thank you again.
Reply to thread Export thread (mbox)