Convert Powerpoint Presentation into Image, HTML and PDF

| May 29, 2010 | 3 Comments

Sometimes we need to save our Office Presentation file(PPT or PPTX) into other format through programming. We will learn here how to convert powerpoint presentation into Image, HTML & PDF. So here is the solution for the same.

Convert powerpoint into image, html and pdf

Convert powerpoint into image, html and pdf

Pre-requisites for the Program:

(1) Microsoft Office Powerpoint software installed in system.
(2) .NET Framework 2.0 or more installed.
(3) Office 2007 add-in installed for converting documents into PDF or XPS. You can get one from here.
(4) Add Reference to Microsoft.Office.Interop.PowerPoint.dll version 12.0 from VS 2005 or greater.

Concepts Explained:

I am only dealing with concepts pertaining to PowerPoint Object Model Reference which has been used in the program. However for full reference click here
1. ApplicationClass: The Microsoft.Office.Interop.PowerPoint.ApplicationClass is used to open office applications with instance of this class.
2. Presentations Object: Represents a collection of presentation(s) that is(are) currently open in PowerPoint.
3. Presentation Object: Is a member of Presentations collection. For more details about methods of Presentation Object you can refer to link.

Code Snippet:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office.Core;
using Powerpoint = Microsoft.Office.Interop.PowerPoint;
namespace Convert_pptTo_imageHtml
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void btnBrowsePpt_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
txtPptLoc.Text = openFileDialog1.FileName;
}
}

