0

Good day, I am developing a feature which download excel based on the pdf layout set using iText. A byte[] data is generated from the iText which in this form "����hp�" if I Console.WriteLine it in LineEncoding.UTF8.GetString.

I want to load the byte[] data in pdf form, into Stream then convert it into excel using Spire library. So the user can download the excel with pdf layout without download and convert the pdf. Thank you for helping me!

//byte[] data which contained pdf layout using iText
byte[] pdfData = _PDFService.CreatePDF(a, b);
//Create Stream
MemoryStream pdfStream = new MemoryStream();
//Write Stream with byte[] data
pdfStream.Write(pdfData, 0, pdfData.Length);
pdfStream.Position = 0;

//Create a PdfDocument instance
PdfDocument document = new PdfDocument();
//Load from Stream
document.LoadFromStream(pdfStream);
//Save to Excel
document.SaveToFile(@"C:\Users\...\output.xlsx", FileFormat.XLSX);

Console output:
Unhandled exception rendering component: The type initializer for 'spr⥪' threw an exception. System.TypeInitializationException: The type initializer for 'spr⥪' threw an exception.

stuartd
  • 70,509
  • 14
  • 132
  • 163
  • `The type initializer for 'spr⥪' threw an exception` - was there an inner exception which detailed what the actual issue was? – stuartd Mar 30 '23 at 02:35
  • "System.PlatformNotSupportedException: System.Drawing.Common is not supported on this platform." Seems like the byte[]data cant write in pdf form, but previously I can use Convert.ToBase64String(data) to render in a pdf form and download it. – Koh Jia Sheng Mar 30 '23 at 02:41

1 Answers1

0

"System.PlatformNotSupportedException: System.Drawing.Common is not supported on this platform."

Are you using Spire.PDF to convert PDF to Excel on a non-windows platform? If so, you can remove the dll of Spire.PDF from your program, then search and install the Spire.Office for.NETStandard package via Nuget (you can also type the command "Install-Package Spire.Officefor.NETStandard" in the Package Manager Console to install it), this package contains the features of Spire.PDF and it does not rely on System.Drawing.Common.

Dheeraj Malik
  • 703
  • 1
  • 4
  • 8