Editing PDF Forms within Silverlight
2012
PDF form or AcroForms allow users to interactively edit specific portions of a PDF document in supporting viewer applications. A PDF form is composed by one or more AcroForm fields that provide a name-value association once they have been edited.
Amyuni PDF for Silverlight is an online PDF viewer based on Amyuni PDF Creator as a server side component and a Silverlight viewer that runs within a browser. Amyuni PDF Creator takes care of converting a PDF file into an equivalent XAML-based package, and sends it to the Silverlight client. A full description of Amyuni PDF for Silverlight can be found in this page: http://www.amyuni.com/en/developer/pdfsilverlight.
This document will focus on how to provide AcroForm editing capabilities to your Silverlight application. |
Reviewing our goals, we want to be able to:
- Show form fields as editable components in Silverlight
- Submit the values of those fields to the server (so that we can store them in a database for example)
- Put the values back in the PDF file.
- Send back the filled-out PDF to the client either as an editable form or as a flattened PDF.
Showing each form field as an editable component in Silverlight
When a PDF file containing form fields is converted into a XAML package by Amyuni PDF Creator, each text field will be converted into a TextBox XAML tag. This tag will be loaded as the corresponding editable component in Silverlight.
Example 1:
<TextBox Canvas.Left = "233.60" Canvas.Top = "242.69" Width = "215.27" Height = "37.13" FontSize="15.91" BorderThickness="0" Background="{x:Null}" Name="acField1">
<TextBox.Foreground>
<SolidColorBrush Color = "#000000" Opacity="1.00"/>
</TextBox.Foreground>
</TextBox>
Let’s first review the internal architecture of our Silverlight viewer sample, we have a library with a Silverlight control called PDFSilverlightControl where our XAML based packages are loaded from a URL provided, and we have a Silverlight sample application that is hosting this control.
In our PDFSilverlightControl sample class we have the property:
Example 2:
/// <summary>
/// Returns editable text fields from the PDF file.
/// </summary>
public List<TextBox> FormFields { get;}
This property can be used to retrieve the form fields in the Silverlight application.
Comment