Click or drag to resize

PdfIntegrationProviderProcessAppendDataRequest Method

Called when processing a request for object data initiated by the Client API which set the user mode to object insertion with a custom object key.

Namespace:  RadPdf.Integration
Assembly:  RadPdfStandard (in RadPdfStandard.dll) Version: 4.1.0.0 (4.1.0.0)
Syntax
public virtual void ProcessAppendDataRequest(
	PdfDataContext context
)

Parameters

context
Type: RadPdf.IntegrationPdfDataContext
An object (defined by PdfDataContext) that contains the request context.
Remarks

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.

Examples
The following example uses a PdfIntegrationProvider to create a custom Integration Provider which will set NeedAppearances to true for all documents as they are saved.
C#
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;
    }
}
The following Program.cs file registers the above custom Integration Provider. This example assumes that CustomPdfIntegrationProvider is in namespace referenced by your ASP.NET web application.
C#
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();
The following .cshtml and code behind files use the the client API to allow server side provided images to be added to a document.

Pages/Shared/_Layout.cshtml

XML
<!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>&copy; Red Software</p>
        </footer>
    </div>
</body>
</html>

Pages/_ViewImports.cshtml

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

Pages/_ViewStart.cshtml

XML
@{
    Layout = "_Layout";
}

Pages/Index.cshtml

XML
@{
             @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

XML
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;
                     }
                 }
             }
See Also