{"id":3498,"date":"2018-06-18T07:31:48","date_gmt":"2018-06-18T06:31:48","guid":{"rendered":"https:\/\/code-maze.com\/?p=3498"},"modified":"2024-01-31T15:17:08","modified_gmt":"2024-01-31T14:17:08","slug":"create-pdf-dotnetcore","status":"publish","type":"post","link":"https:\/\/code-maze.com\/create-pdf-dotnetcore\/","title":{"rendered":"How to Easily Create a PDF Document in ASP.NET Core Web API"},"content":{"rendered":"<p>Let\u2019s imagine that we have a .NET Core Web API project in which we need to generate a PDF report. Even though it shouldn\u2019t suppose to be too hard to do something like that, we could end up losing too much time if we don\u2019t know how to do it properly.<\/p>\n<p>In this article, we are going to show how to use the <code>DinkToPDF<\/code> library to easily generate PDF documents while working on the .NET Core Web API project.<\/p>\n<p>So, without further ado, let\u2019s dive right into the fun part.<\/p>\n<ul id=\"series_parts\" style=\"display: none;\">\n<li><a href=\"https:\/\/code-maze.com\/global-error-handling-aspnetcore\/\" target=\"_blank\" rel=\"noopener noreferrer\">Global Error Handling in .NET Core Web API<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/action-filters-aspnetcore\/\" target=\"_blank\" rel=\"noopener noreferrer\">Implementing Action Filters in ASP.NET Core Web API<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/authentication-aspnetcore-jwt-1\/\" target=\"_blank\" rel=\"noopener noreferrer\">ASP.NET Core Authentication with JWT and Angular<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/async-generic-repository-pattern\/\" target=\"_blank\" rel=\"noopener noreferrer\">Async Generic Repository Pattern in .NET Core<\/a><\/li>\n<li><a href=\"https:\/\/code-maze.com\/visual-studio-productivity\/\" target=\"_blank\" rel=\"noopener noreferrer\">Basic Tips and Tricks to Boost Productivity in Visual Studio<\/a><\/li>\n<\/ul>\n<hr \/>\r\n<p style=\"text-align: center;\"><strong>VIDEO<\/strong>: How to Easily Create a PDF Document in ASP.NET Core Web API video.<\/p>\r\n<p style=\"text-align: center;\"><iframe width=\"560\" height=\"315\" src=https:\/\/www.youtube.com\/embed\/J8Ff57Jj6t8 frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\r\n<hr \/>\n<p>You can download the source code for this article at <a href=\"https:\/\/github.com\/CodeMazeBlog\/create-pdf-with-netcore\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Creating PDF Document Source Code<\/a>.<\/p>\n<p>In this post, we are going to cover:<\/p>\n<ul>\n<li><a href=\"#projectpreparation\">Basic Project Preparations<\/a><\/li>\n<li><a href=\"#dinktopdfconfiguration\">DinkToPdf Library Configuration<\/a><\/li>\n<li><a href=\"#preparingdata\">Preparing Data for the PDF Document<\/a><\/li>\n<li><a href=\"#savingpdftolocalstorage\">Saving the PDF Document on the Local Storage<\/a><\/li>\n<li><a href=\"#pdfinbrowser\">Showing a PDF Document in a Browser<\/a><\/li>\n<li><a href=\"#pdfcontentfromhtmlpage\">Using Existing HTML Page to Generate PDF Content<\/a><\/li>\n<li><a href=\"#enabledownload\">Enabling Download Mode<\/a><\/li>\n<li><a href=\"#deployment\">Update Project For Deployment<\/a><\/li>\n<li><a href=\"#conclusion\">Conclusion<\/a><\/li>\n<\/ul>\n<h2 id=\"projectpreparation\">Basic Project Preparations<\/h2>\n<p>Let\u2019s start, by creating a brand new .NET Core 3.0 Web API project named <code>PDF_Generator<\/code>:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/Creating-project-for-.NET-Core-Web-API-PDF-Document-Creation.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-58409 size-full\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/Creating-project-for-.NET-Core-Web-API-PDF-Document-Creation.png\" alt=\"Creating project for .NET Core Web API PDF Document Creation\" width=\"742\" height=\"437\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/Creating-project-for-.NET-Core-Web-API-PDF-Document-Creation.png 742w, https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/Creating-project-for-.NET-Core-Web-API-PDF-Document-Creation-300x177.png 300w\" sizes=\"auto, (max-width: 742px) 100vw, 742px\" \/><\/a><\/p>\n<p>After the project creation, we are going to modify the <code>launchSettings.json<\/code> file to disable our browser to start automatically:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">{\r\n  \"profiles\": {\r\n    \"PDF_Generator\": {\r\n      \"commandName\": \"Project\",\r\n      \"launchBrowser\": false,\r\n      \"applicationUrl\": \"https:\/\/localhost:5001;http:\/\/localhost:5000\",\r\n      \"environmentVariables\": {\r\n        \"ASPNETCORE_ENVIRONMENT\": \"Development\"\r\n      }\r\n    }\r\n  }\r\n}\r\n<\/pre>\n<h2 id=\"dinktopdfconfiguration\">DinkToPdf Library Configuration<\/h2>\n<p><code>DinkToPdf<\/code> is a cross-platform oriented library which is the wrapper for the Webkit HTML to PDF library. It uses the WebKit engine to convert HTML to PDF.<\/p>\n<p>It will allow us to create a PDF document from our HTML string that we generate in the .NET Core project, or to create a PDF document from an existing HTML page. Furthermore, we can download the created PDF document or save it on a certain location or return a new HTML page with the PDF content.<\/p>\n<p>We are going to cover all these features in this article.<\/p>\n<p>So, let\u2019s install the <code>DinkToPdf<\/code> library first:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">PM&gt; Install-Package DinkToPdf<\/pre>\n<p>Or search for <code>DinkToPdf<\/code> inside the Nuget Package window:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/02-Nuget-Package.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-3489 size-full\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/02-Nuget-Package.png\" alt=\"Nuget package .NET Core PDF Creation\" width=\"663\" height=\"211\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/02-Nuget-Package.png 663w, https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/02-Nuget-Package-600x191.png 600w, https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/02-Nuget-Package-300x95.png 300w\" sizes=\"auto, (max-width: 663px) 100vw, 663px\" \/><\/a><\/p>\n<p>After the installation completes, we need to import native library files to our root project. We can find those files in our source project in the NativeLibrary folder. Inside we will find two folders <code>32bit<\/code> and <code>64bit<\/code>, so we need to choose the appropriate library for our OS. We are going to choose the files from the 64bit folder:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/03-Native-Library.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3490\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/03-Native-Library.png\" alt=\"Native library files\" width=\"227\" height=\"134\" \/><\/a><\/p>\n<p>Finally, we need to register this library with our IoC container in the <code>StartUp<\/code> class:<\/p>\n<p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-highlight=\"3\" data-enlighter-title=\"\">public void ConfigureServices(IServiceCollection services)\r\n{\r\n    services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools()));\r\n\r\n    services.AddControllers();\r\n}\r\n<\/pre><\/p>\n<p>To learn in more detail about service registration in .NET Core and how to keep Startup methods cleaner, you can read the <a href=\"https:\/\/code-maze.com\/net-core-web-development-part2\/\" target=\"_blank\" rel=\"noopener noreferrer\">.NET Core Service Configuration.<\/a><\/p>\n<p>Excellent.<\/p>\n<p>We have everything in place and we are ready to proceed.<\/p>\n<h2 id=\"preparingdata\">Preparing Data for the PDF Document<\/h2>\n<p>In a real-world project, we can collect data from the database or receive it from other API. But for the sake of simplicity, we are going to collect data for our PDF document from the local storage. Then we are going to create an HTML template and store it in the PDF document.<\/p>\n<p>So let\u2019s first create a new folder <code>Models<\/code> and inside it the <code>Employee.cs<\/code> file:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">namespace PDF_Generator.Models\r\n{\r\n    public class Employee\r\n    {\r\n        public string Name { get; set; }\r\n        public string LastName { get; set; }\r\n        public int Age { get; set; }\r\n        public string Gender { get; set; }\r\n    }\r\n}\r\n<\/pre>\n<p>To continue, we are going to create a new folder <code>Utility<\/code> and two class files inside it <code>DataStoage.cs<\/code> and <code>TemplateGenerator.cs<\/code>. A complete structure should look like this:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/04-Utility-Folder-Structure.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3491\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/04-Utility-Folder-Structure.png\" alt=\"Utility Folder Structure\" width=\"207\" height=\"162\" \/><\/a><\/p>\n<p>Now, let\u2019s modify the <code>DataStorage.cs<\/code> file:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">using PDF_Generator.Models;\r\nusing System.Collections.Generic;\r\n\r\nnamespace PDF_Generator.Utility\r\n{\r\n    public static class DataStorage\r\n    {\r\n        public static List&lt;Employee&gt; GetAllEmployees() =&gt;\r\n            new List&lt;Employee&gt;\r\n            {\r\n                new Employee { Name=\"Mike\", LastName=\"Turner\", Age=35, Gender=\"Male\"},\r\n                new Employee { Name=\"Sonja\", LastName=\"Markus\", Age=22, Gender=\"Female\"},\r\n                new Employee { Name=\"Luck\", LastName=\"Martins\", Age=40, Gender=\"Male\"},\r\n                new Employee { Name=\"Sofia\", LastName=\"Packner\", Age=30, Gender=\"Female\"},\r\n                new Employee { Name=\"John\", LastName=\"Doe\", Age=45, Gender=\"Male\"}\r\n            };\r\n    }\r\n}<\/pre>\n<p>In this code, we just return a list of employees that will be displayed inside the HTML template.<\/p>\n<h3>HTML Template Generation<\/h3>\n<p>We want to generate an HTML template, so we need to modify the <code>TemplateGenerator.cs<\/code> file:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">using System.Text;\r\n\r\nnamespace PDF_Generator.Utility\r\n{\r\n    public static class TemplateGenerator\r\n    {\r\n        public static string GetHTMLString()\r\n        {\r\n            var employees = DataStorage.GetAllEmployess();\r\n\r\n            var sb = new StringBuilder();\r\n            sb.Append(@\"\r\n                        &lt;html&gt;\r\n                            &lt;head&gt;\r\n                            &lt;\/head&gt;\r\n                            &lt;body&gt;\r\n                                &lt;div class='header'&gt;&lt;h1&gt;This is the generated PDF report!!!&lt;\/h1&gt;&lt;\/div&gt;\r\n                                &lt;table align='center'&gt;\r\n                                    &lt;tr&gt;\r\n                                        &lt;th&gt;Name&lt;\/th&gt;\r\n                                        &lt;th&gt;LastName&lt;\/th&gt;\r\n                                        &lt;th&gt;Age&lt;\/th&gt;\r\n                                        &lt;th&gt;Gender&lt;\/th&gt;\r\n                                    &lt;\/tr&gt;\");\r\n\r\n            foreach (var emp in employees)\r\n            {\r\n                sb.AppendFormat(@\"&lt;tr&gt;\r\n                                    &lt;td&gt;{0}&lt;\/td&gt;\r\n                                    &lt;td&gt;{1}&lt;\/td&gt;\r\n                                    &lt;td&gt;{2}&lt;\/td&gt;\r\n                                    &lt;td&gt;{3}&lt;\/td&gt;\r\n                                  &lt;\/tr&gt;\", emp.Name, emp.LastName, emp.Age, emp.Gender);\r\n            }\r\n\r\n            sb.Append(@\"\r\n                                &lt;\/table&gt;\r\n                            &lt;\/body&gt;\r\n                        &lt;\/html&gt;\");\r\n\r\n            return sb.ToString();\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<p>So, we are fetching data from our static <code>DataStorage<\/code> class and fill our template with it. The HTML template is nothing more than a pure HTML code.<\/p>\n<p>But we want to style our table and h1 tag as well, so let\u2019s create the new folder <code>assets<\/code> and inside it the new <code>styles.css<\/code> file and modify it:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"scss\">.header {\r\n    text-align: center;\r\n    color: green;\r\n    padding-bottom: 35px;\r\n}\r\n\r\ntable {\r\n    width: 80%;\r\n    border-collapse: collapse;\r\n}\r\n\r\ntd, th {\r\n    border: 1px solid gray;\r\n    padding: 15px;\r\n    font-size: 22px;\r\n    text-align: center;\r\n}\r\n\r\ntable th {\r\n    background-color: green;\r\n    color: white;\r\n}<\/pre>\n<p>This CSS file is going to be loaded later in the Controller class.<\/p>\n<p>That is it, we have our HTML template to use for the PDF creation. Now, we can continue to the Controller logic.<\/p>\n<h2 id=\"savingpdftolocalstorage\">Saving the PDF Document on the Local Storage<\/h2>\n<p>In the <code>Controllers<\/code> folder, we are going to create a new empty API controller <code>PdfCreatorController<\/code>:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">namespace PDF_Generator.Controllers\r\n{\r\n    [Route(\"api\/pdfcreator\")]\r\n    [ApiController]\r\n    public class PdfCreatorController : ControllerBase\r\n    {\r\n    }\r\n}\r\n<\/pre>\n<p>Now, let\u2019s\u00a0modify the <code>PdfCreatorController<\/code> class to support the creation and saving a PDF document to a local drive:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">using DinkToPdf;\r\nusing DinkToPdf.Contracts;\r\nusing Microsoft.AspNetCore.Mvc;\r\nusing PDF_Generator.Utility;\r\nusing System.IO;\r\n\r\nnamespace PDF_Generator.Controllers\r\n{\r\n    [Route(\"api\/pdfcreator\")]\r\n    [ApiController]\r\n    public class PdfCreatorController : ControllerBase\r\n    {\r\n        private IConverter _converter;\r\n\r\n        public PdfCreatorController(IConverter converter)\r\n        {\r\n            _converter = converter;\r\n        }\r\n\r\n        [HttpGet]\r\n        public IActionResult CreatePDF()\r\n        {\r\n            var globalSettings = new GlobalSettings\r\n            {\r\n                ColorMode = ColorMode.Color,\r\n                Orientation = Orientation.Portrait,\r\n                PaperSize = PaperKind.A4,\r\n                Margins = new MarginSettings { Top = 10 },\r\n                DocumentTitle = \"PDF Report\",\r\n                Out = @\"D:\\PDFCreator\\Employee_Report.pdf\"\r\n            };\r\n\r\n            var objectSettings = new ObjectSettings\r\n            {\r\n                PagesCount = true,\r\n                HtmlContent = TemplateGenerator.GetHTMLString(),\r\n                WebSettings = { DefaultEncoding = \"utf-8\", UserStyleSheet =  Path.Combine(Directory.GetCurrentDirectory(), \"assets\", \"styles.css\") },\r\n                HeaderSettings = { FontName = \"Arial\", FontSize = 9, Right = \"Page [page] of [toPage]\", Line = true },\r\n                FooterSettings = { FontName = \"Arial\", FontSize = 9, Line = true, Center = \"Report Footer\" }\r\n            };\r\n\r\n            var pdf = new HtmlToPdfDocument()\r\n            {\r\n                GlobalSettings = globalSettings,\r\n                Objects = { objectSettings }\r\n            };\r\n\r\n            _converter.Convert(pdf);\r\n\r\n            return Ok(\"Successfully created PDF document.\");\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<h3>Code Explanation<\/h3>\n<p>In the code above we first inject our registered Converter with the Dependency Injection inside our constructor by using <code>IConverter<\/code> interface. Then we create two objects <code>globalSettings<\/code> and <code>objectSettings<\/code> and use them as a configuration in the <code>HtmlToPdfDcoument<\/code>property. Finally, we convert our pdf configuration into a real PDF Document on our local machine.<\/p>\n<p>Now let\u2019s talk about the <code>GlobalSettings<\/code> and <code>ObjectSettings<\/code> classes.<\/p>\n<h3>About the GlobalSettings Class<\/h3>\n<p>The <code>GlobalSettings<\/code> class consists of the overall configuration properties for the PDF document. We use just a couple of those properties to set up the color mode, orientation, paper size, document title, etc\u2026 but if we go to the implementation of the <code>GlobalSettings<\/code> class we can find more of those properties.<\/p>\n<p>The <strong>Out<\/strong> property is very important if we want to save our files on a local machine. So we need to set it to the path where we want our document to. If we set the <code>Out<\/code> property then we can use <code>_converter.Convert(pdf);<\/code> to convert our document. We will see how this will change once we try to show our PDF document inside a browser.<\/p>\n<p>One more important note is that\u00a0all the folders from the <span style=\"color: #ff6600;\"><code>Out<\/code><\/span> path should be previously created or the\u00a0conversion won\u2019t work. So in our example where we create a PDF document in the <code>D:<\/code> drive in the\u00a0<code>PDFCreator<\/code> folder, we had to create the <code>PDFCreator<\/code> folder prior to PDF document creation.<\/p>\n<h3>About the ObjectSettings Class<\/h3>\n<p>The <code>ObjectSettings<\/code> class consists of the properties related to the contents of the PDF document. So, we can configure the visibility of the page counter,\u00a0formatting of headers and footers,\u00a0the body content of our document (<code>HtmlContent<\/code> property) or the web settings for our document.<\/p>\n<p>Of course, these are not all of the configuration properties but that&#8217;s all we need for this article.<\/p>\n<p>The <code>HtmlContent<\/code> property is the very important property of this class. It contains our generated HTML template and shows the main body of a PDF document.<\/p>\n<p><code>WebSettings<\/code> is pretty important as well, especially if we have an external CSS file for the styling as we do. In this property, we can configure the encoding of our document and provide the path to our CSS file. If we inspect this property, we are going to find out more settings that we can configure like the background of a PDF document or if we should load images or what the minimum font size is, etc\u2026<\/p>\n<h3>Inspecting Results<\/h3>\n<p>Let\u2019s start our app, open our browser and send a simple request towards our PDF creator endpoint:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/Successfully-created-PDF.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-49572 size-full\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/Successfully-created-PDF.png\" alt=\"Request for PDF creation\" width=\"332\" height=\"112\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/Successfully-created-PDF.png 332w, https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/Successfully-created-PDF-300x101.png 300w\" sizes=\"auto, (max-width: 332px) 100vw, 332px\" \/><\/a><\/p>\n<p>As a result, we have our document created in the PDFCreator folder:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/06-Created-document.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-3493 size-full\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/06-Created-document.png\" alt=\"Created document .NET Core PDF Creation\" width=\"408\" height=\"171\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/06-Created-document.png 408w, https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/06-Created-document-300x126.png 300w\" sizes=\"auto, (max-width: 408px) 100vw, 408px\" \/><\/a><\/p>\n<p>And let\u2019s inspect the content of the document:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/07-PDF-Content.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-3494 size-large\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/07-PDF-Content-1024x379.png\" alt=\"PDF Content .NET Core PDF Creation\" width=\"1024\" height=\"379\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/07-PDF-Content-1024x379.png 1024w, https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/07-PDF-Content-600x222.png 600w, https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/07-PDF-Content-300x111.png 300w, https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/07-PDF-Content-768x284.png 768w, https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/07-PDF-Content.png 1027w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<p>That is awesome.<\/p>\n<p>We can now continue on.<\/p>\n<h2 id=\"pdfinbrowser\">Showing a PDF Document in a Browser<\/h2>\n<p>If we want to show our document in a browser instead, we can configure that quite easily.<\/p>\n<p>First, we need to <strong>remove<\/strong> the <code>Out<\/code> property from the <code>globalSettings<\/code> object.<\/p>\n<p>Then instead of this type of conversion:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">_converter.Convert(pdf);<\/pre>\n<p>We are going to use this type:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var file = _converter.Convert(pdf);<\/pre>\n<p>Why is that?<\/p>\n<p>Well as we said if we use the <code>Out<\/code> property then the file is sent to stdout and saved to our local machine. But without the <code>Out<\/code> property, our output will be stored in a buffer. While converting we need to create a byte array and store it inside the <code>file<\/code> variable.<\/p>\n<p>Finally, we are using that <code>file<\/code> variable and return it to the requester with a content type.<\/p>\n<p>This is our <code>CreatePDF()<\/code> method after modification:<\/p>\n<p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-highlight=\"28,29\" data-enlighter-title=\"\">[HttpGet]\r\npublic IActionResult CreatePDF()\r\n{\r\n    var globalSettings = new GlobalSettings\r\n    {\r\n        ColorMode = ColorMode.Color,\r\n        Orientation = Orientation.Portrait,\r\n        PaperSize = PaperKind.A4,\r\n        Margins = new MarginSettings { Top = 10 },\r\n        DocumentTitle = &quot;PDF Report&quot;\r\n    };\r\n\r\n    var objectSettings = new ObjectSettings\r\n    {\r\n        PagesCount = true,\r\n        HtmlContent = TemplateGenerator.GetHTMLString(),\r\n        WebSettings = { DefaultEncoding = &quot;utf-8&quot;, UserStyleSheet =  Path.Combine(Directory.GetCurrentDirectory(), &quot;assets&quot;, &quot;styles.css&quot;) },\r\n        HeaderSettings = { FontName = &quot;Arial&quot;, FontSize = 9, Right = &quot;Page [page] of [toPage]&quot;, Line = true },\r\n        FooterSettings = { FontName = &quot;Arial&quot;, FontSize = 9, Line = true, Center = &quot;Report Footer&quot; }\r\n     };\r\n\r\n     var pdf = new HtmlToPdfDocument()\r\n     {\r\n        GlobalSettings = globalSettings,\r\n        Objects = { objectSettings }\r\n     };\r\n\r\n     var file = _converter.Convert(pdf);\r\n     return File(file, &quot;application\/pdf&quot;);\r\n}\r\n<\/pre><\/p>\n<p>And this is the result:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/PDF-in-a-browser.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-49573 size-full\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/PDF-in-a-browser.png\" alt=\"PDF browser content .NET Core PDF Creation\" width=\"878\" height=\"395\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/PDF-in-a-browser.png 878w, https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/PDF-in-a-browser-300x135.png 300w, https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/PDF-in-a-browser-768x346.png 768w\" sizes=\"auto, (max-width: 878px) 100vw, 878px\" \/><\/a><\/p>\n<h2 id=\"pdfcontentfromhtmlpage\">Using Existing HTML Page to Generate PDF Content<\/h2>\n<p>We don\u2019t have to use our custom HTML template to generate PDF content, we can use an existing HTML page. The effort is minimal. All we have to do is to <strong>remove<\/strong> the <code>HtmlContent<\/code> property and <strong>add<\/strong> the <code>Page<\/code> property of the <code>ObjectSettings<\/code> class.<\/p>\n<p>So instead of this code:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">HtmlContent = TemplateGenerator.GetHTMLString()<\/pre>\n<p>let\u2019s add this code:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">Page = \"https:\/\/code-maze.com\/\"<\/pre>\n<p>And let\u2019s inspect the result:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/New-web-page-in-pdf.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-49574 size-full\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/New-web-page-in-pdf.png\" alt=\"PDF browser HTML page .NET Core PDF Creation\" width=\"867\" height=\"639\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/New-web-page-in-pdf.png 867w, https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/New-web-page-in-pdf-300x221.png 300w, https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/New-web-page-in-pdf-768x566.png 768w\" sizes=\"auto, (max-width: 867px) 100vw, 867px\" \/><\/a><\/p>\n<h2 id=\"enabledownload\">Enabling Download Mode<\/h2>\n<p>If we want to enable the download feature for the PDF document we need to modify our <code>return<\/code> statement in our action method. All we have to do is simply add the name of the file with its extension to the <code>return<\/code> statement:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">return File(file, \"application\/pdf\", \"EmployeeReport.pdf\");<\/pre>\n<p>As a result, we are going to have our file downloaded:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/10-PDF-downloaded-file.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3497\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/10-PDF-downloaded-file.png\" alt=\"PDF downloaded file\" width=\"298\" height=\"51\" \/><\/a><\/p>\n<p>And there it is.<\/p>\n<p>Everything is working as it supposed to.<\/p>\n<h2 id=\"deployment\">Update Project For Deployment<\/h2>\n<p>If we want to deploy this application, we have to make some changes. Let&#8217;s do that step by step.<\/p>\n<p>First, in the <code>Utility<\/code> folder we are going to add a new class\u00a0<code>CustomAssemblyLoadContext<\/code> and modify it:<\/p>\n<pre  class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">internal class CustomAssemblyLoadContext : AssemblyLoadContext\r\n{\r\n    public IntPtr LoadUnmanagedLibrary(string absolutePath)\r\n    {\r\n        return LoadUnmanagedDll(absolutePath);\r\n    }\r\n    protected override IntPtr LoadUnmanagedDll(string unmanagedDllName)\r\n    {\r\n        return LoadUnmanagedDllFromPath(unmanagedDllName);\r\n    }\r\n\r\n    protected override Assembly Load(AssemblyName assemblyName)\r\n    {\r\n        throw new NotImplementedException();\r\n    }\r\n}<\/pre>\n<p>After that, let&#8217;s modify the <code>ConfigureServices<\/code> method in the <code>StartUp<\/code> class:<\/p>\n<p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\" data-enlighter-highlight=\"3-4\" data-enlighter-title=\"\">public void ConfigureServices(IServiceCollection services)\r\n{\r\n    var context = new CustomAssemblyLoadContext(); \r\n    context.LoadUnmanagedLibrary(Path.Combine(Directory.GetCurrentDirectory(), &quot;libwkhtmltox.dll&quot;));\r\n\r\n    services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools()));\r\n\r\n    services.AddControllers();\r\n}<\/pre><\/p>\n<p>In here, we are creating an instance of the <code>CustomAssemblyLoadContext<\/code> class and just call the <code>LoadUnmanagedLibrary<\/code> method with the path of the <code>libwkhtmltox.dll<\/code> file.<\/p>\n<p>We need to do one more thing. When we publish our application, we need to have the <code>libwkhtmltox.dll<\/code> file and the <code>styles.css<\/code> file in the published directory. To ensure that, right-click on the <code>dll<\/code> file\u00a0in <code>Solution Explorer<\/code> and choose <code>properties<\/code>.\u00a0 For the <code>Build Action<\/code> we are going to choose <code>Content<\/code> and for the <code>Copy to Output Directory<\/code>, we are going to choose <code>Copy always<\/code>. We need to repeat these steps for the CSS file as well:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/09\/properties-for-dll-file.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4430\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/09\/properties-for-dll-file.png\" alt=\"\" width=\"311\" height=\"191\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/09\/properties-for-dll-file.png 311w, https:\/\/code-maze.com\/wp-content\/uploads\/2018\/09\/properties-for-dll-file-300x184.png 300w\" sizes=\"auto, (max-width: 311px) 100vw, 311px\" \/><\/a><\/p>\n<p>Now, all we have to do is to publish our application by following one of these tutorials or both of them:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/net-core-web-development-part16\/\" target=\"_blank\" rel=\"noopener noreferrer\">.NET Core Application IIS Deployment<\/a><\/p>\n<p><a href=\"https:\/\/code-maze.com\/net-core-web-development-part17\/\" target=\"_blank\" rel=\"noopener noreferrer\">.NET Core Application Linux Deployment<\/a><\/p>\n<p>This is the result of the IIS deployment:<\/p>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/09\/published.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4431\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/09\/published.png\" alt=\"\" width=\"1001\" height=\"539\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/09\/published.png 1001w, https:\/\/code-maze.com\/wp-content\/uploads\/2018\/09\/published-600x323.png 600w, https:\/\/code-maze.com\/wp-content\/uploads\/2018\/09\/published-300x162.png 300w, https:\/\/code-maze.com\/wp-content\/uploads\/2018\/09\/published-768x414.png 768w\" sizes=\"auto, (max-width: 1001px) 100vw, 1001px\" \/><\/a><\/p>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>In this article, we have used the DinkToPdf library to create PDF documents while working with the .NET Core Web API project. We have created our PDFs in different ways to show many different features of this library.<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let\u2019s imagine that we have a .NET Core Web API project in which we need to generate a PDF report. Even though it shouldn\u2019t suppose to be too hard to do something like that, we could end up losing too much time if we don\u2019t know how to do it properly. In this article, we [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":54936,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[12,2079],"tags":[148,79,150,149,155,153,147,154,151,152],"class_list":["post-3498","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-csharp","category-web-api","tag-net-core-web-api-pdf-document-creation","tag-asp-net-core","tag-create-a-pdf-document-with-net-core-web-api","tag-dinktopdf","tag-dinktopdf-configuration","tag-download-pdf-document-net-core","tag-pdf-document","tag-pdf-generator","tag-save-pdf-on-local-storage","tag-show-pdf-in-browser","et-has-post-format-content","et_post_format-et-post-format-standard"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Easily Create a PDF Document in ASP.NET Core Web API<\/title>\n<meta name=\"description\" content=\"Find out how to easily create a PDF document in ASP.NET Core Web API. Play with configuration, save, download or show PDF document in a web browser.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/code-maze.com\/create-pdf-dotnetcore\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Easily Create a PDF Document in ASP.NET Core Web API\" \/>\n<meta property=\"og:description\" content=\"Find out how to easily create a PDF document in ASP.NET Core Web API. Play with configuration, save, download or show PDF document in a web browser.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code-maze.com\/create-pdf-dotnetcore\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Maze\" \/>\n<meta property=\"article:published_time\" content=\"2018-06-18T06:31:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-31T14:17:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/create-pdf-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"620\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Marinko Spasojevi\u0107\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/CodeMazeBlog\" \/>\n<meta name=\"twitter:site\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Marinko Spasojevi\u0107\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/code-maze.com\/create-pdf-dotnetcore\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/create-pdf-dotnetcore\/\"},\"author\":{\"name\":\"Marinko Spasojevi\u0107\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/d6fa06e66820968d19b39fb63cff2533\"},\"headline\":\"How to Easily Create a PDF Document in ASP.NET Core Web API\",\"datePublished\":\"2018-06-18T06:31:48+00:00\",\"dateModified\":\"2024-01-31T14:17:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/code-maze.com\/create-pdf-dotnetcore\/\"},\"wordCount\":1675,\"commentCount\":151,\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/create-pdf-dotnetcore\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/create-pdf-featured.png\",\"keywords\":[\".NET Core Web Api PDF Document Creation\",\"asp.net core\",\"Create a PDF document with .NET Core Web API\",\"DinkToPdf\",\"DinkToPdf Configuration\",\"Download PDF Document .NET Core\",\"PDF Document\",\"PDF Generator\",\"Save PDF on Local Storage\",\"Show PDF in Browser\"],\"articleSection\":[\"C#\",\"Web API\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/code-maze.com\/create-pdf-dotnetcore\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/code-maze.com\/create-pdf-dotnetcore\/\",\"url\":\"https:\/\/code-maze.com\/create-pdf-dotnetcore\/\",\"name\":\"How to Easily Create a PDF Document in ASP.NET Core Web API\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/code-maze.com\/create-pdf-dotnetcore\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/create-pdf-dotnetcore\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/create-pdf-featured.png\",\"datePublished\":\"2018-06-18T06:31:48+00:00\",\"dateModified\":\"2024-01-31T14:17:08+00:00\",\"description\":\"Find out how to easily create a PDF document in ASP.NET Core Web API. Play with configuration, save, download or show PDF document in a web browser.\",\"breadcrumb\":{\"@id\":\"https:\/\/code-maze.com\/create-pdf-dotnetcore\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/code-maze.com\/create-pdf-dotnetcore\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/create-pdf-dotnetcore\/#primaryimage\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/create-pdf-featured.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/create-pdf-featured.png\",\"width\":1100,\"height\":620,\"caption\":\"create-pdf-featured\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/code-maze.com\/create-pdf-dotnetcore\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/code-maze.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Easily Create a PDF Document in ASP.NET Core Web API\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/code-maze.com\/#website\",\"url\":\"https:\/\/code-maze.com\/\",\"name\":\"Code Maze\",\"description\":\"Learn. Code. Succeed.\",\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/code-maze.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/code-maze.com\/#organization\",\"name\":\"Code Maze\",\"url\":\"https:\/\/code-maze.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"width\":3511,\"height\":3510,\"caption\":\"Code Maze\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/CodeMazeBlog\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/d6fa06e66820968d19b39fb63cff2533\",\"name\":\"Marinko Spasojevi\u0107\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/marinko-1x1-3-150x150.jpg\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/marinko-1x1-3-150x150.jpg\",\"caption\":\"Marinko Spasojevi\u0107\"},\"description\":\"Hi, my name is Marinko Spasojevic. Currently, I work as a full-time .NET developer and my passion is web application development. Just getting something to work is not enough for me. To make it just how I like it, it must be readable, reusable, and easy to maintain. Prior to being an author on the CodeMaze blog, I had been working as a professor of Computer Science for several years. So, sharing knowledge while working as a full-time developer comes naturally to me.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/marinko-spasojevic\/\",\"https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog\"],\"url\":\"https:\/\/code-maze.com\/author\/marinko\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Easily Create a PDF Document in ASP.NET Core Web API","description":"Find out how to easily create a PDF document in ASP.NET Core Web API. Play with configuration, save, download or show PDF document in a web browser.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/code-maze.com\/create-pdf-dotnetcore\/","og_locale":"en_US","og_type":"article","og_title":"How to Easily Create a PDF Document in ASP.NET Core Web API","og_description":"Find out how to easily create a PDF document in ASP.NET Core Web API. Play with configuration, save, download or show PDF document in a web browser.","og_url":"https:\/\/code-maze.com\/create-pdf-dotnetcore\/","og_site_name":"Code Maze","article_published_time":"2018-06-18T06:31:48+00:00","article_modified_time":"2024-01-31T14:17:08+00:00","og_image":[{"width":1100,"height":620,"url":"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/create-pdf-featured.png","type":"image\/png"}],"author":"Marinko Spasojevi\u0107","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/CodeMazeBlog","twitter_site":"@CodeMazeBlog","twitter_misc":{"Written by":"Marinko Spasojevi\u0107","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/code-maze.com\/create-pdf-dotnetcore\/#article","isPartOf":{"@id":"https:\/\/code-maze.com\/create-pdf-dotnetcore\/"},"author":{"name":"Marinko Spasojevi\u0107","@id":"https:\/\/code-maze.com\/#\/schema\/person\/d6fa06e66820968d19b39fb63cff2533"},"headline":"How to Easily Create a PDF Document in ASP.NET Core Web API","datePublished":"2018-06-18T06:31:48+00:00","dateModified":"2024-01-31T14:17:08+00:00","mainEntityOfPage":{"@id":"https:\/\/code-maze.com\/create-pdf-dotnetcore\/"},"wordCount":1675,"commentCount":151,"publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"image":{"@id":"https:\/\/code-maze.com\/create-pdf-dotnetcore\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/create-pdf-featured.png","keywords":[".NET Core Web Api PDF Document Creation","asp.net core","Create a PDF document with .NET Core Web API","DinkToPdf","DinkToPdf Configuration","Download PDF Document .NET Core","PDF Document","PDF Generator","Save PDF on Local Storage","Show PDF in Browser"],"articleSection":["C#","Web API"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code-maze.com\/create-pdf-dotnetcore\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code-maze.com\/create-pdf-dotnetcore\/","url":"https:\/\/code-maze.com\/create-pdf-dotnetcore\/","name":"How to Easily Create a PDF Document in ASP.NET Core Web API","isPartOf":{"@id":"https:\/\/code-maze.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/code-maze.com\/create-pdf-dotnetcore\/#primaryimage"},"image":{"@id":"https:\/\/code-maze.com\/create-pdf-dotnetcore\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/create-pdf-featured.png","datePublished":"2018-06-18T06:31:48+00:00","dateModified":"2024-01-31T14:17:08+00:00","description":"Find out how to easily create a PDF document in ASP.NET Core Web API. Play with configuration, save, download or show PDF document in a web browser.","breadcrumb":{"@id":"https:\/\/code-maze.com\/create-pdf-dotnetcore\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code-maze.com\/create-pdf-dotnetcore\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/create-pdf-dotnetcore\/#primaryimage","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/create-pdf-featured.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2018\/06\/create-pdf-featured.png","width":1100,"height":620,"caption":"create-pdf-featured"},{"@type":"BreadcrumbList","@id":"https:\/\/code-maze.com\/create-pdf-dotnetcore\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code-maze.com\/"},{"@type":"ListItem","position":2,"name":"How to Easily Create a PDF Document in ASP.NET Core Web API"}]},{"@type":"WebSite","@id":"https:\/\/code-maze.com\/#website","url":"https:\/\/code-maze.com\/","name":"Code Maze","description":"Learn. Code. Succeed.","publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/code-maze.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/code-maze.com\/#organization","name":"Code Maze","url":"https:\/\/code-maze.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","width":3511,"height":3510,"caption":"Code Maze"},"image":{"@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/CodeMazeBlog"]},{"@type":"Person","@id":"https:\/\/code-maze.com\/#\/schema\/person\/d6fa06e66820968d19b39fb63cff2533","name":"Marinko Spasojevi\u0107","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/person\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/marinko-1x1-3-150x150.jpg","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/marinko-1x1-3-150x150.jpg","caption":"Marinko Spasojevi\u0107"},"description":"Hi, my name is Marinko Spasojevic. Currently, I work as a full-time .NET developer and my passion is web application development. Just getting something to work is not enough for me. To make it just how I like it, it must be readable, reusable, and easy to maintain. Prior to being an author on the CodeMaze blog, I had been working as a professor of Computer Science for several years. So, sharing knowledge while working as a full-time developer comes naturally to me.","sameAs":["https:\/\/www.linkedin.com\/in\/marinko-spasojevic\/","https:\/\/x.com\/https:\/\/twitter.com\/CodeMazeBlog"],"url":"https:\/\/code-maze.com\/author\/marinko\/"}]}},"_links":{"self":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/3498","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/comments?post=3498"}],"version-history":[{"count":2,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/3498\/revisions"}],"predecessor-version":[{"id":58410,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/3498\/revisions\/58410"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media\/54936"}],"wp:attachment":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media?parent=3498"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/categories?post=3498"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/tags?post=3498"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}