Already I have OpenXML Excel file in the format of bytes and have convert Aspose excel stream format , After that I have tried to convert pdf format in the stream format but is not working .
Pls find the following my code and pls suggest right solution.
private MemoryStream GenerateExcleFileToPDFFile(byte[] ExcelContent)
{
MemoryStream msFile = new MemoryStream();
Your code is not right, so you should correct it. Apparently you are trying to save Excel XLSX and PDF files directly to the same (existing) streams which is not possible (you may get “Memory stream is not expandable” error). Moreover, if your workbook has single sheet in it, then the line of code will throw an error as you must have one visible worksheet in the workbook:
workbook.Worksheets[0].IsVisible = false;
I tried the following sample code with a sample Excel file and it works fine:
e.g. Sample code:
byte[] bytes = File.ReadAllBytes("e:\\test2\\Bk_test1.xlsx");
Stream msFile = new MemoryStream(bytes);
Workbook workbook = new Workbook(msFile);
Aspose.Cells.PdfSaveOptions opts = new Aspose.Cells.PdfSaveOptions();
opts.AllColumnsInOnePagePerSheet = true;
opts.OptimizationType = Aspose.Cells.Rendering.PdfOptimizationType.MinimumSize;
MemoryStream msPdf = new MemoryStream();
workbook.Save(msPdf, opts);
msPdf.Seek(0, SeekOrigin.Begin);
byte[] buffer = new byte[msPdf.Length];
buffer = msPdf.ToArray();
File.WriteAllBytes("e:\\test2\\outputPdfFile1.pdf", buffer);
I can only help regarding Aspose.Cells APIs here. Regarding your issue/requirements regarding Aspose.PDF API, please be patient as one our fellow colleagues from Aspose.PDF team will assist you there soon.
1 Like
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.