Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
In this tutorial, learn to convert a PowerPoint presentation to a PDF using C# and Iron PDF within Visual Studio 2022. Start by uploading your PowerPoint file to Zamzar, an online tool, to convert it into an HTML file. Once the conversion is complete, download the HTML file, which will be in a zip format, containing all the necessary data. Switch to Visual Studio 2022, where Iron PDF is pre-installed via the NuGet Package Manager. The tutorial demonstrates using the ChromePdfRenderer
class from Iron PDF to render the HTML file into a PDF document. Set the paper size to A2 and use a license key to activate Iron PDF's full features. The code then converts the HTML to a PDF and saves it to your file system. Running the project generates a PDF that maintains the PowerPoint's original formatting and responsiveness. The video concludes with an offer for further support if needed, ensuring users can easily recreate the process.
Here is the sample code used in the tutorial:
using System;
using IronPdf;
namespace PPTToPDFConverter
{
class Program
{
static void Main(string[] args)
{
// Prompting the user to input the path of the downloaded HTML file
Console.WriteLine("Please enter the path to the HTML file:");
string htmlFilePath = Console.ReadLine();
// Prompting the user to input the desired path and name for the output PDF file
Console.WriteLine("Please enter the desired path and name for the output PDF:");
string outputPdfPath = Console.ReadLine();
// Instantiate the ChromePdfRenderer
var renderer = new ChromePdfRenderer();
// Set the paper size for the PDF document
renderer.RenderingOptions.PaperSize = IronPdf.Rendering.PdfPaperSize.A2;
// Optionally apply a license key if available
IronPdf.License.LicenseKey = "YOUR_LICENSE_KEY_HERE"; // Replace with your actual license key
try
{
// Render the PDF from the HTML file
var pdfDocument = renderer.RenderHtmlFileAsPdf(htmlFilePath);
// Save the rendered PDF to the specified path
pdfDocument.SaveAs(outputPdfPath);
Console.WriteLine("PDF generated successfully. Saved at: " + outputPdfPath);
}
catch (Exception ex)
{
// Log any errors that occur during the PDF generation process
Console.WriteLine("An error occurred: " + ex.Message);
}
}
}
}
using System;
using IronPdf;
namespace PPTToPDFConverter
{
class Program
{
static void Main(string[] args)
{
// Prompting the user to input the path of the downloaded HTML file
Console.WriteLine("Please enter the path to the HTML file:");
string htmlFilePath = Console.ReadLine();
// Prompting the user to input the desired path and name for the output PDF file
Console.WriteLine("Please enter the desired path and name for the output PDF:");
string outputPdfPath = Console.ReadLine();
// Instantiate the ChromePdfRenderer
var renderer = new ChromePdfRenderer();
// Set the paper size for the PDF document
renderer.RenderingOptions.PaperSize = IronPdf.Rendering.PdfPaperSize.A2;
// Optionally apply a license key if available
IronPdf.License.LicenseKey = "YOUR_LICENSE_KEY_HERE"; // Replace with your actual license key
try
{
// Render the PDF from the HTML file
var pdfDocument = renderer.RenderHtmlFileAsPdf(htmlFilePath);
// Save the rendered PDF to the specified path
pdfDocument.SaveAs(outputPdfPath);
Console.WriteLine("PDF generated successfully. Saved at: " + outputPdfPath);
}
catch (Exception ex)
{
// Log any errors that occur during the PDF generation process
Console.WriteLine("An error occurred: " + ex.Message);
}
}
}
}
Imports System
Imports IronPdf
Namespace PPTToPDFConverter
Friend Class Program
Shared Sub Main(ByVal args() As String)
' Prompting the user to input the path of the downloaded HTML file
Console.WriteLine("Please enter the path to the HTML file:")
Dim htmlFilePath As String = Console.ReadLine()
' Prompting the user to input the desired path and name for the output PDF file
Console.WriteLine("Please enter the desired path and name for the output PDF:")
Dim outputPdfPath As String = Console.ReadLine()
' Instantiate the ChromePdfRenderer
Dim renderer = New ChromePdfRenderer()
' Set the paper size for the PDF document
renderer.RenderingOptions.PaperSize = IronPdf.Rendering.PdfPaperSize.A2
' Optionally apply a license key if available
IronPdf.License.LicenseKey = "YOUR_LICENSE_KEY_HERE" ' Replace with your actual license key
Try
' Render the PDF from the HTML file
Dim pdfDocument = renderer.RenderHtmlFileAsPdf(htmlFilePath)
' Save the rendered PDF to the specified path
pdfDocument.SaveAs(outputPdfPath)
Console.WriteLine("PDF generated successfully. Saved at: " & outputPdfPath)
Catch ex As Exception
' Log any errors that occur during the PDF generation process
Console.WriteLine("An error occurred: " & ex.Message)
End Try
End Sub
End Class
End Namespace
Key Steps Explained:
Further Reading: How to Convert Powerpoint (PPT) to PDF in C#