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();
}