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
