Загрузка, просмотр, конвертация PPTX документа используя C#

Категория: Office.NET

03 августа 2026

Файл с расширением PPTX - это документ формата Microsoft Powerpoint Open XML, который содержит презентацию.

В данной статье мы рассмотрим наиболее часто встречающиеся ситуации, которые возникают при загрузке, рендеринге, просмотре, конвертации PPTX документа. Все примеры кода ниже используют VintaSoft Imaging .NET SDK и VintaSoft Office .NET Plug-in.

VintaSoft Imaging .NET SDK для работы с PPTX документом использует собственный Open XML Office движок, который написан на C# с нуля и не зависит от Microsoft Office.


Получение информации о PPTX документе

PPTX документ как и любой "Open XML"-документ содержит информацию о документе в объекте OpenXmlDocumentInformation.

Вот C# код, который демонстрирует как получить информацию о PPTX документе:
/// <summary>
/// Shows information about PPTX document from metadata tree.
/// </summary>
/// <param name="pptxFilename">A name of PPTX file.</param>
public static void ShowPptxDocumentInfoFromMetadataTree(string pptxFilename)
{
    // create image collection
    using (Vintasoft.Imaging.ImageCollection images = new Vintasoft.Imaging.ImageCollection())
    {
        // add PPTX document to the image collection
        images.Add(pptxFilename);
        // if image collection has images/pages
        if (images.Count > 0)
        {
            // get the first image/page
            Vintasoft.Imaging.VintasoftImage firstImage = images[0];

            // get PptxDocumentMetadata object from the metadata tree of PPTX decoder
            Vintasoft.Imaging.Metadata.PptxDocumentMetadata pptxDocumentMetadata =
                firstImage.SourceInfo.Decoder.GetDocumentMetadata() as Vintasoft.Imaging.Metadata.PptxDocumentMetadata;
            // if PptxDocumentMetadata object is found
            if (pptxDocumentMetadata != null)
            {
                // get PPTX document from PptxDocumentMetadata object
                Vintasoft.Imaging.Office.OpenXml.Pptx.PptxDocument pptxDocument =
                    pptxDocumentMetadata.Document;

                // show information about PPTX document

                System.Console.WriteLine(string.Format("PPTX document \"{0}\" information:", pptxFilename));
                System.Console.WriteLine(string.Format(" - Page count: {0}", pptxDocument.Pages.Count));
                System.Console.WriteLine(string.Format(" - Category: {0}", pptxDocument.DocumentInformation.Category));
                System.Console.WriteLine(string.Format(" - ContentStatus: {0}", pptxDocument.DocumentInformation.ContentStatus));
                System.Console.WriteLine(string.Format(" - ContentType: {0}", pptxDocument.DocumentInformation.ContentType));
                System.Console.WriteLine(string.Format(" - Created: {0}", pptxDocument.DocumentInformation.Created));
                System.Console.WriteLine(string.Format(" - Creator: {0}", pptxDocument.DocumentInformation.Creator));
                System.Console.WriteLine(string.Format(" - Description: {0}", pptxDocument.DocumentInformation.Description));
                System.Console.WriteLine(string.Format(" - Identifier: {0}", pptxDocument.DocumentInformation.Identifier));
                System.Console.WriteLine(string.Format(" - Keywords: {0}", pptxDocument.DocumentInformation.Keywords));
                System.Console.WriteLine(string.Format(" - Language: {0}", pptxDocument.DocumentInformation.Language));
                System.Console.WriteLine(string.Format(" - LastModifiedBy: {0}", pptxDocument.DocumentInformation.LastModifiedBy));
                System.Console.WriteLine(string.Format(" - LastPrinted: {0}", pptxDocument.DocumentInformation.LastPrinted));
                System.Console.WriteLine(string.Format(" - Modified: {0}", pptxDocument.DocumentInformation.Modified));
                System.Console.WriteLine(string.Format(" - Revision: {0}", pptxDocument.DocumentInformation.Revision));
                System.Console.WriteLine(string.Format(" - Subject: {0}", pptxDocument.DocumentInformation.Subject));
                System.Console.WriteLine(string.Format(" - Title: {0}", pptxDocument.DocumentInformation.Title));
                System.Console.WriteLine(string.Format(" - Version: {0}", pptxDocument.DocumentInformation.Version));
            }
        }

        // dispose images
        images.ClearAndDisposeItems();
    }
}


