RAD PDF - Interactive Demonstrations

In this example, we use the PdfDocumentEditor to fill out several PDF form fields before the document is displayed in RAD PDF. We also have added an arrow object, which can not be moved, styled, resized, or deleted. A form field object has also been added, which can not be styled, resized, or deleted, but can be moved & filled.

RAD PDF Sample Source Files

Default.aspx

<%@ Page Language="C#" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="RadPdf" Namespace="RadPdf.Web.UI" TagPrefix="radPdf" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>RAD PDF Sample</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <radPdf:PdfWebControl id="PdfWebControl1" runat="server" height="600px" width="100%" />
    </div>
    </form>
</body>
</html>

Default.aspx.cs

using System;
using System.Drawing;
using RadPdf.Data.Document;
using RadPdf.Data.Document.Common;
using RadPdf.Data.Document.Objects;
using RadPdf.Data.Document.Objects.FormFields;
using RadPdf.Data.Document.Objects.Shapes;

partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack) 
        {
            //Get PDF as byte array from file (or database, browser upload, remote storage, etc)
            byte[] pdfData = System.IO.File.ReadAllBytes(@"C:\demo.pdf");
            
            //Load PDF byte array into RAD PDF
            this.PdfWebControl1.CreateDocument("Document Name", pdfData); 
            
            //Create PdfDocumentEditor object
            PdfDocumentEditor DocumentEditor1 =
                this.PdfWebControl1.EditDocument();

            //Fill out PDF field using field names
            ((PdfTextField)
              DocumentEditor1.Fields.Find("First Name"))
              .Value = "John";
            ((PdfTextField)
              DocumentEditor1.Fields.Find("Last Name"))
              .Value = "Smith";
            ((PdfCheckField)
              DocumentEditor1.Fields.Find("Product Support"))
              .Checked = true;

            //Add arrow object
            PdfArrowShape a =
              (PdfArrowShape)
              DocumentEditor1.Pages[0].CreateObject(PdfObjectCreatable.ShapeArrow);
            a.LineColor = new PdfColor(Color.Blue);
            a.LineWidth = 2;
            a.SetLine(200, 220, 40, 160);
            a.Moveable = false;
            a.Resizable = false;
            a.Stylable = false;
            a.Deletable = false;
            a.Duplicatable = false;

            //Add text form field object
            PdfTextField f =
              (PdfTextField)
              DocumentEditor1.Pages[0].CreateObject(PdfObjectCreatable.FormFieldText);
            f.Resizable = false;
            f.Stylable = false;
            f.Deletable = false;
            f.Duplicatable = false;

            //Commit PdfDocumentEditor changes
            DocumentEditor1.Save();
        }
    }
}

Default.aspx

<%@ Page Language="VB" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<%@ Register Assembly="RadPdf" Namespace="RadPdf.Web.UI" TagPrefix="radPdf" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>RAD PDF Sample</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <radPdf:PdfWebControl id="PdfWebControl1" runat="server" height="600px" width="100%" />
    </div>
    </form>
</body>
</html>

Default.aspx.vb

Option Explicit On
Option Strict On

Imports System.Drawing
Imports RadPdf.Data.Document
Imports RadPdf.Data.Document.Common
Imports RadPdf.Data.Document.Objects
Imports RadPdf.Data.Document.Objects.FormFields
Imports RadPdf.Data.Document.Objects.Shapes

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack Then

            'Get PDF as byte array from file (or database, browser upload, remote storage, etc)
            Dim pdfData As Byte() = System.IO.File.ReadAllBytes("C:\demo.pdf")

            'Load PDF byte array into RAD PDF
            Me.PdfWebControl1.CreateDocument("Document Name", pdfData)

            'Create PdfDocumentEditor object
            Dim DocumentEditor1 As PdfDocumentEditor = _
                Me.PdfWebControl1.EditDocument()

            'Fill out PDF field using field names
            DirectCast( _
              DocumentEditor1.Fields.Find("First Name"), _
              PdfTextField _
              ).Value = "John"
            DirectCast( _
              DocumentEditor1.Fields.Find("Last Name"), _
              PdfTextField _
              ).Value = "Smith"
            DirectCast( _
              DocumentEditor1.Fields.Find("Product Support"), _
              PdfCheckField _
              ).Checked = True

            'Add arrow object
            Dim a As PdfArrowShape = _
              DirectCast( _
              DocumentEditor1.Pages(0).CreateObject(PdfObjectCreatable.ShapeArrow), _
              PdfArrowShape)
            a.LineColor = New PdfColor(Color.Blue)
            a.LineWidth = 2
            a.SetLine(200, 220, 40, 160)
            a.Moveable = False
            a.Resizable = False
            a.Stylable = False
            a.Deletable = False
            a.Duplicatable = False

            'Add text form field object
            Dim f As PdfTextField = _
              DirectCast( _
              DocumentEditor1.Pages(0).CreateObject(PdfObjectCreatable.FormFieldText), _
              PdfTextField)
            f.Resizable = False
            f.Stylable = False
            f.Deletable = False
            f.Duplicatable = False

            'Commit PdfDocumentEditor changes
            DocumentEditor1.Save()

        End If
    End Sub
End Class
RAD PDF is a Red Software product - ©2007-2024 Red Software