Skip to content

Commit 0242273

Browse files
Merge pull request #896 from syncfusion-content/893607_ug
893607: UG documentation for LTV and Timestamp - Flutter PDF.
2 parents 6bf80d6 + 1346979 commit 0242273

File tree

1 file changed

+170
-0
lines changed

1 file changed

+170
-0
lines changed

Flutter/pdf/working-with-digital-signature.md

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,173 @@ File('Output.pdf').writeAsBytes(await document.save());
255255
document.dispose();
256256

257257
{% endhighlight %}
258+
259+
## Long Term Validation (LTV) PDF signature
260+
261+
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.
262+
263+
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.
264+
265+
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.
266+
267+
{% highlight dart %}
268+
269+
// Load the existing PDF document.
270+
PdfDocument document =
271+
PdfDocument(inputBytes: File('input.pdf').readAsBytesSync());
272+
// Load the existing signature field.
273+
PdfSignatureField field = document.form.fields[0] as PdfSignatureField;
274+
// Create LTV for loaded signed signature.
275+
bool isLTVAdded = await field.signature!.createLongTermValidity();
276+
// Save the document.
277+
File('output.pdf').writeAsBytesSync(await document.save());
278+
// Dispose the document.
279+
document.dispose();
280+
281+
{% endhighlight %}
282+
283+
## Create Long Term Validation (LTV) with public certificates data
284+
285+
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.
286+
287+
{% highlight dart %}
288+
289+
// Load the existing PDF document.
290+
PdfDocument document =
291+
PdfDocument(inputBytes: File('input.pdf').readAsBytesSync());
292+
// Load the existing signature field.
293+
PdfSignatureField field = document.form.fields[0] as PdfSignatureField;
294+
// Load the certificate from the PFX file.
295+
PdfCertificate certificate =
296+
PdfCertificate(File('PDF.pfx').readAsBytesSync(), 'syncfusion');
297+
// Get the public certificates data.
298+
List<List<int>>? publicCertificatesData = certificate.getCertificateChain();
299+
// Create LTV with your public certificates.
300+
await field.signature!.createLongTermValidity(
301+
publicCertificatesData: publicCertificatesData,
302+
includePublicCertificates: true);
303+
// Save the document.
304+
File('output.pdf').writeAsBytesSync(await document.save());
305+
// Dispose the document.
306+
document.dispose();
307+
308+
{% endhighlight %}
309+
310+
## Adding a timestamp in digital signature
311+
312+
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.
313+
314+
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).
315+
316+
{% highlight dart %}
317+
318+
// Create a new PDF document.
319+
PdfDocument document = PdfDocument();
320+
// Add a new page to the document.
321+
PdfPage page = document.pages.add();
322+
// Create a new timestamp server.
323+
TimestampServer server = TimestampServer(
324+
Uri.parse('http://syncfusion.digistamp.com'),
325+
userName: 'user',
326+
password: '123456',
327+
timeOut: const Duration(milliseconds: 5000));
328+
// Check whether the timestamp server is valid.
329+
bool isValid = await server.isValid;
330+
if (isValid) {
331+
// Add a new signature field to the page.
332+
PdfSignatureField field = PdfSignatureField(page, 'signature',
333+
bounds: const Rect.fromLTWH(0, 0, 200, 100),
334+
signature: PdfSignature(
335+
certificate:
336+
PdfCertificate(File('PDF.pfx').readAsBytesSync(), 'syncfusion'),
337+
contactInfo: 'johndoe@owned.us',
338+
locationInfo: 'Honolulu, Hawaii',
339+
reason: 'I am author of this document.',
340+
));
341+
// Add the timestamp server to the signature.
342+
field.signature!.timestampServer = server;
343+
// Get the graphics of the signature field.
344+
final PdfGraphics? graphics = field.appearance.normal.graphics;
345+
// Draw an image to the signature field.
346+
graphics!.drawImage(PdfBitmap(File('picture.png').readAsBytesSync()),
347+
Rect.fromLTWH(0, 0, field.bounds.width, field.bounds.height));
348+
// Add the signature field to the form fields collection.
349+
document.form.fields.add(field);
350+
}
351+
// Save the document.
352+
File('output.pdf').writeAsBytesSync(await document.save());
353+
// Dispose the document.
354+
document.dispose();
355+
356+
{% endhighlight %}
357+
358+
## Adding a timestamp in the PDF document
359+
360+
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.
361+
362+
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).
363+
364+
365+
{% highlight dart %}
366+
367+
// Create a new PDF document.
368+
PdfDocument document = PdfDocument();
369+
// Add a new page to the document.
370+
PdfPage page = document.pages.add();
371+
// Create a new timestamp server.
372+
TimestampServer server = TimestampServer(
373+
Uri.parse('http://syncfusion.digistamp.com'),
374+
userName: 'user',
375+
password: '123456',
376+
timeOut: const Duration(milliseconds: 5000));
377+
// Check whether the timestamp server is valid.
378+
bool isValid = await server.isValid;
379+
if (isValid) {
380+
// Add a new signature field to the page.
381+
PdfSignatureField field =
382+
PdfSignatureField(page, 'signature', signature: PdfSignature());
383+
// Add the timestamp server to the signature.
384+
field.signature!.timestampServer = server;
385+
// Add the signature field to the form fields collection.
386+
document.form.fields.add(field);
387+
}
388+
// Save the document.
389+
File('output.pdf').writeAsBytesSync(await document.save());
390+
// Dispose the document.
391+
document.dispose();
392+
393+
{% endhighlight %}
394+
395+
## Adding a timestamp in an existing PDF document
396+
397+
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.
398+
399+
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).
400+
401+
{% highlight dart %}
402+
403+
// Create a new PDF document.
404+
PdfDocument document =
405+
PdfDocument(inputBytes: File('input.pdf').readAsBytesSync());
406+
// Load the existing signature field.
407+
PdfSignatureField field = document.form.fields[0] as PdfSignatureField;
408+
// Create a new timestamp server.
409+
TimestampServer server = TimestampServer(
410+
Uri.parse('http://syncfusion.digistamp.com'),
411+
userName: 'user',
412+
password: '123456',
413+
timeOut: const Duration(milliseconds: 5000));
414+
// Check whether the timestamp server is valid.
415+
bool isValid = await server.isValid;
416+
if (isValid) {
417+
// Add new signature to the existing signature field.
418+
field.signature = PdfSignature();
419+
// Add the timestamp server to the signature.
420+
field.signature!.timestampServer = server;
421+
}
422+
// Save the document.
423+
File('output.pdf').writeAsBytesSync(await document.save());
424+
// Dispose the document.
425+
document.dispose();
426+
427+
{% endhighlight %}

0 commit comments

Comments
 (0)