Skip to main content

pdfium_render/pdf/document/page/field/
signature.rs

1//! Defines the [PdfFormSignatureField] struct, exposing functionality related to a single
2//! form field of type [PdfFormFieldType::Signature].
3
4use crate::bindgen::{FPDF_ANNOTATION, FPDF_FORMHANDLE};
5use crate::pdf::document::page::field::private::internal::PdfFormFieldPrivate;
6use crate::pdfium::PdfiumLibraryBindingsAccessor;
7use std::marker::PhantomData;
8
9#[cfg(doc)]
10use {
11    crate::pdf::document::form::PdfForm,
12    crate::pdf::document::page::annotation::PdfPageAnnotationType,
13    crate::pdf::document::page::field::{PdfFormField, PdfFormFieldType},
14};
15
16/// A single [PdfFormField] of type [PdfFormFieldType::Signature]. The form field object defines
17/// an interactive data entry widget that allows the user to draw a signature.
18///
19/// Form fields in Pdfium are wrapped inside page annotations of type [PdfPageAnnotationType::Widget]
20/// or [PdfPageAnnotationType::XfaWidget]. User-specified values can be retrieved directly from
21/// each form field object by unwrapping the form field from the annotation, or in bulk from the
22/// [PdfForm::field_values()] function.
23pub struct PdfFormSignatureField<'a> {
24    form_handle: FPDF_FORMHANDLE,
25    annotation_handle: FPDF_ANNOTATION,
26    lifetime: PhantomData<&'a FPDF_ANNOTATION>,
27}
28
29impl<'a> PdfFormSignatureField<'a> {
30    pub(crate) fn from_pdfium(
31        form_handle: FPDF_FORMHANDLE,
32        annotation_handle: FPDF_ANNOTATION,
33    ) -> Self {
34        PdfFormSignatureField {
35            form_handle,
36            annotation_handle,
37            lifetime: PhantomData,
38        }
39    }
40}
41
42impl<'a> PdfFormFieldPrivate<'a> for PdfFormSignatureField<'a> {
43    #[inline]
44    fn form_handle(&self) -> FPDF_FORMHANDLE {
45        self.form_handle
46    }
47
48    #[inline]
49    fn annotation_handle(&self) -> FPDF_ANNOTATION {
50        self.annotation_handle
51    }
52}
53
54impl<'a> PdfiumLibraryBindingsAccessor<'a> for PdfFormSignatureField<'a> {}
55
56#[cfg(feature = "thread_safe")]
57unsafe impl<'a> Send for PdfFormSignatureField<'a> {}
58
59#[cfg(feature = "thread_safe")]
60unsafe impl<'a> Sync for PdfFormSignatureField<'a> {}