docx icon indicating copy to clipboard operation
docx copied to clipboard

Using embedded fonts for client side generated files

Open xong opened this issue 1 year ago • 0 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

xong avatar Apr 04 '24 10:04 xong