ComponentOne Web API Edition
Services / PDF Services / Configure PDF Web API Service
In This Topic
    Configure PDF Web API Service
    In This Topic

    PDF Web API enables you to build HTTP services, which can be consumed by a variety of clients for viewing, loading and caching PDF files. These are REST based API services, which communicate with the HTML 5 PDFViewer control to display the pdf file content on the web.

    Complete the following steps to setup PDF services.

    Create a new WebAPI application

    1. Open Visual Studio and Select Create a new project.
    2. In the Create a new project window, select C1 from the Project Types drop down and select C1 Web API Application for ASP.NET Core (.Net Framework) and click Next.
    3. Set a Name and Location for your application and click Create.
    4. In the ComponentOne ASP.NET Web API Application Wizard, select Pdf services option.

      ComponentOne ASP.NET Web API Application Wizard
    5. Once you have selected the Services from the wizard, click OK to create a new C1 Web API Service application.

    Back to Top

    Configure Startup.cs file

    1. Create a folder named PdfRoot, in your service application.
    2. Add the desired PDF files to the PdfRoot folder.
    3. From the Solution Explorer, select and open Startup.cs file.
    4. In the Startup.cs file, replace the existing code under Startup class with the following code.
      Copy Code
      public class Startup
              public Startup(IWebHostEnvironment env, IConfiguration config, ILoggerFactory loggerFactory)
                  Environment = env;
                  var builder = new ConfigurationBuilder()
                      .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                      .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
                  Configuration = builder.Build();
              public static IWebHostEnvironment Environment { get; set; }
              public IConfiguration Configuration { get; }
              //Add services to the container.
              public void ConfigureServices(IServiceCollection services)
                  // Add framework services.
                  //Grapecity API
                  services.AddMvc().ConfigureApplicationPartManager(manager =>
                      var afp = manager.FeatureProviders.First(iafp => iafp.GetType() == typeof(ControllerFeatureProvider));
                      if (afp != null)
                      manager.FeatureProviders.Add(new CustomControllerFeatureProvider());
                  // CORS support
                  services.AddCors(options =>
                        options.AddPolicy("AllowAll", builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
                  services.Configure<FormOptions>(options => options.ValueLengthLimit = int.MaxValue);
                  // Grapecity API
                  services.AddMvc(option => { option.EnableEndpointRouting = false; });
              // Configure the HTTP request pipeline.
              public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
                  //Grapecity API
                  var defaultCulture = "en-US";
                  IList<CultureInfo> supportedCultures = new List<CultureInfo>
                      new CultureInfo(defaultCulture)
                  app.UseRequestLocalization(new RequestLocalizationOptions
                      DefaultRequestCulture = new RequestCulture(defaultCulture),
                      SupportedCultures = supportedCultures,
                      SupportedUICultures = supportedCultures
                  //Grapecity API
                      .AddDiskStorage("PdfRoot", Path.Combine(env.WebRootPath, "Pdfs"));

      Notice that the disk storage is added in the Configure method of Startup using the AddDiskStorage method.

    Back to Top

    Build and Run the Project

    1. Click Build | Build Solution to build the project.
    2. Press F5 to run the project.

    Back to Top