You are here > Demos > PDF Modification

This demonstration shows how the developer can modify the PDF before display, including adding shapes & text and pre-filling form fields.

<%@ Page Language="C#" CodeFile="Editor.aspx.cs" Inherits="PDF_Editor" %>

<%@ Register Assembly="APPortalUI" Namespace="APPortalUI.Web.UI" TagPrefix="apPortalUI" %>

<!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>activePDF Portal Sample</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <apPortalUI:PdfWebControl id="PdfWebControl1" runat="server" height="600px" width="100%" />
    </div>
    </form>
</body>
</html>

using System;
using System.Drawing;
using APPortal.Data.Document;
using APPortal.Data.Document.Common;
using APPortal.Data.Document.Objects;
using APPortal.Data.Document.Objects.FormFields;
using APPortal.Data.Document.Objects.Shapes;
using APPortalUI.Web.UI;

partial class Editor : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.PdfWebControl1.CreateDocument("filename", System.IO.File.ReadAllBytes(Server.MapPath(@"pdfs\APPortalSampleForm.pdf")));

            //Create DocumentEditor object
            PdfDocumentEditor DocumentEditor1 =
                this.PdfWebControl1.EditDocument();

            //Fill out PDF field using field names
            ((PdfTextField)
                  DocumentEditor1.Fields.Find("firstName"))
                  .Value = "John";
                ((PdfTextField)
                  DocumentEditor1.Fields.Find("lastName"))
                  .Value = "Smith";
                ((PdfCheckField)
                  DocumentEditor1.Fields.Find("c1_04"))
                  .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;

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

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

<%@ Page Language="VB" CodeFile="Editor.aspx.vb" Inherits="PDF_Editor" %>

<%@ Register Assembly="APPortalUI" Namespace="APPortalUI.Web.UI" TagPrefix="apPortalUI" %>

<!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>activePDF Portal Sample</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <apPortalUI:PdfWebControl id="PdfWebControl1" runat="server" height="600px" width="100%" />
    </div>
    </form>
</body>
</html>

Option Explicit On
Option Strict On

Imports System.Drawing
Imports APPortal.Data.Document
Imports APPortal.Data.Document.Common
Imports APPortal.Data.Document.Objects
Imports APPortal.Data.Document.Objects.FormFields
Imports APPortal.Data.Document.Objects.Shapes
Imports APPortalUI.Web.UI

Partial Class Editor
    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

            Me.PdfWebControl1.CreateDocument("filename", System.IO.File.ReadAllBytes(Server.MapPath("pdfs\APPortalSampleForm.pdf")))

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

            'Fill out PDF field using field names
            DirectCast( _
              DocumentEditor1.Fields.Find("firstName"), _
              PdfTextField _
              ).Value = "John"
            DirectCast( _
              DocumentEditor1.Fields.Find("lastName"), _
              PdfTextField _
              ).Value = "Smith"
            DirectCast( _
              DocumentEditor1.Fields.Find("c1_04"), _
              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

            '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

            'Commit DocumentEditor changes
            DocumentEditor1.Save()

        End If
    End Sub
End Class