How to Convert PDF or XPS Document to .NET WebForms Presentation?
PDF to PowerPoint presentation conversion
The Essential® Presentation library does not have direct support for converting a PDF document to a PowerPoint presentation. However, you can achieve this using the Essential® Presentation library and the Essential® PdfViewer control.
The conversion process includes the steps below:
- Convert the PDF pages into images using the Essential® PdfViewer control.
- Insert the exported images into the PowerPoint slides using Essential® Presentation library.
Limitation:
Since the converted presentation only contains the images of PDF pages, you cannot select or modify the content in the converted presentation.
The following assemblies are needed to compile the code examples below:
- Syncfusion.Compression.Base.dll
- Syncfusion.Presentation.Base.dll
- Syncfusion.Pdf.Base.dll
- Syncfusion.PdfViewer.Windows.dll
The code example below demonstrates exporting the images from a PDF document using the PDFViewer control.
// Create an instance of PDFViewer control PdfViewerControl pdfViewer1 = new PdfViewerControl(); // Load the PDF document in the viewer pdfViewer1.Load("Sample.Pdf"); // Get the total number of pages in the PDF document int pageCount = pdfViewer1.PageCount; // Export the images from the PDFViewer control System.Drawing.Image[] images = pdfViewer1.ExportAsMetafile(0, (pageCount - 1));
The below code example demonstrates adding the exported images to the Presentation slides using the Essential® Presentation APIs.
// Create an instance of PowerPoint presentation
IPresentation presentation = Presentation.Create();
for (int j = 0; j < images.Length; j++)
{
// Create a memory stream to hold the image
MemoryStream image = new MemoryStream();
// Save the image in the stream
images[j].Save(image, System.Drawing.Imaging.ImageFormat.Jpeg);
// Add a blank slide to the presentation
ISlide slide = presentation.Slides.Add(SlideLayoutType.Blank);
// Set the appropriate orientation for the slide
slide.SlideSize.SlideOrientation = SlideOrientation.Landscape;
// Add the image to the slide
IPicture picture = slide.Pictures.AddPicture(image, 70, 0, 600, 540);
}
// Save the presentation
presentation.Save("PDFtoPresentation.pptx");
XPS to PowerPoint presentation conversion
You can also convert an XPS document to a PowerPoint presentation by first converting the XPS document to a PDF document and then converting the PDF document to a PowerPoint presentation, as explained above.
The below code example demonstrates how to convert the XPS document to PDF document.
// Create an instance of XPSToPdfConverter XPSToPdfConverter converter = new XPSToPdfConverter(); // Convert the XPS document to PDF document PdfDocument document converter.Convert(txtFile.Tag.ToString()); // Save the PDF document document.Save("PdfDocument.pdf"); |
You can find the complete sample here.
Note:
A new version of Essential® Studio® for ASP.NET is available. Versions prior to the release of Essential® Studio® 2014, Volume 2, will now be referred to as a classic versions.The new ASP.NET suite is powered by Essential® Studio® for JavaScript, providing client-side rendering of HTML5-JavaScript controls, offering better performance, and better support for touch interactivity. The new version includes all the features of the old version, so migration is easy.
The Classic controls can be used in existing projects; however, if you are starting a new project, we recommend using the latest version of Essential® Studio® for ASP.NET. Although Syncfusion® will continue to support all Classic Versions, we are happy to assist you in migrating to the newest edition.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls. If you have any queries or require clarifications, please let us know in the comments section below.
You can also contact us through our support forums or feedback portal. We are always happy to assist you!