This is a migrated thread and some comments may be shown as answers.
Export to pdf - font styles not exported?
6 Answers 72 Views
This is a migrated thread and some comments may be shown as answers.
ITsolution
Top achievements
Rank 1
ITsolution asked on 20 Mar 2018, 08:07 AM

Hi! I'm generating an Excel document containing various fonts of "HelveticaNeue". Please see attached images for samples.

When exporting to pdf using PdfFormatProvider, the font styles are changed, e.g. bold style disappears. However, when exporting using Excel interops it works.

Code using interops:

public static void ExcelToPdf( string xlFilePath, string pdfOutputPath )
{
    try
    {
        Excel.Application app = new Excel.Application();
        app.Visible = false;
        app.DisplayAlerts = false;
        Excel.Workbook wkb = app.Workbooks.Open( xlFilePath, ReadOnly: true );
        wkb.ExportAsFixedFormat( Excel.XlFixedFormatType.xlTypePDF, pdfOutputPath );
 
        wkb.Close();
        app.Quit();
    }
    catch ( Exception ex )
    {
        Console.WriteLine( ex.StackTrace );
        throw ex;
    }
}

 

Code using Telerik PdfFormatProvider:

public override void Generate( DimensionTableInput input )
{
    CreateWorkbook();
    CreateWorkbookStyles();
    CreateWorksheets( input );
 
    XlsxFormatProvider xlsxFormatProvider = new XlsxFormatProvider();
 
    PdfFormatProvider pdfFormatProvider = new PdfFormatProvider();
    // this will result in 1 page per sheet
    pdfFormatProvider.ExportSettings = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.Pdf.Export.PdfExportSettings( ExportWhat.EntireWorkbook, true );
 
    string xlsxFileName = $"{input.DocumentTitle}.xlsx";
    string xlsxFullPath = $"{ Path.Combine( input.OutputPath, xlsxFileName )}";
    ExportToFile( xlsxFormatProvider, xlsxFullPath );
 
    string pdfFileName = $"{input.DocumentTitle}.pdf";
    string pdfFullPath = $"{ Path.Combine( input.OutputPath, pdfFileName )}";
    ExportToFile( pdfFormatProvider, pdfFullPath );
    //Helpers.ExcelHelper.ExcelToPdf( xlsxFullPath, pdfFullPath );
}
 
private void ExportToFile( IWorkbookFormatProvider formatProvider, string fileName )
{
    using ( Stream fs = File.OpenWrite( fileName ) )
    {
        formatProvider.Export( _workbook, fs );
    }
}

 

I can share the original Excel and Pdf files if needed.

Thanks in advance,

John

6 Answers, 1 is accepted

Sort by
0
Polya
Telerik team
answered on 22 Mar 2018, 03:52 PM
Hi John,

When the Helvetica Neue font is used we're using Segoe UI as fallback font when exporting the xlsx document to pdf. When this fallback happens, we are not preserving the bold/italic, etc. styles of the text. That is the reason why after export the bold style is lost.
Microsoft Excel also have a fallback font for the Helvetica Neue font, when exporting to pdf, but they are using Cambria, instead of Segoe UI. Also, they are preserving the bold style of the text.
That said, I can only suggest using a different font; one that can also be used when exporting, instead of a fallback font replacement. For example, Arial font.
Hope this is suitable for your scenario.

Regards,
Polya
Progress Telerik

0
ITsolution
Top achievements
Rank 1
answered on 26 Mar 2018, 07:24 AM

Hi Poyla,

Thank you for the reply. Why does the fallback happen at all? Why can't Helvetica Neue be used during the export to pdf? I can't use another font because the marketing department is very specific about the fonts and styles.

 

BR,

John

0
Polya
Telerik team
answered on 28 Mar 2018, 01:11 PM
Hi John,

We've investigated our side and it appears that there is a problem with the "HelveticaNeue.ttf" font. In mode detail, the issue is that this font file does not contain information about encoding for the Windows platform in its data. For that reason, we, as well as Microsoft Excel, fall back to different font when exporting this document.
In order to try and fix the font, I've opened it using FontForge, changed its encoding (Encoding->Reencode-> "ISO 10646-1 (Unicode Full)") and generated a new font (File->Generate Fonts; in the dialog choose "True Type" for the first combo box and then save the new MyHelveticaNeue.ttf file). After that, I've installed the new font (MyHelveticaNeue.ttf), replacing the previously installed font (HelveticaNeue.ttf). As a result, the xlsx file was exported with the "Helvetica Neue" font, instead of "Segoe UI". 
In short, the font file was fixed after passing it through the FontForge program so you could give this approach a try at your side and see whether the issue is resolved.

Regards,
Polya
Progress Telerik

0
Chris
Top achievements
Rank 1
answered on 10 Jun 2020, 01:27 PM

Hi,

I've just come across the same problem, this time generating a PDF.  My fix was to open the OpenType (.otf) font in FontForge, make no changes - leaving Encoding as BMP: "ISO 10646-1 (Unicode BMP)" - and Generating as a TrueType (.ttf) font.  Installing this causes the font to be loaded fine.

Could the issue be related to OpenType, rather than the encoding? 

I realise that FontForge will be re-generating lots of fields but Generating to a OpenType font always fails in my testing, even changing the encoding to 'Full'.

Also, would it be possible for Telerik to default to ISO 10646-1 if it fails to find the required encoding, rather than failing to load the font?

Thanks,

Chris

(UI for WPF 2020 R2)

0
Dimitar
Telerik team
answered on 11 Jun 2020, 06:59 AM

Hello Chris,

Yes, the "otf" format is currently not supported and this is why you need to convert it. We have a feature request for this on our feedback portal. You can track its progress, subscribe to status changes, and add your comment to it here: PdfProcessing: Support for OTF font file format

Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Chris
Top achievements
Rank 1
answered on 11 Jun 2020, 11:55 AM
Ah, that explains it.  Thanks.
Asked by
ITsolution
Top achievements
Rank 1
Answers by
Polya
Telerik team
ITsolution
Top achievements
Rank 1
Chris
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or