テキストに独自のフォントを設定する

window.onload = function(){ //DsPdfViewer.LicenseKey = "***key***"; const viewer = new DsPdfViewer("#viewer", { workerSrc: "/diodocs/pdfviewer/demos/product-bundles/build/dspdfviewer.worker.js", supportApi: getSupportApiSettings(), restoreViewStateOnLoad: false, language: "ja" }); 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(); viewer.options.editorDefaults.freeTextAnnotation = { fontName: 'FantaisieArtistique', borderStyle: { width: 0 } }; viewer.options.editorDefaults.fontNames = [ { name: 'ディスコ', value: 'BudmoJiggler-Regular' }, { name: 'ファンタジー', value: 'FantaisieArtistique' } ]; 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], convertToContent: true } ); 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], convertToContent: true }); viewer.zoom = { mode: 1 }; }); }
<!DOCTYPE html> <html lang="ja"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>テキストへの独自フォント設定</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="./src/styles.css"> <script src="/diodocs/pdfviewer/demos/product-bundles/build/dspdfviewer.js"></script> <script src="/diodocs/pdfviewer/demos/product-bundles/build/wasmSupportApi.js"></script> <script src="/diodocs/pdfviewer/demos/resource/js/init.js"></script> <script src="./src/app.js"></script> <link rel="preload" href="/diodocs/pdfviewer/demos/product-bundles/assets/fonts/budmo_jiggler.ttf" as="font" type="truetype" crossorigin> <link rel="preload" href="/diodocs/pdfviewer/demos/product-bundles/assets/fonts/FantaisieArtistique.ttf" as="font" type="truetype" crossorigin> <style> @font-face { font-family: BudmoJiggler-Regular; src: url(/diodocs/pdfviewer/demos/product-bundles/assets/fonts/budmo_jiggler.ttf) format('truetype'); } @font-face { font-family: FantaisieArtistique; src: url(/diodocs/pdfviewer/demos/product-bundles/assets/fonts/FantaisieArtistique.ttf) format('truetype'); } </style> </head> <body> <div id="viewer"></div> </body> </html>
#viewer { height: 100%; }