private void btnBrowseSaveLocation_Click(object sender, EventArgs e)
{
if (rbImage.Checked)
{
//Setting properties of saveFileDialog1
this.saveFileDialog1.DefaultExt = "(*.jpeg)";
this.saveFileDialog1.FileName = "ImageFile";
this.saveFileDialog1.Filter = "Types allowed (*.jpeg)|*.jpeg|All Files|*.jpg";

//Calling function to save accordingly
this.SavePpt();
}
else if (rbHtml.Checked)
{
//Setting properties of saveFileDialog1
this.saveFileDialog1.DefaultExt = "(*.html)";
this.saveFileDialog1.FileName = "HtmlFile";
this.saveFileDialog1.Filter = "Types allowed (*.html)|*.html|All Files|*.html";

//Calling function to save accordingly
this.SavePpt();
}
else if (rbPdf.Checked)
{
//Setting properties of saveFileDialog1
this.saveFileDialog1.DefaultExt = "(*.pdf)";
this.saveFileDialog1.FileName = "PdfFile";
this.saveFileDialog1.Filter = "Types allowed (*.pdf)|*.pdf";

//Calling function to save accordingly
this.SavePpt();
}
else
{
MessageBox.Show("Oops! You have not selected the option for saving.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}

public void SavePpt()
{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
txtSaveLoc.Text = saveFileDialog1.FileName;
}

try
{
//Declaration of variables
string savePath = txtSaveLoc.Text;
string pptPath = txtPptLoc.Text;
int iIndex = savePath.LastIndexOf(".");

//MsoTriState represents to show links or icons for opened application
Powerpoint.ApplicationClass pptApplication = new Powerpoint.ApplicationClass();
Powerpoint.Presentation pptPresentation = pptApplication.Presentations.Open(pptPath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);

#region Saving As Image
if (txtPptLoc.Text != string.Empty && rbImage.Checked)
{
for (int i = 1; i {
string strNewPath = savePath.Remove(iIndex);
savePath = strNewPath + i.ToString() + ".jpeg";

pptPresentation.Slides[i].Export(savePath, "jpg", 1024, 800);
}

lblStatus.Text = "STATUS: Image saved successfully!";
}
#endregion

#region Saving As HTML
if (txtPptLoc.Text != String.Empty && rbHtml.Checked)
{
pptPresentation.SaveAs(txtSaveLoc.Text, Powerpoint.PpSaveAsFileType.ppSaveAsHTML, MsoTriState.msoFalse);

lblStatus.Text = "STATUS: Html file saved successfully!";
}
#endregion

#region Saving As PDF
if (txtPptLoc.Text != String.Empty && rbPdf.Checked)
{
pptPresentation.ExportAsFixedFormat(txtSaveLoc.Text,
Powerpoint.PpFixedFormatType.ppFixedFormatTypePDF,
Powerpoint.PpFixedFormatIntent.ppFixedFormatIntentPrint,
MsoTriState.msoFalse,
Powerpoint.PpPrintHandoutOrder.ppPrintHandoutHorizontalFirst,
Powerpoint.PpPrintOutputType.ppPrintOutputSlides,
MsoTriState.msoFalse,
null,
Powerpoint.PpPrintRangeType.ppPrintAll,
"",
false,
false,
false,
true,
true,
System.Reflection.Missing.Value);

lblStatus.Text = "STATUS: Pdf file saved successfully!";

}
#endregion

//Closing the opened presentation file
pptPresentation.Close();

//Claiming unused memory
GC.Collect();
}
catch (Exception ex)
{
lblStatus.Text = String.Empty;

MessageBox.Show("APPLICATION REPORTED ERROR. CONSULT VENDOR"
+ " FOR HELP!\n\nTechnical Report: " + ex.ToString(), "Application Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

Download Source Code

Tags: ,

Category: .NET

Comments (3)

Trackback URL | Comments RSS Feed

  1. I really like your blog.. very nice colors & theme. Did you make this website yourself or did
    you hire someone to do it for you? Plz respond as I’m looking to design my
    own blog and would like to find out where u got this from.
    thanks

  2. Leticia says:

    Howdy just wanted to give you a quick heads up. The text
    in your post seem to be running off the screen in
    Opera. I’m not sure if this is a formatting issue or something to do with web browser compatibility but I
    thought I’d post to let you know. The style and design look great though!

    Hope you get the problem solved soon. Kudos

  3. This is a good,common sense article.Very helpful to one who is just finding the resouces about this part.It will certainly help educate me.

Leave a Reply

%d bloggers like this:
| not cached | 2087 | SELECT post_id, meta_key, meta_value FROM wp_postmeta WHERE post_id IN (225) ORDER BY meta_id ASC 43 | 0.0003 | enabled | not cached | 2087 | SELECT post_id, meta_key, meta_value FROM wp_postmeta WHERE post_id IN (228) ORDER BY meta_id ASC 44 | 0.0005 | enabled | not cached | 4495 | SELECT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('category') AND t.term_id IN ( 4,8,9,2,3 ) ORDER BY t.name ASC 45 | 0.0001 | enabled | cached | 736 | SELECT t.term_id FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('category') AND tr.object_id IN (42) ORDER BY t.name ASC 46 | 0.0003 | enabled | not cached | 529 | SELECT option_value FROM wp_options WHERE option_name = 'text_direction' LIMIT 1 47 | 0.0009 | enabled | not cached | 3863 | SELECT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('post_tag') AND tr.object_id IN (42) ORDER BY t.name ASC 48 | 0.0007 | enabled | not cached | 3555 | SELECT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('category') AND tr.object_id IN (42) ORDER BY t.name ASC 49 | 0.0137 | enabled | not cached | 7558 | SELECT * FROM wp_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 42 ORDER BY comment_date_gmt ASC 50 | 0.0004 | enabled | not cached | 632 | SELECT p.ID FROM wp_posts AS p WHERE p.post_date < '2010-05-29 10:25:00' AND p.post_type = 'post' AND p.post_status = 'publish' ORDER BY p.post_date DESC LIMIT 1 51 | 0.0003 | enabled | not cached | 13657 | SELECT * FROM wp_posts WHERE ID = 43 LIMIT 1 52 | 0.0003 | enabled | not cached | 631 | SELECT p.ID FROM wp_posts AS p WHERE p.post_date > '2010-05-29 10:25:00' AND p.post_type = 'post' AND p.post_status = 'publish' ORDER BY p.post_date ASC LIMIT 1 53 | 0.0003 | enabled | not cached | 8872 | SELECT * FROM wp_posts WHERE ID = 41 LIMIT 1 54 | 0.017 | enabled | not cached | 2512 | SELECT p.ID AS 'id', p.post_title AS 'title', p.post_date AS 'date', p.post_author AS 'uid', ( SUM(v.pageviews)/(IF ( DATEDIFF('2017-04-13 21:19:10', DATE_SUB('2017-04-13 21:19:10', INTERVAL 1 WEEK)) > 0, DATEDIFF('2017-04-13 21:19:10', DATE_SUB('2017-04-13 21:19:10', INTERVAL 1 WEEK)), 1) ) ) AS 'avg_views' FROM wp_popularpostssummary v LEFT JOIN wp_posts p ON v.postid = p.ID WHERE 1 = 1 AND p.post_type IN('post','page') AND v.last_viewed > DATE_SUB('2017-04-13 21:19:10', INTERVAL 1 WEEK) AND p.post_password = '' AND p.post_status = 'publish' GROUP BY v.postid ORDER BY avg_views DESC LIMIT 5; 55 | 0.0003 | disabled (query) | not cached | 0 | SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') ORDER BY wp_posts.post_date DESC LIMIT 0, 5 56 | 0.0001 | disabled (query) | not cached | 0 | SELECT FOUND_ROWS() 57 | 0.0022 | enabled | not cached | 7381 | SELECT DISTINCT ID, post_title, post_password, comment_ID, comment_post_ID, comment_author, comment_author_email, comment_date_gmt, comment_approved, comment_type,comment_author_url, SUBSTRING(comment_content,1,100) AS com_excerpt FROM wp_comments LEFT OUTER JOIN wp_posts ON (wp_comments.comment_post_ID = wp_posts.ID) WHERE comment_approved = '1' AND comment_type = '' AND post_password = '' ORDER BY comment_date_gmt DESC LIMIT 5 58 | 0.0003 | enabled | not cached | 10061 | SELECT * FROM wp_posts WHERE ID = 15 LIMIT 1 59 | 0.0005 | enabled | not cached | 2074 | SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC 60 | 0.0002 | enabled | cached | 4714 | SELECT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('category') ORDER BY t.name ASC 61 | 0.0008 | enabled | not cached | 8853 | SELECT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('post_tag') AND tt.count > 0 ORDER BY tt.count DESC LIMIT 200 62 | 0.0004 | enabled | not cached | 3470 | SELECT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = 'nav_menu' AND t.term_id = 33 LIMIT 1 63 | 0.0003 | enabled | not cached | 946 | SELECT tr.object_id FROM wp_term_relationships AS tr INNER JOIN wp_term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('nav_menu') AND tt.term_id IN ('33') ORDER BY tr.object_id ASC 64 | 0.0005 | enabled | not cached | 11910 | SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND wp_posts.ID IN (231,232,234,244,289,306) AND wp_posts.post_type = 'nav_menu_item' AND ((wp_posts.post_status = 'publish')) ORDER BY wp_posts.menu_order ASC 65 | 0.0005 | enabled | not cached | 2109 | SELECT post_id, meta_key, meta_value FROM wp_postmeta WHERE post_id IN (234) ORDER BY meta_id ASC 66 | 0.0002 | enabled | not cached | 2092 | SELECT post_id, meta_key, meta_value FROM wp_postmeta WHERE post_id IN (231) ORDER BY meta_id ASC 67 | 0.0004 | enabled | not cached | 2086 | SELECT post_id, meta_key, meta_value FROM wp_postmeta WHERE post_id IN (232) ORDER BY meta_id ASC 68 | 0.0003 | enabled | not cached | 2086 | SELECT post_id, meta_key, meta_value FROM wp_postmeta WHERE post_id IN (289) ORDER BY meta_id ASC 69 | 0.0003 | enabled | not cached | 2086 | SELECT post_id, meta_key, meta_value FROM wp_postmeta WHERE post_id IN (244) ORDER BY meta_id ASC 70 | 0.0003 | enabled | not cached | 2086 | SELECT post_id, meta_key, meta_value FROM wp_postmeta WHERE post_id IN (306) ORDER BY meta_id ASC 71 | 0.0007 | enabled | not cached | 26613 | SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND wp_posts.ID IN (207,209,279,239,301) AND wp_posts.post_type = 'page' AND ((wp_posts.post_status = 'publish')) ORDER BY wp_posts.post_date DESC 72 | 0.0001 | enabled | cached | 736 | SELECT t.term_id FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('category') AND tr.object_id IN (42) ORDER BY t.name ASC 73 | 0.0001 | enabled | cached | 559 | select meta_key from wp_postmeta where meta_key like '_wp_page_template' and meta_value like 'page-youtube.php' 74 | 0.0001 | enabled | cached | 625 | select meta_key from wp_postmeta where meta_key like '_wp_page_template' and meta_value like 'page-portfolio.php' 75 | 0.0001 | enabled | cached | 559 | select meta_key from wp_postmeta where meta_key like '_wp_page_template' and meta_value like 'page-youtube.php' 76 | 0.0001 | enabled | cached | 625 | select meta_key from wp_postmeta where meta_key like '_wp_page_template' and meta_value like 'page-portfolio.php' -->