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.
Startup.cs |
Copy Code
|
---|---|
public class Startup { public Startup(IWebHostEnvironment env, IConfiguration config, ILoggerFactory loggerFactory) { Environment = env; var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) .AddEnvironmentVariables(); Configuration = builder.Build(); } public static IWebHostEnvironment Environment { get; set; } public IConfiguration Configuration { get; } //Add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc(); // Add framework services. //MESCIUS API services.AddMvc().ConfigureApplicationPartManager(manager => { var afp = manager.FeatureProviders.First(iafp => iafp.GetType() == typeof(ControllerFeatureProvider)); if (afp != null) { manager.FeatureProviders.Remove(afp); } 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); // MESCIUS API services.AddMvc(option => { option.EnableEndpointRouting = false; }); services.AddC1Api(); } // Configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) { //MESCIUS API app.UseC1Api(); app.UseStaticFiles(); 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 }); app.UseMvc(); //MESCIUS API app.UseStorageProviders() .AddDiskStorage("PdfRoot", Path.Combine(env.WebRootPath, "Pdfs")); } } |
Notice that the disk storage is added in the Configure method of Startup using the AddDiskStorage method.