|
This code snippet is taken from Annotations.cs line 847 in the
Annotations example project.
CatalogElement cat = new CatalogElement(Doc.ObjectSoup.Catalog);
cat.EntryAcroForm.EntrySigFlags = 3;
// NB If you don't want your signature to print then set the /F flag to 0
int fieldID = Doc.AddObject("<</Type /Annot /Subtype /Widget /F 4 /FT /Sig /DA (/TimesRoman 0 Tf 0 g)>>");
WidgetAnnotationElement widget = new WidgetAnnotationElement(Doc.ObjectSoup[fieldID]);
SignatureFieldElement field = (SignatureFieldElement)widget.FieldElement;
FormField formField = new FormField(this, inName, field.Object.ID);
formField.Widget.Rect = new XRect(inRect);
if (mSig == null)
Doc.Form.Refresh();
else {
string sigName = mSig.Name;
Doc.Form.Refresh();
mSig = (Signature)Doc.Form[sigName];
}
if (inAppearanceText != null) {
XRect rect = widget.EntryRect.GetRect();
rect.Pin = XRect.Corner.TopLeft;
rect.Width = 200; // Change this to fit the Text
rect.Height = 60; // Change this to fit the Text
widget.EntryRect.SetRect(rect);
rect.Pin = XRect.Corner.BottomLeft;
rect.Position(0, 0);
int fontSize = 12;
string theRect = Doc.Rect.String;
int theFont = Doc.Font;
int theFontSize = Doc.FontSize;
double charSpacing = Doc.TextStyle.CharSpacing;
double lineSpacing = Doc.TextStyle.LineSpacing;
int pageID = Doc.Page;
// Use a detached page to avoid changes to the current page
// or to the page tree for a new page
Doc.Page = Doc.AddObject("<</Type /Page /MediaBox [" + rect.String + "] >>");
Doc.Rect.String = rect.String;
int fontID = Doc.AddFont("Times-Roman");
Doc.Font = fontID;
Doc.FontSize = fontSize;
Doc.TextStyle.CharSpacing = 0;
Doc.TextStyle.LineSpacing = 2;
int textID = Doc.AddText(inAppearanceText);
string textStream = Doc.GetInfo(textID, "Stream");
Doc.Delete(textID);
int l1 = textStream.IndexOf("/Fabc", 0, textStream.Length);
int l2 = textStream.IndexOf(" ", l1, textStream.Length - l1);
string fontResName = textStream.Substring(l1 + 1, l2 - l1 - 1);
Doc.Delete(Doc.Page);
Doc.Page = pageID;
Doc.Rect.String = theRect;
Doc.Font = theFont;
Doc.FontSize = theFontSize;
Doc.TextStyle.CharSpacing = charSpacing;
Doc.TextStyle.LineSpacing = lineSpacing;
widget.EntryAP = new AppearanceElement(widget);
widget.EntryAP.EntryN = MakeAppearance(rect, null, 0, fontResName, fontID, textStream);
}
return formField;
Dim cat As New CatalogElement(Doc.ObjectSoup.Catalog)
cat.EntryAcroForm.EntrySigFlags = 3
' NB If you don't want your signature to print then set the /F flag to 0
Dim fieldID As Integer = Doc.AddObject("<</Type /Annot /Subtype /Widget /F 4 /FT /Sig /DA (/TimesRoman 0 Tf 0 g)>>")
Dim widget As New WidgetAnnotationElement(Doc.ObjectSoup(fieldID))
Dim field As SignatureFieldElement = CType(widget.FieldElement, SignatureFieldElement)
Dim formField As New FormField(Me, inName, field.Object.ID)
formField.Widget.Rect = New XRect(inRect)
If mSig Is Nothing Then
Doc.Form.Refresh()
Else
Dim sigName As String = mSig.Name
Doc.Form.Refresh()
mSig = CType(Doc.Form(sigName), Signature)
End If
If inAppearanceText IsNot Nothing Then
Dim rect As XRect = widget.EntryRect.GetRect()
rect.Pin = XRect.Corner.TopLeft
rect.Width = 200 ' Change this to fit the Text
rect.Height = 60 ' Change this to fit the Text
widget.EntryRect.SetRect(rect)
rect.Pin = XRect.Corner.BottomLeft
rect.Position(0, 0)
Dim fontSize As Integer = 12
Dim theRect As String = Doc.Rect.String
Dim theFont As Integer = Doc.Font
Dim theFontSize As Integer = Doc.FontSize
Dim charSpacing As Double = Doc.TextStyle.CharSpacing
Dim lineSpacing As Double = Doc.TextStyle.LineSpacing
Dim pageID As Integer = Doc.Page
' Use a detached page to avoid changes to the current page
' or to the page tree for a new page
Doc.Page = Doc.AddObject("<</Type /Page /MediaBox [" & rect.String & "] >>")
Doc.Rect.String = rect.String
Dim fontID As Integer = Doc.AddFont("Times-Roman")
Doc.Font = fontID
Doc.FontSize = fontSize
Doc.TextStyle.CharSpacing = 0
Doc.TextStyle.LineSpacing = 2
Dim textID As Integer = Doc.AddText(inAppearanceText)
Dim textStream As String = Doc.GetInfo(textID, "Stream")
Doc.Delete(textID)
Dim l1 As Integer = textStream.IndexOf("/Fabc", 0, textStream.Length)
Dim l2 As Integer = textStream.IndexOf(" ", l1, textStream.Length - l1)
Dim fontResName As String = textStream.Substring(l1 + 1, l2 - l1 - 1)
Doc.Delete(Doc.Page)
Doc.Page = pageID
Doc.Rect.String = theRect
Doc.Font = theFont
Doc.FontSize = theFontSize
Doc.TextStyle.CharSpacing = charSpacing
Doc.TextStyle.LineSpacing = lineSpacing
widget.EntryAP = New AppearanceElement(widget)
widget.EntryAP.EntryN = MakeAppearance(rect, Nothing, 0, fontResName, fontID, textStream)
End If
Return formField
|
|
|