Custom fonts in free text annotations

Shows how to register an arbitrary font with the viewer, and how to use that font in free text annotations.

window.onload = function(){ //DsPdfViewer.LicenseKey = "***key***"; const viewer = new DsPdfViewer("#viewer", { supportApi: getSupportApiSettings(), restoreViewStateOnLoad: false }); initializeViewerLayout(viewer); viewer.options.editorDefaults.freeTextAnnotation = { fontName: 'FantaisieArtistique', borderStyle: { width: 0 } }; viewer.registerFont("BudmoJiggler-Regular", "/document-solutions/javascript-pdf-viewer/demos/product-bundles/assets/fonts/budmo_jiggler.ttf"); viewer.registerFont("FantaisieArtistique", "/document-solutions/javascript-pdf-viewer/demos/product-bundles/assets/fonts/FantaisieArtistique.ttf"); viewer.newDocument().then(async function() { await viewer.addAnnotation(0, { annotationType: 3, // AnnotationTypeCode.FREETEXT borderStyle: { width: 0 }, appearanceColor: "#ff1493", fontName: "BudmoJiggler-Regular", fontSize: 74, contents: "DISCO MUSIC", textAlignment: 1, rect: [0, 680, 612, 782] } ); await viewer.addAnnotation(0, { annotationType: 3, // AnnotationTypeCode.FREETEXT borderStyle: { width: 0 }, appearanceColor: "#00bcd4", fontName: "FantaisieArtistique", fontSize: 46, contents: "Disco Music ignites\ncity nights,\na magic spell\nthat syncs hearts and bodies.\nMirror ball's gleam fuels energy waves, filling air with joy.\nWear dance shoes, embrace light and sound –\ndisco's timeless.", textAlignment: 1, rect: [56, 50, 556, 680] }); viewer.zoom = { mode: 1 }; }); } function initializeViewerLayout(viewer) { viewer.addDefaultPanels(); viewer.addAnnotationEditorPanel(); viewer.toolbarLayout.viewer = { default: ["save", "zoom", "about"], mobile: ["save", "zoom", "about"], fullscreen: ["$fullscreen", "save", "zoom", "about"] }; viewer.toolbarLayout.annotationEditor = { default: ["edit-select", "$split", "edit-free-text", "$split", "edit-undo", "edit-redo", "save"], mobile: ["edit-select", "$split", "edit-free-text", "$split", "edit-undo", "edit-redo", "save"], fullscreen: ["$fullscreen", "edit-select", "$split", "edit-free-text", "$split", "edit-undo", "edit-redo", "save"] }; viewer.applyToolbarLayout(); }
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Custom FreeText font family support</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="./src/styles.css"> <script src="/document-solutions/javascript-pdf-viewer/demos/product-bundles/build/dspdfviewer.js"></script> <script src="/document-solutions/javascript-pdf-viewer/demos/product-bundles/build/wasmSupportApi.js"></script> <script src="/document-solutions/javascript-pdf-viewer/demos/resource/js/init.js"></script> <script src="./src/app.js"></script> </head> <body> <div id="viewer"></div> </body> </html>
#viewer { height: 100%; }