Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Last active November 27, 2021 07:57
Show Gist options
  • Save GroupDocsGists/3b2358dd1dcdf2281bd21c0f01ceef0c to your computer and use it in GitHub Desktop.
Save GroupDocsGists/3b2358dd1dcdf2281bd21c0f01ceef0c to your computer and use it in GitHub Desktop.
How to Convert PowerPoint Presentation to PDF using C#
// Convert few consecutive PPT slides to PDF using C#
using (Converter converter = new Converter("path/presentation.pptx"))
{
PdfConvertOptions options = new PdfConvertOptions
{
PageNumber = 2,
PagesCount = 3
};
converter.Convert("path/converted-presentation.pdf", options);
}
// Convert whole PPT to PDF using C#
using (Converter converter = new Converter("path/presentation.pptx"))
{
converter.Convert("path/converted-presentation.pdf", new PdfConvertOptions());
}
// Convert only specific PPT slides to PDF using C#
using (Converter converter = new Converter("path/presentation.pptx"))
{
PdfConvertOptions options = new PdfConvertOptions
{
Pages = new List<int>{ 1, 3 }
};
converter.Convert("path/converted-presentation.pdf", options);
}
// List possible conversions of PPT using .NET API
string sourceFile = "path/presentation.pptx";
using (Converter converter = new Converter(sourceFile))
{
PossibleConversions conversions = converter.GetPossibleConversions();
Console.WriteLine("{0} is of type {1} and could be converted to:", sourceFile, conversions.Source.Extension);
foreach (var conversion in conversions.All)
{
Console.WriteLine("\t {0} as {1} conversion.", conversion.Format, conversion.IsPrimary?"primary": "secondary");
}
}
// Conversion of presentations to PDF with advanced options using C#
using (Converter converter = new Converter("path/presentation.pptx"))
{
PdfConvertOptions options = new PdfConvertOptions
{
PageNumber = 2,
PagesCount = 1,
Rotate = Rotation.On180,
Dpi = 300,
Width = 1024,
Height = 768
};
converter.Convert("path/converted-presentation.pdf", options);
}
// Apply watermark to presentation slides while converting it to PDF using C#
using (Converter converter = new Converter("path/presentation.pptx"))
{
PdfConvertOptions options = new PdfConvertOptions
{
Watermark = new WatermarkTextOptions("Watermark")
{
Color = Color.Blue,
Width = 100,
Height = 100,
Background = true,
RotationAngle = -45,
Transparency = 0.5
}
};
converter.Convert("path/converted-presentation.pdf", options);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment