Класс PdfInteractiveFormListBoxField
В этом разделе
Предоставляет информацию о поле интерактивной формы, которое определяет поле списка.
Объектная модель
Синтаксис
Ремарки
Используйте свойство SelectedItem или SelectedItems для изменения поля. значение.
Используйте DefaultSelectedItem или DefaultSelectedItems для изменения значения поля по умолчанию.
Пример
Вот пример, показывающий, как создать PDF документ с полем ListBox:
Class PdfInteractiveFormListBoxFieldExample
''' <summary>
''' Creates a PDF document with the list box field.
''' </summary>
''' <param name="filename">The filename.</param>
Public Shared Sub CreateDocumentWithListBoxField(filename As String)
' create PDF document
Using document As New Vintasoft.Imaging.Pdf.PdfDocument()
' create interactive form in PDF document
document.InteractiveForm = New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm(document)
' specify that the viewer application must construct appearance streams and
' appearance properties for all widget annotations
document.InteractiveForm.NeedAppearances = True
' create an empty page
Dim page As New Vintasoft.Imaging.Pdf.Tree.PdfPage(document, Vintasoft.Imaging.PaperSizeKind.A4)
' add page to the document
document.Pages.Add(page)
Dim width As Single = 60
Dim height As Single = 70
' create a rectangle that defines list box position on PDF page
Dim rect As New System.Drawing.RectangleF((page.Size.Width - width) / 2, ((page.Size.Height - height) / 3) * 2, width, height)
' create a list box field
Dim listBox As New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormListBoxField(document, "ListBox1", rect, New String() {"Item1", "Item2", "Item3"})
' set the selected item
listBox.SelectedItem = "Item2"
' set yje default selected item
listBox.DefaultSelectedItem = listBox.SelectedItem
' set the border style
listBox.Annotation.BorderStyle = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyle(document)
listBox.Annotation.BorderStyle.Style = Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyleType.Beveled
listBox.Annotation.BorderStyle.Width = 1
' set the appearance characteristics
listBox.Annotation.AppearanceCharacteristics = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationAppearanceCharacteristics(document)
listBox.Annotation.AppearanceCharacteristics.BorderColor = System.Drawing.Color.Gray
' set the default appearance of text
Dim font As Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont = document.FontManager.GetStandardFont(Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman)
listBox.SetTextDefaultAppearance(font, 12, System.Drawing.Color.Black)
' add the list box field to the interactive form of document
document.InteractiveForm.Fields.Add(listBox)
' add annotation, associated with list box field, to the page
page.Annotations = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document)
page.Annotations.Add(listBox.Annotation)
' save the document
document.Save(filename)
End Using
End Sub
End Class
class PdfInteractiveFormListBoxFieldExample
{
/// <summary>
/// Creates a PDF document with the list box field.
/// </summary>
/// <param name="filename">The filename.</param>
public static void CreateDocumentWithListBoxField(string filename)
{
// create PDF document
using (Vintasoft.Imaging.Pdf.PdfDocument document = new Vintasoft.Imaging.Pdf.PdfDocument())
{
// create interactive form in PDF document
document.InteractiveForm =
new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm(document);
// specify that the viewer application must construct appearance streams and
// appearance properties for all widget annotations
document.InteractiveForm.NeedAppearances = true;
// create an empty page
Vintasoft.Imaging.Pdf.Tree.PdfPage page = new Vintasoft.Imaging.Pdf.Tree.PdfPage(
document, Vintasoft.Imaging.PaperSizeKind.A4);
// add page to the document
document.Pages.Add(page);
float width = 60;
float height = 70;
// create a rectangle that defines list box position on PDF page
System.Drawing.RectangleF rect = new System.Drawing.RectangleF(
(page.Size.Width - width) / 2,
((page.Size.Height - height) / 3) * 2,
width, height);
// create a list box field
Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormListBoxField listBox =
new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormListBoxField(
document, "ListBox1", rect, new string[] { "Item1", "Item2", "Item3" });
// set the selected item
listBox.SelectedItem = "Item2";
// set yje default selected item
listBox.DefaultSelectedItem = listBox.SelectedItem;
// set the border style
listBox.Annotation.BorderStyle =
new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyle(document);
listBox.Annotation.BorderStyle.Style =
Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyleType.Beveled;
listBox.Annotation.BorderStyle.Width = 1;
// set the appearance characteristics
listBox.Annotation.AppearanceCharacteristics =
new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationAppearanceCharacteristics(document);
listBox.Annotation.AppearanceCharacteristics.BorderColor = System.Drawing.Color.Gray;
// set the default appearance of text
Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont font = document.FontManager.GetStandardFont(
Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman);
listBox.SetTextDefaultAppearance(font, 12, System.Drawing.Color.Black);
// add the list box field to the interactive form of document
document.InteractiveForm.Fields.Add(listBox);
// add annotation, associated with list box field, to the page
page.Annotations = new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document);
page.Annotations.Add(listBox.Annotation);
// save the document
document.Save(filename);
}
}
}
Иерархия наследования
Требования
Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5
Смотрите также