Рендеринг страниц PPTX документа

Каждая страница PPTX документа может быть отрендерена, то есть получена в виде изображения.

Вот C# код, который демонстрирует как отрендерить все страницы PPTX документа и сохранить в PNG файлы:
/// <summary>
/// Renders pages of PPTX document.
/// </summary>
/// <param name="pptxFilename">A name of PPTX file.</param>
public static void RenderPagesOfPptxDocument(string pptxFilename)
{
    // create image collection
    using (Vintasoft.Imaging.ImageCollection images = new Vintasoft.Imaging.ImageCollection())
    {
        // add PPTX document to the image collection
        images.Add(pptxFilename);

        // for each image in collection
        for (int i = 0; i < images.Count; i++)
        {
            // get image
            Vintasoft.Imaging.VintasoftImage image = images[i];

            // save image to a PNG file
            image.Save(string.Format("page{0}.png", i));
        }

        // dispose images
        images.ClearAndDisposeItems();
    }
}


Извлечение текста из PPTX документа

Каждая страница PPTX документа может содержать текст и графику.

Вот C# код, который демонстрирует как получить текст всех страниц PPTX документа:
public static void ExtractPptxPageTextFromMetadataTree(string pptxFilename)
{
    // create image collection
    using (Vintasoft.Imaging.ImageCollection images = new Vintasoft.Imaging.ImageCollection())
    {
        // add PPTX document to the image collection
        images.Add(pptxFilename);

        // for each image in collection
        for (int i = 0; i < images.Count; i++)
        {
            // get image
            Vintasoft.Imaging.VintasoftImage image = images[i];

            // get PptxPageTextRegionMetadata object from the metadata tree of image
            Vintasoft.Imaging.Metadata.PptxPageTextRegionMetadata pptxPageTextRegionMetadata =
                image.Metadata.MetadataTree.FindChildNode<Vintasoft.Imaging.Metadata.PptxPageTextRegionMetadata>();
            // if PptxPageTextRegionMetadata object is found
            if (pptxPageTextRegionMetadata != null)
            {
                // get the text region from the PptxPageTextRegionMetadata object
                Vintasoft.Imaging.Text.TextRegion textregion = pptxPageTextRegionMetadata.GetTextRegion();
                // if text region is found
                if (textregion != null)
                {
                    // show information about text region
                    System.Console.WriteLine(string.Format("Page {0}, Text={1}", i, textregion.TextContent));
                }
            }
        }

        // dispose images
        images.ClearAndDisposeItems();
    }
}


Просмотр PPTX документа в WinForms приложении

WinForms UI-контрол ImageViewer позволяет просматривать PPTX документ.
Вот C# код, который демонстрирует как просмотреть PPTX документ в WinForms UI-контроле ImageViewer в WinForms приложении:
...
// open PPTX file in WinForms image viewer
imageViewer1.Images.Add("PptxTestDocument.pptx");
...


Просмотр PPTX документа в WPF приложении

WPF UI-контрол WpfImageViewer позволяет просматривать PPTX документ.
Вот C# код, который демонстрирует как просмотреть PPTX документ в WPF UI-контроле WpfImageViewer в WPF приложении:
...
// open PPTX file in WPF image viewer
wpfImageViewer1.Images.Add("PptxTestDocument.pptx");
...


Просмотр PPTX документа в Веб приложении

JavaScript UI-контрол WebImageViewerJS позволяет просматривать PPTX документ.
Вот JavaScript код, который демонстрирует как просмотреть PPTX документ в JavaScript UI-контроле WebImageViewerJS в Веб приложении:
...
var imageViewer1 = new Vintasoft.Imaging.UI.WebImageViewerJS("WebImageViewer1");
// open PPTX file in web image viewer
imageViewer1.get_Images().openFile("PptxTestDocument.pptx");
...


