Konwersja PPT (PowerPoint) do PDF w C# (przyklad samouczka)
Converting PowerPoint presentations to PDFs using C# can enhance business operations by enabling quick creation, easy updates, and sharing of presentations. This conversion also ensures compatibility with various devices and programs, thereby saving time and improving efficiency.
IronPPT seamlessly loads and saves PPTX files - no Microsoft Office required. Perfect for automating slides, text, shapes, and images in any .NET application. Get started with IronPPT now!
This tutorial shows how to convert a PowerPoint presentation to PDF in C# using the IronPDF library.
How to Convert PPT (PowerPoint) to PDF in C#
- Install C# library to convert PowerPoint files to PDFs
- Konwersja prezentacji PowerPoint do pliku HTML
- Utilize
RenderHtmlFileAsPdfmethod to generate PDF from HTML file - Opcjonalnie można dodać niestandardowe nagłówki i stopki do nowego pliku PDF
- Zapisuj pliki PDF o identycznym wyglądzie jak w programie PowerPoint
IronPDF: biblioteka PDF dla platformy .NET
IronPDF is a .NET PDF library that makes it simple for C# and VB developers to create, edit, and manipulate PDF documents within .NET applications. IronPDF provides excellent rendering capabilities with support for converting HTML to PDF using IronPDF, converting URLs to PDF using IronPDF, SVG to Image, HTML File to PDF, and much more. IronPDF excels at producing PDFs of reports, invoices, statements, and receipts from web pages or existing HTML/CSS templates.
One critical feature is that the IronPDF library can be used to fill out existing PDF forms or create new PDF forms from scratch. This allows businesses to streamline their document workflow by automating the creation and filling out of forms with IronPDF. In addition, IronPDF makes it easy to add headers and footers using IronPDF, apply watermarks to PDFs with IronPDF, and page numbers to PDF files. This makes it an ideal solution for creating professional-looking PDFs. Let's see how to use IronPDF to convert a PowerPoint presentation to a PDF document.
Wymagania wstępne
There are some prerequisites to converting a .ppt file to a PDF document.
- Visual Studio 2022 (zalecane)
- Działająca aplikacja .NET z najnowszym .NET Framework (zalecane)
- Zainstalowany pakiet Microsoft Office
- A stable internet connection to install the IronPDF library for PDF conversion
Let's move to the main steps in converting .ppt files to PDFs.
Step 1: Export your PowerPoint Presentation as HTML
The first step is to convert PowerPoint files to HTML, and then the exported HTML is used to convert to a PDF document.
To export your .ppt file to HTML format, do the following:
- Open the Zamzar PPT to HTML converter online tool.
- Upload the PowerPoint document to the Zamzar website.
-
Click on the "Convert Now" button.
Convert PPT to HTML
It'll start converting the PPTX file to HTML.
Step 2: Add IronPDF to the solution
IronPDF can be installed using NuGet Package Manager or the NuGet Package Manager Console.
Let's use the Package Manager Console method to install IronPDF.
Go to "Tools" in the toolbar and select the "Package Manager Console" option from the side menu.
NuGet Package Manager is shown in Visual Studio
Enter the following command in the console to install IronPDF.
Install-Package IronPPT
Installation of IronPDF Library
Now, it's time to write the code to convert a PowerPoint to PDF using the IronPDF library.
Step 3: Convert the HTML File to PDF
Once the HTML file is available, IronPDF will be used to convert the HTML file to a PDF file.
Add IronPDF to the Code file
First, add the following line of code to the top of the source file to import IronPDF.
using IronPdf;
using IronPdf;
Imports IronPdf
Instantiate ChromePdfRenderer Object
Now, instantiate the ChromePdfRenderer object. It'll help to create and customize the PDF file.
var renderer = new ChromePdfRenderer();
var renderer = new ChromePdfRenderer();
Dim renderer = New ChromePdfRenderer()
Convert HTML file (Exported from PowerPoint file) to PDF
Let's use the RenderHtmlFileAsPdf method to convert the HTML file to the PDF.
var pdf = renderer.RenderHtmlFileAsPdf(@"C:\Presentation\Presentation.html");
var pdf = renderer.RenderHtmlFileAsPdf(@"C:\Presentation\Presentation.html");
Dim pdf = renderer.RenderHtmlFileAsPdf("C:\Presentation\Presentation.html")
The PowerPoint .ppt files are converted to PDF. Let's see how to customize the generated PDF with a watermark, password, and headers.
Step 4: Add watermark, password, and headers in the PDF file
Add Watermarks in PDFs using IronPDF
This section shows how to add a watermark in the PDF as a stamped image. Below, use the ApplyStamp method to apply watermarks in the PDF file.
pdf.ApplyStamp(new ImageStamper("https://ironpdf.com/img/products/ironpdf-logo-text-dotnet.svg"));
pdf.ApplyStamp(new ImageStamper("https://ironpdf.com/img/products/ironpdf-logo-text-dotnet.svg"));
pdf.ApplyStamp(New ImageStamper("https://ironpdf.com/img/products/ironpdf-logo-text-dotnet.svg"))
Add Password Protection to PDFs
Dodanie hasła do pliku PDF chroni go przed nieautoryzowanym dostępem. IronPDF supports adding passwords for both users and owners. You can set a different password for the user and admin to allow customization of PDF files.
pdf.Password = "EasyPassword";
pdf.Password = "EasyPassword";
pdf.Password = "EasyPassword"
Add HTML headers
HTML headers are a good functionality for PDFs. It makes it easy to customize the header stylishly. Use the HtmlHeaderFooter object to add headers in the PDF file.
renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter()
{
MaxHeight = 20, //millimeters
HtmlFragment = "<h1>Headers are easy with IronPDF!</h1>",
};
renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter()
{
MaxHeight = 20, //millimeters
HtmlFragment = "<h1>Headers are easy with IronPDF!</h1>",
};
renderer.RenderingOptions.HtmlHeader = New HtmlHeaderFooter() With {
.MaxHeight = 20,
.HtmlFragment = "<h1>Headers are easy with IronPDF!</h1>"
}
Step 5: Save PDF File
After all customizations are done, it's now time to save the PDF file on the local machine. Use IronPDF's SaveAs method to save the PDF file.
pdf.SaveAs("C:\\PptToPdf.pdf");
pdf.SaveAs("C:\\PptToPdf.pdf");
pdf.SaveAs("C:\PptToPdf.pdf")
Let's look at the Program.cs file.
using IronPdf;
using IronPdf.Editing;
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter()
{
MaxHeight = 20, //millimeters
HtmlFragment = "<h1>Headers are easy with IronPDF!</h1>",
};
var pdf = renderer.RenderHtmlFileAsPdf(@"C:\Presentation\Presentation.html");
pdf.ApplyStamp(new ImageStamper("https://ironpdf.com/img/products/ironpdf-logo-text-dotnet.svg"));
pdf.Password = "EasyPassword";
pdf.SaveAs("C:\\PptToPdf.pdf");
using IronPdf;
using IronPdf.Editing;
var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter()
{
MaxHeight = 20, //millimeters
HtmlFragment = "<h1>Headers are easy with IronPDF!</h1>",
};
var pdf = renderer.RenderHtmlFileAsPdf(@"C:\Presentation\Presentation.html");
pdf.ApplyStamp(new ImageStamper("https://ironpdf.com/img/products/ironpdf-logo-text-dotnet.svg"));
pdf.Password = "EasyPassword";
pdf.SaveAs("C:\\PptToPdf.pdf");
Imports IronPdf
Imports IronPdf.Editing
Private renderer = New ChromePdfRenderer()
renderer.RenderingOptions.HtmlHeader = New HtmlHeaderFooter() With {
.MaxHeight = 20,
.HtmlFragment = "<h1>Headers are easy with IronPDF!</h1>"
}
Dim pdf = renderer.RenderHtmlFileAsPdf("C:\Presentation\Presentation.html")
pdf.ApplyStamp(New ImageStamper("https://ironpdf.com/img/products/ironpdf-logo-text-dotnet.svg"))
pdf.Password = "EasyPassword"
pdf.SaveAs("C:\PptToPdf.pdf")
Plik PDF wyjściowy
The following PowerPoint presentation was converted to a PDF file.
PowerPoint Presentation
The generated PDF file is saved at the given location when the project is run. Open the file, and when it asks for a password, enter the password given in the project.
Password Dialog Box
After entering the correct password, the output PDF file looks like this.
Output of the Generated PDF
IronPDF renders the PDF file while preserving the formatting and responsiveness of the PowerPoint presentation. Headers and watermarks have been applied in the project.
Podsumowanie
That's how you convert a .ppt to PDF using IronPDF in C#. If you need more information about IronPDF, be sure to check out another example of using HTML to create a PDF using IronPDF. The sample pages contain a wealth of resources that can help you with all PDF-related operations.
Cheap and functional, IronPDF is the perfect solution for those who need to create PDF documents in .NET applications. IronPDF starts from $799, making it one of the more affordable PDF libraries on the market.
Purchase Iron Software's complete software suite of five products for only the price of two of them!
Często Zadawane Pytania
Jak mogę przekonwertować prezentację PowerPoint do formatu PDF bez utraty formatowania?
Aby przekonwertować prezentację PowerPoint do formatu PDF bez utraty formatowania, należy najpierw wyeksportować plik PowerPoint do formatu HTML za pomocą narzędzia online, takiego jak Zamzar. Następnie należy użyć metody `RenderHtmlFileAsPdf` biblioteki IronPDF, aby przekonwertować plik HTML do formatu PDF, zachowując oryginalny wygląd i układ.
Jakie są kroki, aby przekonwertować plik PowerPoint na PDF przy użyciu języka C#?
Zacznij od wyeksportowania pliku PowerPoint do formatu HTML za pomocą usługi takiej jak Zamzar. Dodaj bibliotekę IronPDF do swojego projektu .NET za pośrednictwem menedżera pakietów NuGet. Użyj metody `RenderHtmlFileAsPdf`, aby przekonwertować HTML na PDF, a następnie zapisz wynikowy plik lokalnie.
Jak mogę zapewnić bezpieczeństwo moich dokumentów PDF?
Możesz zwiększyć bezpieczeństwo swoich dokumentów PDF, używając IronPDF do dodania ochrony hasłem. Wymaga to ustawienia haseł użytkownika i właściciela, aby ograniczyć nieautoryzowany dostęp i modyfikacje.
Czy można spersonalizować plik PDF za pomocą znaków wodnych?
Tak, za pomocą IronPDF można dostosować plik PDF, dodając do niego znaki wodne. Aby nałożyć obraz znaku wodnego na dokument PDF, należy użyć metody `ApplyStamp` wraz z obiektem `ImageStamper`.
Jakie narzędzia są potrzebne do konwersji pliku PPT na PDF w języku C#?
Będziesz potrzebować programu Visual Studio 2022, aplikacji .NET z najnowszym środowiskiem .NET Framework oraz biblioteki IronPDF, którą można zainstalować za pomocą menedżera pakietów NuGet.
Jak mogę dodać nagłówki HTML do mojego dokumentu PDF?
Możesz dodać nagłówki HTML do dokumentu PDF, korzystając z możliwości IronPDF. Pozwala to na umieszczenie dynamicznej treści, takiej jak tytuły lub numery stron, w sekcji nagłówka pliku PDF.
Jakie są kwestie związane z kosztami korzystania z IronPDF?
IronPDF oferuje opłacalny model cenowy, zaczynający się od licencji $liteLicense, co czyni go przystępnym cenowo rozwiązaniem dla programistów pragnących tworzyć profesjonalnej jakości dokumenty PDF w ramach aplikacji .NET.
Czy IronPPT i IronPDF obsługują .NET 10 do konwersji plików PPT do PDF w języku C#?
Tak — IronPPT w pełni obsługuje .NET 10 (a także wersje 9, 8, 7, 6, .NET Framework i .NET Core), zapewniając kompatybilność podczas konwersji prezentacji PowerPoint do formatu PDF przy użyciu C# i IronPDF. ([ironsoftware.com](https://ironsoftware.com/csharp/PPT/blog/using-IronPPT/PPT-PowerPoint-to-PDF-C#-tutorial/))

