PdfIntegrationProviderProcessAppendDataRequest Method |
Namespace: RadPdf.Integration
If this method is overridden in an inheriting class, do not call this base method.
This method is not triggered by Append(Byte) or similar overloads.
using System; using System.Web; using RadPdf.Integration; public class CustomPdfIntegrationProvider : PdfIntegrationProvider { public override void OnDocumentSaving(DocumentSavingEventArgs e) { base.OnDocumentSaving(e); // Set that a PDF reader should construct the appearance for // form fields in the document. e.Document.Fields.NeedAppearances = true; } }
using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using RadPdf; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddRazorPages(); builder.Services.AddSession(); var app = builder.Build(); app.UseStaticFiles(); app.UseRouting(); app.UseSession(); app.UseAuthorization(); // Or however you normally process page requests app.MapRazorPages(); // Create middleware settings RadPdfCoreMiddlewareSettings settings = new RadPdfCoreMiddlewareSettings() { // Add SQL Server Connection String, if not using Lite Documents // Sample connection string below connects to a SQL Server Express instance on localhost // TrustServerCertificate=True is set to avoid a trust exception (e.g. "The certificate chain was issued by an authority that is not trusted.") // ConnectionString = @"Server=.\SQLExpress;Database=RadPdf;Trusted_Connection=Yes;TrustServerCertificate=True;", // Add License Key LicenseKey = "DEMO", // Attach the Integration Provider IntegrationProvider = new CustomPdfIntegrationProvider() // To run RAD PDF without the System Service, add UseService = false // If using Lite Documents without the System Service, a LiteStorageProvider must also be implemented //UseService = false }; // Add RAD PDF's middleware to app app.UseRadPdf(settings); app.Run();
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"] - RadPdfNetDemo</title> @Html.Raw(RadPdf.Web.UI.PdfWebControlLite.RenderHead()) </head> <body> <div class="container body-content"> @RenderBody() <hr /> <footer> <p>© Red Software</p> </footer> </div> </body> </html>
Pages/_ViewImports.cshtml
@using RadPdfNetDemo @namespace RadPdfNetDemo.Pages @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
Pages/_ViewStart.cshtml
@{
Layout = "_Layout";
}Pages/Index.cshtml
@{
@page
@model RadPdfNetDemo.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.PdfWebControlLite.RenderHead())
See: /Pages/Shared/_Layout.cshtml
*@
@{
ViewData["Title"] = "Basic Example";
// Get web control from ViewBag
PdfWebControlLite pdfWebControl1 = ViewData["PdfWebControl1"] as PdfWebControlLite;
// Set control's properties
pdfWebControl1.ID = "PdfWebControl1"; // Important if Client API is to be used!
pdfWebControl1.Height = "600px";
pdfWebControl1.Width = "100%";
}
<div>
@* Render web control to body *@
@Html.Raw(pdfWebControl1.RenderControl())
</div>
<div>
<a href="#" onclick="(new PdfWebControlApi()).append("my_key");return false;">Append PDF Data</a>
</div>Pages/Index.cshtml.cs
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.RazorPages;
using RadPdf.Lite;
using RadPdf.Web.UI;
namespace RadPdfNetDemo.Pages
{
public class BasicModel : PageModel
{
public void OnGet()
{
string path = @"C:\demo.pdf";
// Get PDF as byte array from file (or database, browser upload, remote storage, etc)
byte[] pdfData = System.IO.File.ReadAllBytes(path);
// Create RAD PDF control
PdfWebControlLite pdfWebControl1 = new PdfWebControlLite(HttpContext);
// Create document from PDF data
pdfWebControl1.CreateDocument("Document Name", pdfData);
// Put control in ViewBag
ViewData["PdfWebControl1"] = pdfWebControl1;
}
}
}