Convert DOCX file to PDF file in an "ASP.NET Core Web App (Model-View-Controller)" application
In This Topic
This tutorial shows how to create a blank "ASP.NET Core Web App (Model-View-Controller)" application in Visual Studio .NET 2026 and convert DOCX file to a PDF file in ASP.NET Core application.
Here are steps, which must be done:
-
Create a blank "ASP.NET Core Web App (Model-View-Controller)" application.
Open Visual Studio .NET 2026 and create a new project, of "ASP.NET Core Web App (Model-View-Controller)" application type:
Configure the project to use .NET 10.0:
-
Server side: Add references to the Vintasoft nuget-packages to the ASP.NET Core application.
Add references to the nuget-packages "Vintasoft.Imaging.AspNetCore.ApiControllers", "Vintasoft.Imaging.Pdf.Office", "Vintasoft.Imaging.Office.OpenXml", "Vintasoft.Imaging.Drawing.SkiaSharp", "System.IO.Packaging" to the ASP.NET Core application. Other necessary nuget-packages will be added automatically.
-
Server side: Create web service, which allow to convert file.
-
Create web service that allows to upload/download file
-
Press the right mouse button on the "Controllers" folder and select the "Add => Controller..." menu from context menu
-
Select "Empty API controller" template, set the controller name to the "MyVintasoftFileConverterApiController" and press the "Add" button
-
Specify that MyVintasoftFileConverterApiController class is derived from VintasoftFileConverterApiController class
Here are source codes of MyVintasoftFileConverterApiController class:
namespace WebApplication1.Controllers
{
public class MyVintasoftFileConverterApiController : Vintasoft.Imaging.AspNetCore.ApiControllers.VintasoftFileConverterApiController
{
public MyVintasoftFileConverterApiController(IWebHostEnvironment hostingEnvironment)
: base(hostingEnvironment)
{
}
}
}
-
Client side: Add JavaScript libraries to the project.
-
Add the "wwwroot\lib\Vintasoft\" folder to ASP.NET Core application.
-
Copy Vintasoft.Shared.js and Vintasoft.Imaging.js files from "<InstallPath>\VintaSoft Imaging .NET 15.0\Bin\JavaScript\" folder into "wwwroot\lib\Vintasoft\" folder.
-
Client side: Add JavaScript code that allows to convert PDF file to a DOCX file.
-
Create folder "wwwroot\UploadedImageFiles\SessionID\" and copy test DOCX document to the folder. This file will be converted to a PDF file.
-
Open file "Views\Home\Index.cshtml" and add references to used JavaScript libraries.
Here is HTML code that adds references to the Vintasoft JavaScript files:
<script src="~/lib/Vintasoft/Vintasoft.Shared.js" type="text/javascript"></script>
<script src="~/lib/Vintasoft/Vintasoft.Imaging.js" type="text/javascript"></script>
-
Open file "wwwroot\js\site.js", add JavaScript code that converts DOCX file to a PDF file:
Here is JavaScript code that converts DOCX file to a PDF file:
// convert DOCX file to a PDF file
__convertDocxToPdf("DocxTestDocument.docx");
/**
* Converts DOCX file to a PDF file.
*/
function __convertDocxToPdf(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 DOCX file in folder "wwwroot\UploadedImageFiles\SessionID"
fileId: fileId,
// password to a DOCX file
password: "",
// the rendering settings that should be used for rendering of DOCX file
renderingSettings: new Vintasoft.Shared.WebRenderingSettingsJS(new Vintasoft.Shared.WebResolutionJS(300, 300)),
// the encoder settings that should be used for encoding PDF file
encoderSettings: new Vintasoft.Imaging.WebPdfEncoderSettingsJS(),
// specify that PDF 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 'DocxTestDocument.docx' is successfully converted to the file '" + status.resultFilesIds[0] + "'.");
}
// if error occurred
if (status.errorMessage != null) {
alert("Error: " + status);
}
}
-
Run the ASP.NET Core application and see the result.
Converted PDF file "DocxTestDocument.pdf" can be found in folder "wwwroot\UploadedImageFiles\SessionID\".