Spire.Presentation is a professional PowerPoint® compatible library that enables developers to create, read, write, modify, convert and Print PowerPoint documents. Get free and professional technical support for Spire.Presentation for .NET, Java, Android, C++, Python.

Thu Jul 02, 2020 4:18 pm

Hi,

Is it possible to convert a pptx file to pdf? Any time I try to load my pptx file (coming from SharePoint) as a stream, I get an unsupported file format exception.

here is my code
1 Presentation pres = new Presentation();
2 pres.LoadFromStream(pptxFileStream, Spire.Presentation.FileFormat.PPT);
3 var newFileStream = new MemoryStream();
4 pres.SaveToFile(newFileStream, Spire.Presentation.FileFormat.PDF);

The error occurs on line 2.

cbcsDocMerger
 
Posts: 3
Joined: Thu Jul 02, 2020 3:05 pm

Fri Jul 03, 2020 11:06 am

Hi,

Thanks for your inquiry.
Please make sure that the stream you are loading is in .ppt format. If you use the LoadFromStream method to load the data whose format can't be loaded by our product, you will get an unsupported file format exception. I suggest you use below code to write the streams to a PPT file, if the generated PPT file has errors or can’t be opened normally, I’m afraid that your issue is related to your data but not our product.
Code: Select all
byte[] bytes = new byte[pptxFileStream.Length];
pptxFileStream.Read(bytes, 0, bytes.Length);
pptxFileStream.Seek(0, SeekOrigin.Begin);
FileStream fs = new FileStream("PPT file", FileMode.Create);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(bytes);
bw.Close();
fs.Close();


If there is no problem with the generated PPT, please provide your input file to help us further investigate your issue. You could send it to us via email (support@e-iceblue.com).

Best wishes,
Gina
E-iceblue support team
User avatar

Gina.li
 
Posts: 4
Joined: Wed Jul 01, 2020 1:46 am

Tue Jul 07, 2020 3:30 pm

So this doesn't exactly answer my question...I am asking, does your product support converting **pptx** files to PDF? The clients will be uploading pptx files, and asking them to convert to ppt first could be an issue. I have tried out the suggested code, and I still get the "Unknown File Format" issue. It doesn't seem like anything in the code you posted would do an intermediate conversion from pptx to ppt.

Does this make sense? Thanks

cbcsDocMerger
 
Posts: 3
Joined: Thu Jul 02, 2020 3:05 pm

Wed Jul 08, 2020 2:07 am

Hello,

Thanks for your response.
Sorry our reply may have caused you some misunderstanding. Our LoadFromStream method is mainly used to load the PPT/PPTX file, if you use it to load the file whose format can't be loaded by our product (such as a PDF file), the application will throw the error "Unknown file format".
Our Spire.Presentation supports converting PPTX files to PDF. To help us further investigate this issue, please provide us with your input file. You could attach it here or send it to us via email (support@e-iceblue.com). Thanks in advance.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Wed Jul 08, 2020 12:48 pm

Hi there,

I am trying to convert the following simple pptx file (attached) to a PDF file. Preferably, I am trying to convert it without having to save to the local file system, i.e. only by handling in memory streams, however I suppose saving as a local file is okay.

I have tried loading from stream as Spire.Presentation.FileFormat.PPT, Auto, and some of the pptx values.

cbcsDocMerger
 
Posts: 3
Joined: Thu Jul 02, 2020 3:05 pm

Thu Jul 09, 2020 1:58 am

Hello,

Thanks for your sharing.
I used the latest Spire.Presentation Pack Hotfix Version:5.6.1 to test the following code but did not encounter any issue. If you are using an older version, please download the latest version and try again. If the issue still occurs, to help us investigate further, please provide your environment information, such as OS information (E.g. Windows 7, 64 bit) and region setting (E.g. China, Chinese). Thanks in advance.
Code: Select all
            FileStream fs = new FileStream("AndrewTestPPT.pptx", FileMode.Open);
            Presentation ppt = new Presentation();

            //These all work well
            //ppt.LoadFromStream(fs, FileFormat.PPT);
            //ppt.LoadFromStream(fs, FileFormat.Pptx2013);
            ppt.LoadFromStream(fs, FileFormat.Auto);

            var newFileStream = new MemoryStream();
            ppt.SaveToFile(newFileStream, FileFormat.PDF);

            //byte[] fileBytes = newFileStream.ToArray();
            //FileStream fileStream = new FileStream("Result.pdf", FileMode.Create, FileAccess.ReadWrite);
            //fileStream.Write(fileBytes, 0, fileBytes.Length);


Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Fri Jul 24, 2020 9:50 am

Hello,

Greetings from E-iceblue!
How is your issue now? Could you please give us some feedback at your convenience?
Thanks in advance.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.Presentation