RAD PDF - Interactive Demonstrations

This implementation demonstrates how to use RAD PDF with ASP.NET 5 and ASP.NET Core

RAD PDF Sample Source Files

Pages\Shared\_Layout.cshtml


<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>@ViewData["Title"] - RadPdfNet5Demo</title>

    @Html.Raw(RadPdf.Web.UI.PdfWebControl.RenderHead())
</head>
<body>
    <div>
        @RenderBody()
    </div>
</body>
</html>

Pages\_ViewImports.cshtml


@using RadPdfNet5Demo
@namespace RadPdfNet5Demo.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

Pages\_ViewStart.cshtml


@{
    Layout = "_Layout";
}

Pages\Index.cshtml


@{
@page
@model RadPdfNet5Demo.Pages.BasicModel

@using RadPdf.Web.UI;

@*
    To use the Client API, the following code must be in the <head> element of your View's HTML:
    @Html.Raw(RadPdf.Web.UI.PdfWebControl.RenderHead())

    See: /Pages/Shared/_Layout.cshtml
*@

@{
    ViewData["Title"] = "Basic Example";

    // Get web control from ViewBag
    PdfWebControl pdfWebControl1 = ViewData["PdfWebControl1"] as PdfWebControl;

    // Set control's properties
    pdfWebControl1.ID = "PdfWebControl1"; // Important if Client API is to be used!
    pdfWebControl1.Height = "600px";
    pdfWebControl1.Width = "100%";
}

<h2>Basic</h2>

@* Render web control to body *@
@Html.Raw(pdfWebControl1.RenderControl())

Program.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace RadPdfNet5Demo
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });
        }
}

Startup.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

using RadPdf;

namespace RadPdfNet5Demo
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddRazorPages();

            //Default RAD PDF session provider relies on ASP.NET session state.
            //A custom session provider can be used to avoid use of this.
            services.AddSession();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseStaticFiles();

            app.UseRouting();

            // Default RAD PDF session provider relies on ASP.NET session state, so call this before .UseRadPdf()
            // A custom session provider can be used to avoid use of this.
            app.UseSession();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapRazorPages();
            });

            // Create middleware settings
            RadPdfCoreMiddlewareSettings settings = new RadPdfCoreMiddlewareSettings() { ConnectionString = "Server=.;Database=RadPdf;Trusted_Connection=Yes;", LicenseKey = "DEMO" };

            // Add RAD PDF's middleware to app
            app.UseRadPdf(settings);
        }
    }
}

RadPdfNet5Demo.csproj


<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="RadPdfCore" Version="3.19.5" />
  </ItemGroup>

</Project>
RAD PDF & PDFescape are Red Software products - ©2007-2021 Red Software