Skip to content
ComPDF

Import Fonts

Sometimes the document dones't embed a font, in this case, you can import a custom font.

Create the fonts.json

You should create the fonts.json, which should contain the fonts you want to import.

json
// fonts.json
[
  {
    "family": "DroidSansFallbackFull",
    "filePath": "DroidSansFallbackFull.ttf"
  }
]

The fonts to be imported need to be placed in a folder such as /webviewer/lib/, and the created fonts.json file above also needs to be placed in this folder. Then you can init your webviewer and import the fonts in your project.

javascript
// Import the JS file of ComPDFKit Demo.
import ComPDFKitViewer from "@compdfkit_pdf_sdk/webviewer";

const viewer = document.getElementById('webviewer');
WebViewer.init({
  path: '/',
  pdfUrl: './example/developer_guide_web.pdf',
  license: '<Input your license here>',
  webFontURL: '/webviewer/lib/',
}, viewer).then((instance) => {
  const docViewer = instance.docViewer

  docViewer.addEvent('documentloaded', async () => {
    console.log('document loaded')
  })
})