VintaSoft Imaging .NET SDK 15.0: Документация для Веб разработчика
В этом разделе
    Конвертация PDF файла в DOCX-файл в приложении "ASP.NET Core Web App (Model-View-Controller)"
    В этом разделе
    В этом руководстве показано, как создать пустое приложение "ASP.NET Core Web App (Model-View-Controller)" в Visual Studio .NET 2026 и сконвертировать PDF файл в файл DOCX в ASP.NET приложении Core.

    Вот шаги, которые необходимо выполнить:
    1. Создайте пустое приложение "ASP.NET Core Web App (Model-View-Controller)".

      Откройте Visual Studio .NET 2026 и создайте новый проект типа приложения "ASP.NET Core Web App (Model-View-Controller)":

      Настройте проект для использования .NET 10.0:

    2. Серверная сторона: Добавьте ссылки на nuget-пакеты Vintasoft в приложение ASP.NET Core.

      Добавьте ссылки на nuget-пакеты "Vintasoft.Imaging.AspNetCore.ApiControllers", "Vintasoft.Imaging.Pdf.Office", "Vintasoft.Imaging.Office.OpenXml", "Vintasoft.Imaging.Drawing.SkiaSharp", "System.IO.Packaging" в приложение ASP.NET Core. Другие необходимые nuget-пакеты будут добавлены автоматически.



    3. Серверная сторона: Создайте веб сервис, позволяющий конвертировать файлы.

      • Создайте веб сервис, позволяющий загружать/скачивать файл

        • Нажмите правую кнопку мыши на папке "Controllers" и выберите меню "Add => Controller..." из контекстного меню
        • Выберите шаблон "Empty API controller", задайте имя контроллера "MyVintasoftFileConverterApiController" и нажмите кнопку "Добавить".
        • Укажите, что класс MyVintasoftFileConverterApiController является производным от класса VintasoftFileConverterApiController.

          Вот исходный код класса MyVintasoftFileConverterApiController:
          namespace WebApplication1.Controllers
          {
              public class MyVintasoftFileConverterApiController : Vintasoft.Imaging.AspNetCore.ApiControllers.VintasoftFileConverterApiController
              {
          
                  public MyVintasoftFileConverterApiController(IWebHostEnvironment hostingEnvironment)
                      : base(hostingEnvironment)
                  {
                  }
          
              }
          }
          
          
    4. Клиентская сторона: Добавьте JavaScript-библиотеки в проект.

      • Добавьте папку "wwwroot\lib\Vintasoft" в приложение ASP.NET Core.

      • Скопируйте файлы Vintasoft.Shared.js и Vintasoft.Imaging.js из папки "<InstallPath>\VintaSoft Imaging .NET 15.0\Bin\JavaScript\" в папку "wwwroot\lib\Vintasoft\".

    5. Клиентская сторона: Добавьте код JavaScript, позволяющий преобразовать PDF-файл в DOCX-файл.

      • Создайте папку "wwwroot\UploadedImageFiles\SessionID" и скопируйте в нее тестовый PDF документ. Этот файл будет преобразован в DOCX-файл.

      • Откройте файл "Views\Home\Index.cshtml" и добавьте ссылки на используемые библиотеки JavaScript.


        Вот HTML-код, который добавляет ссылки на Vintasoft JavaScript-файлы:
        <script src="~/lib/Vintasoft/Vintasoft.Shared.js" type="text/javascript"></script>
        <script src="~/lib/Vintasoft/Vintasoft.Imaging.js" type="text/javascript"></script>
        
        

      • Откройте файл "wwwroot\js\site.js" и добавьте в него JavaScript-код, который преобразует PDF-файл в DOCX-файл:

        Вот код JavaScript, который преобразует PDF-файл в файл DOCX:
        // convert PDF file to a DOCX file
        __convertPdfToDocx("VintasoftImagingDemo.pdf");
        
        
        /**
         * Converts PDF file to a DOCX file.
         */
        function __convertPdfToDocx(fileId) {
            // set the session identifier
            Vintasoft.Shared.WebImagingEnviromentJS.set_SessionId("SessionID");
        
            // specify web service, which should be used by file converter
            Vintasoft.Shared.WebServiceJS.defaultConverterService =
                new Vintasoft.Shared.WebServiceControllerJS("/vintasoft/api/MyVintasoftFileConverterApi");
        
            // create the web file converter
            var fileConverter = new Vintasoft.Imaging.WebFileConverterJS(100);
            // subscribe to the events of web file converter
            Vintasoft.Shared.subscribeToEvent(fileConverter, "started", __fileConverter_started);
            Vintasoft.Shared.subscribeToEvent(fileConverter, "progress", __fileConverter_progress);
            Vintasoft.Shared.subscribeToEvent(fileConverter, "finished", __fileConverter_finished);
        
            // create object that contains parameters of file conversion process
            var fileConverterParams = {
                // identifier of PDF file in folder "wwwroot\UploadedImageFiles\SessionID"
                fileId: fileId,
                // password to a PDF file
                password: "",
                // the rendering settings that should be used for rendering of PDF file
                renderingSettings: new Vintasoft.Shared.WebRenderingSettingsJS(new Vintasoft.Shared.WebResolutionJS(300, 300)),
                // the encoder settings that should be used for encoding of DOCX file
                encoderSettings: new Vintasoft.Imaging.WebDocxEncoderSettingsJS(),
                // specify that result file should be saved in folder "wwwroot\UploadedImageFiles\SessionID"
                createFileInCacheFolder: false
            };
            // start the asynchronous file conversion process
            fileConverter.convertFileTo(fileConverterParams, __fileConverter_success, __fileConverter_error);
        }
        
        /**
         * File conversion process is started successfully.
         */
        function __fileConverter_success(eventArgs) {
        }
        
        /**
         * File conversion process is NOT started.
         */
        function __fileConverter_error(eventArgs) {
            alert("Error: " + eventArgs.message);
        }
        
        /**
         * File conversion is started.
         */
        function __fileConverter_started() {
        }
        
        /**
         * File conversion is in progress.
         */
        function __fileConverter_progress(event, status) {
        }
        
        /**
         * File conversion is finished.
         */
        function __fileConverter_finished(event, status) {
            // if file is converted successfully
            if (status.resultFilesIds != null) {
                alert("File 'VintasoftImagingDemo.pdf' is successfully converted to the file '" + status.resultFilesIds[0] + "'.");
            }
            // if error occurred
            if (status.errorMessage != null) {
                alert("Error: " + status);
            }
        }
        
        
    6. Запустите приложение ASP.NET Core и посмотрите результат.



      Сконвертированный файл DOCX "VintasoftImagingDemo.docx" можно найти в папке "wwwroot\UploadedImageFiles\SessionID\".