Print as pdf in DevExpress RichEdit react

30 views Asked by At

I'm using DevExpress RichEdit in my React app.

Everything is working except for the printing. I have added custom fonts which I can see is working in the editor, but as I understand it I need to use PrintMode.Pdf in order to get the same fonts when printing, at least it is not working right now with PrintMode.Html (default)

I have a fonts.css that looks like this:

@font-face {
  font-family: 'Arimo';
  src: url(/src/fonts/Arimo/Arimo-Regular.ttf),
    url(/src/fonts/Arimo/Arimo-Italic.ttf), url(/src/fonts/Arimo/Arimo-Bold.ttf),
    url(/src/fonts/Arimo/Arimo-BoldItalic.ttf);
  font-style: normal;
  font-weight: normal;
}

I've loaded the fonts using the options.fonts like this:

options.fonts = {
    defaultFolder: 'src/fonts/'
    fonts: [
        {
          name: 'Arimo',
          fontFamily: 'Arimo',
          italicFontUri: 'Arimo/Arimo-Italic.ttf',
          boldFontUri: 'Arimo/Arimo-Bold.ttf',
          boldItalicFontUri: 'Arimo/Arimo-BoldItalic.ttf',
          regularFontUri: 'Arimo/Arimo-Regular.ttf',
        },
     ],
    mappings: {
      defaultFontName: 'Arimo',
};

And in the end I set the print mode like this:

  const printSettings: IPrintingSettings = {
    mode: PrintMode.Pdf,
    closePrintDialogWithHtmlPreview: true,
  };

  options.printing = printSettings;

I have, along with all other imports, imported the pdfkit like this:

import 'devexpress-richedit/dist/pdfkit';

As I said, fonts works fine in editor, but when I try to print I get warnings saying:

OTS parsing error: invalid sfntVersion: 1008813135

And then error in the console saying:

pdfkit.js:52349  Uncaught (in promise) Error: Unknown font format
    at Object.$a35dad4d16c8d1df$export$185802fd694ee1f5 (pdfkit.js:52349:11)
    at PDFFontFactory.open (pdfkit.js:42368:22)
    at PDFDocument.font (pdfkit.js:42420:33)
    at PdfBoxExporter.exportText (box-exporter.js:70:26)
    at PdfBoxExporter.export (box-exporter.js:28:18)
    at PdfLayoutRowExporter.export (row-exporter.js:26:30)
    at PdfLayoutPageAreaExporter.exportColumn (page-area-exporter.js:28:34)
    at page-area-exporter.js:18:51
    at Array.forEach (<anonymous>)
    at PdfLayoutPageAreaExporter.export (page-area-exporter.js:18:26)

Any idea how to fix this?

Edit: I've seen comments like this in many places, so it should be something about how the font is loaded

1008813135 is <!DO in Latin encoding, which is, in all probability, the start of <!DOCTYPE

Update: Problem seems to be related to the import of pdfkit

import 'devexpress-richedit/dist/pdfkit';
0

There are 0 answers