Convert PDF to PowerPoint in C#
PDF to PPTX
Nutrient .NET SDK (formerly GdPicture.NET) includes the ability to convert any supported file type into PowerPoint.
To save a PDF to a PowerPoint presentation (PPTX), use the SaveAsPPTX method of the GdPictureDocumentConverter class. It uses the following parameter:
Stream, or the overloadFilePath— A stream object where the current document is saved as a PPTX file. This stream object must be initialized before it can be sent into this method, and it should stay open for subsequent use. If the output stream isn’t open for both reading and writing, the method will fail, returning theGdPictureStatus.InvalidParameterstatus, which is the file path where the converted file will be saved. If the specified file already exists, it’ll be overwritten. You have to specify a full file path, including the file extension.
Note that the output stream should be open for both reading and writing and closed/disposed of by the user once processing is complete using the CloseDocument method.
How to convert PDF to PPTX
- Create a
GdPictureDocumentConverterobject. - Load the source document by passing its path to the
LoadFromFilemethod. This method accepts all supported file formats. However, only a PDF file can be converted into a PPTX (other input file formats will returnGdPictureStatus.NotImplemented). If the source document isn’t a PDF, it can be converted to PDF first withGdPictureDocumentConverter.SaveAsPDF. Recommended: Specify the source document format with a member of theDocumentFormatenumeration. - Save the PDF file as a PPTX using
SaveAsPPTX.
The following example converts and saves a PDF document to a PPTX file (it can also be saved as a stream):
using GdPictureDocumentConverter converter = new();GdPictureStatus status = converter.LoadFromFile("input.pdf");if (status != GdPictureStatus.OK){ throw new Exception(status.ToString());}
status = converter.SaveAsPPTX("output.pptx");if (status != GdPictureStatus.OK){ throw new Exception(status.ToString());}
Console.WriteLine("The input document has been converted to a pptx file");Related topics