Также JavaScript UI-контрол WebDocumentViewerJS позволяет просматривать PPTX документ.
Вот JavaScript код, который демонстрирует как просмотреть PPTX документ в JavaScript UI-контроле WebDocumentViewerJS в Веб приложении:
...
// create the document viewer
var docViewer1 = new Vintasoft.Imaging.DocumentViewer.WebDocumentViewerJS(docViewerSettings);
...
// open PPTX file in web document viewer
docViewer1.openFile("PptxTestDocument.pptx");
...


Печать PPTX документа

Если нужно распечатать PPTX документ в WPF-приложении, то прочитайте статью 'Печать изображений в WPF'.

Если нужно распечатать PPTX документ в WinForms- или консольном-приложении, то прочитайте статью 'Печать изображений используя библиотеку System.Drawing'.


Конвертация PPTX файла в PDF файл

Процесс конвертации PPTX файла в PDF файл состоит из следующих шагов:

Вот C# код, который демонстрирует как сконвертировать PPTX файл в PDF файл:
/// <summary>
/// Converts PPTX document to a PDF document using ImageCollection and PdfEncoder classes.
/// </summary>
public static void ConvertPptxToPdf(string pptxFileName, string pdfFileName)
{
    // specify that VintaSoft Imaging .NET SDK should use GDI+ for drawing of 2D graphics
    Vintasoft.Imaging.Drawing.Gdi.GdiGraphicsFactory.SetAsDefault();
    // specify that VintaSoft Imaging .NET SDK should use SkiaSharp for drawing of 2D graphics
    //Vintasoft.Imaging.Drawing.SkiaSharp.SkiaSharpDrawingFactory.SetAsDefault();

    // create image collection
    using (Vintasoft.Imaging.ImageCollection imageCollection = new Vintasoft.Imaging.ImageCollection())
    {
        // add PPTX document to collection
        imageCollection.Add(pptxFileName);

        // create pdfEncoder
        using (Vintasoft.Imaging.Codecs.Encoders.PdfEncoder pdfEncoder = 
            new Vintasoft.Imaging.Codecs.Encoders.PdfEncoder(true))
        {
            // set comression for image resources
            pdfEncoder.Settings.Compression = Vintasoft.Imaging.Codecs.Encoders.PdfImageCompression.Jpeg;

            // save images of image collection to PDF document using PdfEncoder
            imageCollection.SaveSync(pdfFileName, pdfEncoder);
        }

        // dispose images
        imageCollection.ClearAndDisposeItems();
    }
}


Конвертация PPTX файла в многостраничный TIFF файл

Процесс конвертации PPTX файла в многостраничный TIFF файл состоит из следующих шагов:

Вот C# код, который демонстрирует как сконвертировать PPTX файл в многостраничный TIFF файл:
/// <summary>
/// Converts PPTX document to TIFF file using ImageCollection and TiffEncoder classes.
/// PPTX document is rendered with specified resolution.
/// </summary>
public static void ConvertPptxToTiff(string pptxFileName, string tiffFileName, float dpi)
{
    // specify that VintaSoft Imaging .NET SDK should use GDI+ for drawing of 2D graphics
    Vintasoft.Imaging.Drawing.Gdi.GdiGraphicsFactory.SetAsDefault();
    // specify that VintaSoft Imaging .NET SDK should use SkiaSharp for drawing of 2D graphics
    //Vintasoft.Imaging.Drawing.SkiaSharp.SkiaSharpDrawingFactory.SetAsDefault();

    // create image collection
    using (Vintasoft.Imaging.ImageCollection imageCollection = new Vintasoft.Imaging.ImageCollection())
    {
        // add PPTX document to collection
        imageCollection.Add(pptxFileName);

        // set rendering settings
        imageCollection.SetRenderingSettings(new Vintasoft.Imaging.Codecs.Decoders.RenderingSettings(dpi, dpi));

        // create TiffEncoder
        using (Vintasoft.Imaging.Codecs.Encoders.TiffEncoder tiffEncoder = 
            new Vintasoft.Imaging.Codecs.Encoders.TiffEncoder(true))
        {
            // set TIFF compression to Zip
            tiffEncoder.Settings.Compression = 
                Vintasoft.Imaging.Codecs.ImageFiles.Tiff.TiffCompression.Zip;

            // save images of image collection to TIFF file using TiffEncoder
            imageCollection.SaveSync(tiffFileName, tiffEncoder);
        }

        // dispose images
        imageCollection.ClearAndDisposeItems();
    }
}


