I get this error trying to export my workbook to PDF
Server Error in '/' Application.
--------------------------------------------------------------------------------
Culture is not supported.
Parameter name: culture
66569 (0x10409) is an invalid culture identifier.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Globalization.CultureNotFoundException: Culture is not supported.
Parameter name: culture
66569 (0x10409) is an invalid culture identifier.
Source Error:
Line 83: settings.EmbedFonts = true;
Line 84: settings.TemplateDocument = pdfDocument;
Line 85: pdfDocument = pdfConverter.Convert(settings);
Line 86:
Line 87: byte[] fileData;
Source File: C:\Projects\AVM Solutions\Common\Helpers\PDFConverter.cs Line: 85
Stack Trace:
[CultureNotFoundException: Culture is not supported.
Parameter name: culture
66569 (0x10409) is an invalid culture identifier.]
System.Globalization.CultureData.GetCultureData(Int32 culture, Boolean bUseUserOverride) +12562108
System.Globalization.CultureInfo.InitializeFromCultureId(Int32 culture, Boolean useUserOverride) +59
Spire.Xls.Core.FormatParser.FormatTokens.CultureToken.get_Culture() +37
Spire.Xls.Core.FormatParser.FormatSection.a(Double A_0, Boolean A_1, Int32 A_2, Int32 A_3, Boolean A_4, Boolean A_5, Boolean A_6) +638
Spire.Xls.Core.FormatParser.FormatSection.ApplyFormat(Double value, Boolean bShowReservedSymbols) +660
Spire.Xls.Core.Spreadsheet.XlsRange.get_NumberText() +940
Spire.Xls.Converter.PdfConverter.a(XlsExtendedFormat A_0, XlsRange A_1, RectangleF A_2, RectangleF A_3, PdfCanvas A_4) +775
Spire.Xls.Converter.PdfConverter.b(Worksheet A_0, MergedRegion A_1, Int32 A_2, Int32 A_3, PdfCanvas A_4, ItemSizeHelper A_5, ItemSizeHelper A_6) +594
Spire.Xls.Converter.PdfConverter.a(Worksheet A_0, Int32 A_1, Int32 A_2, Int32 A_3, Int32 A_4, PdfCanvas A_5, ItemSizeHelper A_6, ItemSizeHelper A_7, b A_8) +229
Spire.Xls.Converter.PdfConverter.a(Worksheet A_0, Int32 A_1, Int32 A_2, Int32 A_3, Int32 A_4, CellRange A_5, Single A_6, Single A_7, ItemSizeHelper A_8, ItemSizeHelper A_9) +916
Spire.Xls.Converter.PdfConverter.a(Worksheet A_0, CellRange A_1) +2894
Spire.Xls.Converter.PdfConverter.Convert() +823
AVM.AvmSolutions.Common.Helpers.PDFConverter.ExcelToPdf(Stream stream) in C:\Projects\AVM Solutions\Common\Helpers\PDFConverter.cs:85
AVM.AvmSolutions.Common.Helpers.PDFConverter.DocumentToPdf(ModuleItem moduleItem) in C:\Projects\AVM Solutions\Common\Helpers\PDFConverter.cs:36
AVM.AvmSolutions.Web.Portal.Controls.GroupModules.ModulesGrid_ItemCommand(Object sender, GridCommandEventArgs e) in C:\Projects\AVM Solutions\Web.Portal\Controls\GroupModules.ascx.cs:143
Telerik.Web.UI.RadGrid.OnBubbleEvent(Object source, EventArgs e) +64
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +52
Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e) +102
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +52
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3707
--------------------------------------------------------------------------------------------
this is the code I'm using:
private static byte[] ExcelToPdf(Stream stream)
{
var workbook = new Workbook();
workbook.LoadFromStream(stream, ExcelVersion.Version97to2003);
var pdfConverter = new PdfConverter(workbook);
var pdfDocument = new PdfDocument();
var settings = new PdfConverterSettings();
settings.EmbedFonts = true;
settings.TemplateDocument = pdfDocument;
pdfDocument = pdfConverter.Convert(settings);
byte[] fileData;
using (var pdfStream = new MemoryStream())
{
pdfDocument.SaveToStream(pdfStream);
pdfStream.Position = 0;
var binaryReader = new BinaryReader(pdfStream);
fileData = binaryReader.ReadBytes((int)pdfStream.Length);
}
return fileData;
}