Как преобразовать PPT файл в PDF файл на C# и .NET

Полный код

using System;
using System.IO;
using System.Collections;

namespace Sample
{
    class Test
    {
        static void Main(string[] args)
        {
            // Convert PPT file to PDF file
            // If you need more information about UseOffice .Net email us at:
            // [email protected].
            SautinSoft.UseOffice u = new SautinSoft.UseOffice();

            string inpFile = Path.GetFullPath(@"..\..\..\..\..\Testing files\example.ppt");
            string outFile = Path.GetFullPath(@"Result.pdf");

            // Prepare UseOffice .Net, loads MS PowerPoint in memory
            int ret = u.InitPowerPoint();

            // Return values:
            // 0 - Loading successfully
            // 1 - Can't load MS PowerPoint library in memory
            if (ret == 1)
            {
                Console.WriteLine("Error! Can't load MS PowerPoint library in memory");
                return;
            }

            // Perform the conversion.
            ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.PPT_to_PDF);

            // Release MS PowerPoint from memory
            u.ClosePowerPoint();

            // 0 - Converting successfully
            // 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
            // 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
            // 3 - Converting failed, please contact with our Support Team
            // 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
            if (ret == 0)
            {
                Console.WriteLine("Converting successfully!");
                // Open the result.
                System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });

            }
            else
                Console.WriteLine("Error! Please contact with SautinSoft support: [email protected].");
        }
    }
}

Download

Imports System
Imports System.IO
Imports System.Collections

Namespace Sample
    Friend Class Test
        Shared Sub Main(ByVal args() As String)
            ' Convert PPT file to PDF file
            ' If you need more information about UseOffice .Net email us at:
            ' [email protected].
            Dim u As New SautinSoft.UseOffice()

            Dim inpFile As String = Path.GetFullPath("..\..\..\..\Testing files\example.ppt")
            Dim outFile As String = Path.GetFullPath("Result.pdf")

            ' Prepare UseOffice .Net, loads MS PowerPoint in memory
            Dim ret As Integer = u.InitPowerPoint()

            ' Return values:
            ' 0 - Loading successfully
            ' 1 - Can't load MS PowerPoint library in memory
            If ret = 1 Then
                Console.WriteLine("Error! Can't load MS PowerPoint library in memory")
                Return
            End If

            ' Perform the conversion.
            ret = u.ConvertFile(inpFile, outFile, SautinSoft.UseOffice.eDirection.PPT_to_PDF)

            ' Release MS PowerPoint from memory
            u.ClosePowerPoint()

            ' 0 - Converting successfully
            ' 1 - Can't open input file. Check that you are using full local path to input file, URL and relative path are not supported
            ' 2 - Can't create output file. Please check that you have permissions to write by this path or probably this path already used by another application
            ' 3 - Converting failed, please contact with our Support Team
            ' 4 - MS Office isn't installed. The component requires that any of these versions of MS Office should be installed: 2000, XP, 2003, 2007, 2010, 2013, 2016 or 2019.
            If ret = 0 Then
                Console.WriteLine("Converting successfully!")
                ' Open the result.
                System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFile) With {.UseShellExecute = True})

            Else
                Console.WriteLine("Error! Please contact with SautinSoft support: [email protected].")
            End If
        End Sub
    End Class
End Namespace

Download


Если вам нужен пример кода или у вас есть вопрос: напишите нам по адресу [email protected] или спросите в онлайн-чате (правый нижний угол этой страницы) или используйте форму ниже:



Вопросы и предложения всегда приветствуются!

Мы разрабатываем компоненты .Net с 2002 года. Мы знаем форматы PDF, DOCX, RTF, HTML, XLSX и Images. Если вам нужна помощь в создании, изменении или преобразовании документов в различных форматах, мы можем вам помочь. Мы напишем для вас любой пример кода абсолютно бесплатно.