pdfMake: «Uncaught File [font.tff]» появляется для предотвращения работы функции - PullRequest
0 голосов
/ 04 апреля 2019

Я никогда раньше не использовал pdfMake , и я пытаюсь преобразовать текст в PDF с помощью нажатия кнопки.Я импортирую pdfMake в index.js, поэтому я не уверен, работает ли сам pdfMake или нет.

Я получаю консольную ошибку: Uncaught File 'Roboto-Regular.ttf' not found in virtual file system, и я считаю, что она препятствует запуску функции.Я немного подправил свой файл index.js (см. Прокомментированный код), но все равно ничего.Есть мысли по этому поводу?

index.js:

import 'jquery';
import './SiteAssets/styles/RecruitmentTracking.css';
import 'bootstrap/dist/css/bootstrap.min.css';

import './SiteAssets/scripts/printPDF.js';

import 'jquery-ui-bundle/jquery-ui.min.js';
import 'bootstrap/dist/js/bootstrap.bundle.min.js';

import 'pdfmake/build/pdfmake.min.js';
import 'pdfmake/build/vfs_fonts';

// import pdfFonts from "pdfmake/build/vfs_fonts";
// pdfMake.vfs = pdfFonts.pdfMake.vfs;
// require('imports-loader?this=>window!pdfmake/build/vfs_fonts.js');

console.log('this is index.js');

printPDF.js:

import $ from 'jquery';
// import { pdfMake } from 'pdfmake/build/vfs_fonts';
import pdfMake from 'pdfmake/build/pdfmake.min.js';

console.log('this is printPDF')

function _myFunc() {

    var docDefinition = {
        content: [
            'First paragraph',
            'Another paragraph, this time a little bit longer to make sure, this line will be divided into at least two lines'
        ]
    };

    pdfMake.createPdf(docDefinition).download('test.pdf');
    console.log(docDefinition.content)

}

$("#pdf-trigger").on("click", _myFunc)

console.log(_myFunc)

index.html:

<!-- Button trigger PDF -->
        <button type="button" class="btn btn-secondary" 
          id="pdf-trigger" data-toggle="" 
          data-target="#pdfprint">PDF Print</button>

console.log:

log.js?1afd:24 - [HMR] Waiting for update signal from WDS...

printPDF.js?40b7:5 - this is printPDF

pdfmake.min.js?be6c:8 - Uncaught File 'Roboto-Regular.ttf' not found in virtual file system

client?56b6:85 - [WDS] Hot Module Replacement enabled.

1 Ответ

0 голосов
/ 04 апреля 2019

Обновление:

Согласно пользователю GH Предложение RizkiDPrast , я вошел в vfs_fonts.js и отредактировал верхнюю строку с: this.pdfMake = this.pdfMake || {}; this.pdfMake.vfs = { до: pdfMake = pdfMake || {}; pdfMake.vfs = {

...