Конвертация PPTX файла в PNG файлы

Процесс конвертации PPTX файла в PNG файлы состоит из следующих шагов:

Вот C# код, который демонстрирует как сконвертировать PPTX файла в PNG файлы:
/// <summary>
/// Converts pages of PPTX document to PNG files.
/// </summary>
public static void ConvertPptxToPng(string pptxFileName)
{
    // specify that VintaSoft Imaging .NET SDK should use GDI+ for drawing of 2D graphics
    Vintasoft.Imaging.Drawing.Gdi.GdiGraphicsFactory.SetAsDefault();
    // specify that VintaSoft Imaging .NET SDK should use SkiaSharp for drawing of 2D graphics
    //Vintasoft.Imaging.Drawing.SkiaSharp.SkiaSharpDrawingFactory.SetAsDefault();

    // create image collection
    using (Vintasoft.Imaging.ImageCollection images = new Vintasoft.Imaging.ImageCollection())
    {
        // add PPTX document to the image collection
        images.Add(pptxFileName);

        // create PNG encoder
        using (Vintasoft.Imaging.Codecs.Encoders.PngEncoder pngEncoder =
            new Vintasoft.Imaging.Codecs.Encoders.PngEncoder())
        {
            // for each page in PPTX document
            for (int i = 0; i < images.Count; i++)
            {
                // save rendered image to a PNG file
                images[i].Save(string.Format("page{0}.png", i), pngEncoder);
            }
        }

        // dispose images
        images.ClearAndDisposeItems();
    }
}


Конвертация PPTX файла в SVG файлы

Процесс конвертации PPTX файла в SVG файлы состоит из следующих шагов:

Вот C# код, который демонстрирует как сконвертировать PPTX файл в SVG файлы:
/// <summary>
/// Converts PPTX document to the SVG files using ImageCollection and SvgEncoder classes.
/// </summary>
public static void ConvertPptxToSvg(string pptxFileName)
{
    // specify that VintaSoft Imaging .NET SDK should use GDI+ for drawing of 2D graphics
    Vintasoft.Imaging.Drawing.Gdi.GdiGraphicsFactory.SetAsDefault();
    // specify that VintaSoft Imaging .NET SDK should use SkiaSharp for drawing of 2D graphics
    //Vintasoft.Imaging.Drawing.SkiaSharp.SkiaSharpDrawingFactory.SetAsDefault();

    // create image collection
    using (Vintasoft.Imaging.ImageCollection images = new Vintasoft.Imaging.ImageCollection())
    {
        // add PPTX document to the image collection
        images.Add(pptxFileName);

        // create SVG encoder
        using (Vintasoft.Imaging.Codecs.Encoders.SvgEncoder svgEncoder =
            new Vintasoft.Imaging.Codecs.Encoders.SvgEncoder())
        {
            // specify that SVG encoder should compress embedded image using PNG compression
            svgEncoder.Settings.EmbeddedImageEncoder = new Vintasoft.Imaging.Codecs.Encoders.PngEncoder();

            // for each page in PPTX document
            for (int i = 0; i < images.Count; i++)
            {
                // save page to SVG file
                images[i].Save(string.Format("page{0}.svg", i), svgEncoder);
            }
        }

        // dispose images
        images.ClearAndDisposeItems();
    }
}