Character not supported error - ArgumentOutOfRangeException

Hello guys,

So I ran into an issue where when i try to export a grid using PDF a special char will make the export fail and give the following error,
Uncaught (in promise) Error: ArgumentOutOfRangeException:index, The character is not supported by the font.
    at t.items (_shared.js:7212)
    at t.getCharWidthInternal (_shared.js:7212)
    at t.getLineWidth (_shared.js:7212)
    at e.getLineWidth (_shared.js:7212)
    at e.layoutLine (_shared.js:7212)
    at e.doLayout (_shared.js:7212)
    at e.layout (_shared.js:7212)
    at e.measureWidth (_shared.js:7212)
    at e.get [as width] (_shared.js:7212)
    at t.measureColumnsWidth (_shared.js:7212)

Excel export however works fine.
I Am using ej2 js version of the export which is failing, with the PDFExportOptions being set as, 
{
        pageOrientation: 'Landscape',
        pageSize: 'A3',
        contentType: "Text"
    }

is there perhaps a option that I am missing currently? For the data I am trying to export, I dont control the data that comes back, so any form of special chars can be added to a field.

Kind regards
Johandre

9 Replies

MS Mani Sankar Durai Syncfusion Team August 13, 2018 11:24 AM UTC

Hi Johandre, 

Thanks for contacting Syncfusion support. 

We have validated your query and the provided information. We have already considered “Support for true type font in PDF library” as a feature and logged the report for the same. The feature will be available in any of our upcoming release. 

Regards,
Manisankar Durai. 



JD Johandre Duminy August 13, 2018 12:25 PM UTC

Hello Manisankar,

Thank you for the response, do you know perhaps when the upcoming release would be?

Kind regards
Johandre Duminy


MS Mani Sankar Durai Syncfusion Team August 14, 2018 06:41 AM UTC

Hi Johandre, 

The featureSupport for true type font in PDF library’ will be available in our volume 3, 2018 release which is expected to be rolled out at the end of September 2018. 

Please be patience until then. 

Regards, 
Manisankar Durai. 



BN Bill Naples July 14, 2019 05:23 PM UTC

I see from this test how to use this PdfTrueTypeFont:

But I don't want to have to embed this crazy long base64 encoded string for the font. Are there default fonts I can choose from or import? Do you have an example? Ideally I'd just like to specify "Arial" or something like that, and it should just be able to generate a pdf with non-ascii characters.


SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team July 15, 2019 11:21 AM UTC

Hi Bill, 

In Essential JavaScript 2 Grid pdf export, we use “Helvetica” font in the exported document. Also We have some predefined font in our library and You can change the default font by using “pdfExportProperties.theme” property. If you want to use the fonts other than the available fonts, you need to use the base64 string of that font which is the default behavior of EJ2 Grid Pdf Export. Please refer to the below available fonts and documentation link for more information. 

  1. Helvetica
  2. TimesRoman
  3. Courier
  4. Symbol
  5. ZapfDingbats


Regards, 
Seeni Sakthi Kumar S. 



BN Bill Naples July 15, 2019 11:47 AM UTC

Hi Seeni,

Are you saying I have to embed a long base64 font file string in order to export a pdf with unicode characters? It's not that I want to configure a custom font. I just want support for non-ascii characters that is common in non-English countries.


BN Bill Naples July 16, 2019 10:28 AM UTC

Hi Seeni, Do you have any more information? Can you please provide the simplest example to configure the pdf font so international characters can be exported? I don't need custom font per se. My understanding is that many "standard" fonts support these characters already.


BN Bill Naples July 16, 2019 12:01 PM UTC

I figured out how to load the ttf. For reference, the code looks like this:

```
import axios from 'axios'
import { PdfTrueTypeFont } from '@syncfusion/ej2-pdf-export'

// https://www.syncfusion.com/forums/139194/character-not-supported-error-argumentoutofrangeexception
function getBase64 (url) {
return axios
.get(url, {
responseType: 'arraybuffer'
})
.then(response => btoa(String.fromCharCode(...new Uint8Array(response.data))))
}

getPdfExportProperties () {
if (_pdfExportProperties) return Promise.resolve(_pdfExportProperties)
return getBase64('/font/OpenSans-Regular.ttf')
.then(fontString => {
_pdfExportProperties = {
theme: {
header: { font: new PdfTrueTypeFont(fontString, 12) },
caption: { font: new PdfTrueTypeFont(fontString, 10) },
record: { font: new PdfTrueTypeFont(fontString, 9) }
}
}
return _pdfExportProperties
})
}
```





SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team July 16, 2019 01:00 PM UTC

Hi Bill, 

Thanks for the update. 

We are happy to hear that your requirement has been achieved and you are good to go. 

Regards,  
Seeni Sakthi Kumar S. 


Loader.
Up arrow icon