dolanmiu / docx

Easily generate and modify .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.

Home Page:https://docx.js.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using embedded fonts for client side generated files

xong opened this issue · comments

Hi,

I am trying to embed custom fonts.
The docx-file ist generated at the client browser.

Please consider following example:

// create document0
import {Document, Packer} from "docx";

// base64 encoded demo/assets/Pacifico.ttf (Insert by yourself since it would burst this comment.)
const font = atob('...');

const doc = new Document({
    sections: [],
    fonts: [{ name: 'Pacifico', data: font }], // this is the error causing line
});

Packer.toBlob(doc).then((blob) => {
    let a = document.createElement('a');
    a.href = window.URL.createObjectURL(blob);
    a.download = 'example.docx';
    a.click();
});

I get following error message for index.mjs:18833:

Uncaught (in promise) TypeError: bytesToObfuscate.map is not a function

Is there any way to embed custom fonts for client side use?

Your help will be very much appreciated.

Robert