Skip to content

893607: UG documentation for LTV and Timestamp - Flutter PDF. #895

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 170 additions & 0 deletions Flutter/pdf/working-with-digital-signature.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,173 @@ File('Output.pdf').writeAsBytes(await document.save());
document.dispose();

{% endhighlight %}

## Long Term Validation (LTV) PDF signature

The Syncfusion Flutter PDF supports creating long term signature validation for the signed PDF document. The LTV signature allows you to check the validity of a signature long after the document has been signed. To achieve long term validation, all the required elements for signature validation must be embedded in the signed PDF.

N> The resulting PDF document size will be substantial because all the necessary signature information, Certificate Revocation List (CRL), and Online Certificate Status Protocol (OCSP) are embedded.

The following code example shows how to enable LTV for a signed PDF document using createLongTermValidity method in [PdfSignature](https://pub.dev/documentation/syncfusion_flutter_pdf/latest/pdf/PdfSignature-class.html) class.

{% highlight dart %}

// Load the existing PDF document.
PdfDocument document =
PdfDocument(inputBytes: File('input.pdf').readAsBytesSync());
// Load the existing signature field.
PdfSignatureField field = document.form.fields[0] as PdfSignatureField;
// Create LTV for loaded signed signature.
bool isLTVAdded = await field.signature!.createLongTermValidity();
// Save the document.
File('output.pdf').writeAsBytesSync(await document.save());
// Dispose the document.
document.dispose();

{% endhighlight %}

## Create Long Term Validation (LTV) with public certificates data

The following code example shows how to create an LTV for a signed PDF document using public certificates with the createLongTermValidity method in [PdfSignature](https://pub.dev/documentation/syncfusion_flutter_pdf/latest/pdf/PdfSignature-class.html) class.

{% highlight dart %}

// Load the existing PDF document.
PdfDocument document =
PdfDocument(inputBytes: File('input.pdf').readAsBytesSync());
// Load the existing signature field.
PdfSignatureField field = document.form.fields[0] as PdfSignatureField;
// Load the certificate from the PFX file.
PdfCertificate certificate =
PdfCertificate(File('PDF.pfx').readAsBytesSync(), 'syncfusion');
// Get the public certificates data.
List<List<int>>? publicCertificatesData = certificate.getCertificateChain();
// Create LTV with your public certificates.
await field.signature!.createLongTermValidity(
publicCertificatesData: publicCertificatesData,
includePublicCertificates: true);
// Save the document.
File('output.pdf').writeAsBytesSync(await document.save());
// Dispose the document.
document.dispose();

{% endhighlight %}

## Adding a timestamp in digital signature

The Syncfusion Flutter PDF allows you to add timestamp in the digital signature of the PDF document using timestampServer property in [PdfSignature](https://pub.dev/documentation/syncfusion_flutter_pdf/latest/pdf/PdfSignature-class.html) class. The following code example explains the same.

N> Signing using TimestampServer only works when the document is saved using asynchronous [save](https://pub.dev/documentation/syncfusion_flutter_pdf/latest/pdf/PdfDocument/save.html). It is not supported in synchronous [saveSync](https://pub.dev/documentation/syncfusion_flutter_pdf/latest/pdf/PdfDocument/saveSync.html).

{% highlight dart %}

// Create a new PDF document.
PdfDocument document = PdfDocument();
// Add a new page to the document.
PdfPage page = document.pages.add();
// Create a new timestamp server.
TimestampServer server = TimestampServer(
Uri.parse('http://syncfusion.digistamp.com'),
userName: 'user',
password: '123456',
timeOut: const Duration(milliseconds: 5000));
// Check whether the timestamp server is valid.
bool isValid = await server.isValid;
if (isValid) {
// Add a new signature field to the page.
PdfSignatureField field = PdfSignatureField(page, 'signature',
bounds: const Rect.fromLTWH(0, 0, 200, 100),
signature: PdfSignature(
certificate:
PdfCertificate(File('PDF.pfx').readAsBytesSync(), 'syncfusion'),
contactInfo: 'johndoe@owned.us',
locationInfo: 'Honolulu, Hawaii',
reason: 'I am author of this document.',
));
// Add the timestamp server to the signature.
field.signature!.timestampServer = server;
// Get the graphics of the signature field.
final PdfGraphics? graphics = field.appearance.normal.graphics;
// Draw an image to the signature field.
graphics!.drawImage(PdfBitmap(File('picture.png').readAsBytesSync()),
Rect.fromLTWH(0, 0, field.bounds.width, field.bounds.height));
// Add the signature field to the form fields collection.
document.form.fields.add(field);
}
// Save the document.
File('output.pdf').writeAsBytesSync(await document.save());
// Dispose the document.
document.dispose();

{% endhighlight %}

## Adding a timestamp in the PDF document

You can add timestamp to the PDF document using timestampServer property in [PdfSignature](https://pub.dev/documentation/syncfusion_flutter_pdf/latest/pdf/PdfSignature-class.html) class. The following code example explains the same.

N> Signing using TimestampServer only works when the document is saved using asynchronous [save](https://pub.dev/documentation/syncfusion_flutter_pdf/latest/pdf/PdfDocument/save.html). It is not supported in synchronous [saveSync](https://pub.dev/documentation/syncfusion_flutter_pdf/latest/pdf/PdfDocument/saveSync.html).


{% highlight dart %}

// Create a new PDF document.
PdfDocument document = PdfDocument();
// Add a new page to the document.
PdfPage page = document.pages.add();
// Create a new timestamp server.
TimestampServer server = TimestampServer(
Uri.parse('http://syncfusion.digistamp.com'),
userName: 'user',
password: '123456',
timeOut: const Duration(milliseconds: 5000));
// Check whether the timestamp server is valid.
bool isValid = await server.isValid;
if (isValid) {
// Add a new signature field to the page.
PdfSignatureField field =
PdfSignatureField(page, 'signature', signature: PdfSignature());
// Add the timestamp server to the signature.
field.signature!.timestampServer = server;
// Add the signature field to the form fields collection.
document.form.fields.add(field);
}
// Save the document.
File('output.pdf').writeAsBytesSync(await document.save());
// Dispose the document.
document.dispose();

{% endhighlight %}

## Adding a timestamp in an existing PDF document

You can add timestamp to the existing PDF document using timestampServer property in [PdfSignature](https://pub.dev/documentation/syncfusion_flutter_pdf/latest/pdf/PdfSignature-class.html) class. The following code example explains the same.

N> Signing using TimestampServer only works when the document is saved using asynchronous [save](https://pub.dev/documentation/syncfusion_flutter_pdf/latest/pdf/PdfDocument/save.html). It is not supported in synchronous [saveSync](https://pub.dev/documentation/syncfusion_flutter_pdf/latest/pdf/PdfDocument/saveSync.html).

{% highlight dart %}

// Create a new PDF document.
PdfDocument document =
PdfDocument(inputBytes: File('input.pdf').readAsBytesSync());
// Load the existing signature field.
PdfSignatureField field = document.form.fields[0] as PdfSignatureField;
// Create a new timestamp server.
TimestampServer server = TimestampServer(
Uri.parse('http://syncfusion.digistamp.com'),
userName: 'user',
password: '123456',
timeOut: const Duration(milliseconds: 5000));
// Check whether the timestamp server is valid.
bool isValid = await server.isValid;
if (isValid) {
// Add new signature to the existing signature field.
field.signature = PdfSignature();
// Add the timestamp server to the signature.
field.signature!.timestampServer = server;
}
// Save the document.
File('output.pdf').writeAsBytesSync(await document.save());
// Dispose the document.
document.dispose();

{% endhighlight %}