- How to add page numbers to your PDF
- Add text field to PDF
- Append multiple PDF documents
- Bulleted list from XML and XSL
- Merge PDF
- Calculate the height of a paragraph in PDF
- Multipage TIFF to PDF
- Convert TXT to PDF
- Convert XHTML to PDF
- Create PDF in C# - Tall Components - Check out our PDF code samples
- Text formatting
- Generate PDF form from XML
- Generate PDF with local images from XML with Xamarin.iOS
- XhtmlParagraph and TrueType fonts
- Add footer with left and right aligned text on same line
- Read and write meta data from PDF
- Stitch PDF documents
- Use multiple licenses
- What is the resulting fontsize in PDF rich text used in SimpleXhtmlShape
Add text field to PDF
Code sample that shows how to add a text field to an existing PDF document.
Add text field to an existing PDF document
This code sample illustrates how you can add TextFields to your PDF. Do take note that you need to add a Widget to your document; in MVC terms the textfield is the model and the Widget is the view.
Document document = new Document();
Page page = new Page( PageSize.Letter );
document.Pages.Add( page );
TextField textField = new TextField( "text1" );
textField.Value = "Hello!";
document.Fields.Add( textField );
Widget widget = new Widget( 200, 400, 200, 50 );
widget.FontSize = 0; // auto-size
widget.TextColor = RgbColor.Red;
widget.BorderColor = RgbColor.Black;
widget.BorderStyle = BorderStyle.Solid;
widget.BorderWidth = 2;
textField.Widgets.Add( widget );
page.Widgets.Add( widget );
using ( FileStream file = new FileStream("addtextfield.pdf", FileMode.Create, FileAccess.Write))
{
document.Write( file );
}
Dim document As New Document()
Dim page As New Page(PageSize.Letter)
document.Pages.Add(page)
Dim textField As New TextField("text1")
textField.Value = "Hello!"
document.Fields.Add(textField)
Dim widget As New Widget(200, 400, 200, 50)
widget.FontSize = 0
' auto-size
widget.TextColor = RgbColor.Red
widget.BorderColor = RgbColor.Black
widget.BorderStyle = BorderStyle.Solid
widget.BorderWidth = 2
textField.Widgets.Add(widget)
page.Widgets.Add(widget)
Using file As New FileStream("addtextfield.pdf", FileMode.Create, FileAccess.Write)
document.Write(file)
End Using