Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Wed Apr 23, 2014 7:42 am

I'm trying to convert Excel document to PDF. And when I use file, it works fine:
Code: Select all
var workbook = new Workbook();
workbook.LoadFromFile("file.xlsx");
workbook.SaveToFile("file2.pdf", FileFormat.PDF);
file2.pdf - normal pdf file.

But when I try to save into stream, I get Excel file in this stream:
Code: Select all
var workbook = new Workbook();
workbook.LoadFromFile("file.xlsx");
using (var stream = new MemoryStream())
{
    workbook.SaveToStream(stream, FileFormat.PDF);
    stream.Seek(0, SeekOrigin.Begin);
    File.WriteAllBytes("file3.pdf", stream.ToArray());
}
file3.pdf - Excel file

Why it's happening? How can I get PDF file from workbook in my stream?

Thank You

user001
 
Posts: 5
Joined: Wed Apr 09, 2014 12:54 pm

Wed Apr 23, 2014 8:09 am

Hello,

Thanks for your inquiry.
I used Spire.XLS Pack Hotfix Version:7.3.12 to test your code of saving into stream, but it worked fine in my side, I got file3.pdf .
Would you please try the version?

You could also try the below solution.
Code: Select all
  Workbook wb = new Workbook();
            wb.LoadFromFile(@"file.xlsx");
            using (var stream = new MemoryStream())
            {
                wb.SaveToStream(stream, FileFormat.PDF);
                stream.Position = 0;
                File.WriteAllBytes("file3.pdf", stream.ToArray());
            }


Best wishes,
Amy
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Wed Apr 23, 2014 9:34 am

I tested with proposed version and it works fine...
But this issue still present in free version. I tried with Version:7.3.14.

Are you planing to fix it?

Thanks

user001
 
Posts: 5
Joined: Wed Apr 09, 2014 12:54 pm

Thu Apr 24, 2014 7:47 am

Hello,

Sorry for the inconvenience caused by the issue in Free version.
I have posted the issue to our dev team. We will inform you when it is fixed.
Feel free to contact us if you have any problems.

Best wishes,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.XLS