- Use multiple licenses
- Convert XHTML to PDF
- Append multiple PDF documents
- Calculate the height of a paragraph in PDF
- Multipage TIFF to PDF
- Bulleted list from XML and XSL
- Generate PDF with local images from XML with Xamarin.iOS
- Convert TXT to PDF
- XhtmlParagraph and TrueType fonts
- Generate PDF form from XML
- What is the resulting fontsize in PDF rich text used in SimpleXhtmlShape
- Merge PDF
- Add text field to PDF
- Add footer with left and right aligned text on same line
- How to add page numbers to your PDF
- Read and write meta data from PDF
- Text formatting
- Stitch PDF documents
- Create PDF in C# - Tall Components - Check out our PDF code samples
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