public class

XfdfFormatter

extends Object
java.lang.Object
   ↳ com.pspdfkit.document.formatters.XfdfFormatter

Class Overview

Provides methods for exporting data in XFDF format from the document as well as parsing the existing XFDF data and applying it to the document.

Summary

Public Constructors
XfdfFormatter()
Public Methods
static List<Annotation> parseXfdf(PdfDocument document, DataProvider dataProvider)
Parses XFDF file served by the data provider and returns a list of annotations that can be added to the document.
static Single<List<Annotation>> parseXfdfAsync(PdfDocument document, DataProvider dataProvider)
Parses XFDF file served by the data provider and returns a list of annotations that can be added to the document.
static void writeXfdf(PdfDocument document, List<Annotation> annotations, List<FormField> formFields, OutputStream outputStream)
Generates an XFDF file out of provided annotations and form fields and writes the output to the given output stream.
static Completable writeXfdfAsync(PdfDocument document, List<Annotation> annotations, List<FormField> formFields, OutputStream outputStream)
Generates an XFDF file out of provided annotations and form fields and writes the output to the given output stream.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public XfdfFormatter ()

Public Methods

public static List<Annotation> parseXfdf (PdfDocument document, DataProvider dataProvider)

Parses XFDF file served by the data provider and returns a list of annotations that can be added to the document. This doesn't automatically add all the annotations to the document. To do that use addAnnotationToPage(Annotation).

The method will throw a XfdfFormatterException when encountering an unexpected error while importing the XFDF.

Warning: this method runs on the current thread. If the current thread is the UI thread, it's recommended that you offload it to some other one, because this operation can take some time and thus block the UI.

Parameters
document Document for which we're parsing XFDF file.
dataProvider Data provider serving the source XFDF file.
Returns
  • List of annotations parsed from the XFDF file, ready to be added to the document.

public static Single<List<Annotation>> parseXfdfAsync (PdfDocument document, DataProvider dataProvider)

Parses XFDF file served by the data provider and returns a list of annotations that can be added to the document. This doesn't automatically add all the annotations to the document. To do that use addAnnotationToPage(Annotation).

The returned completable will emit a XfdfFormatterException when encountering an unexpected error while importing the XFDF.

Parameters
document Document for which we're parsing XFDF file.
dataProvider Data provider serving the source XFDF file.
Returns
  • Single that finishes after the parsing is performed, either by returning array of parsed annotation in `onSuccess()`, or `onError()`.

public static void writeXfdf (PdfDocument document, List<Annotation> annotations, List<FormField> formFields, OutputStream outputStream)

Generates an XFDF file out of provided annotations and form fields and writes the output to the given output stream.

Warning: this method runs on the current thread. If the current thread is the UI thread, it's recommended that you offload it to some other one, because this operation can take some time and thus block the UI.

Parameters
document Document containing given annotations and form fields.
annotations List of annotations to be parsed. The annotations need to be attached to the document, otherwise an exception is thrown.
formFields List of form fields to be parsed.
outputStream Output stream for writing the generated XFDF file.
Throws
IllegalArgumentException If one of the passed annotations isn't attached to the document.
IOException

public static Completable writeXfdfAsync (PdfDocument document, List<Annotation> annotations, List<FormField> formFields, OutputStream outputStream)

Generates an XFDF file out of provided annotations and form fields and writes the output to the given output stream.

Parameters
document Document containing given annotations and form fields.
annotations List of annotations to be parsed. The annotations need to be attached to the document, otherwise an exception is thrown.
formFields List of form fields to be parsed, or null.
outputStream Output stream for writing the generated XFDF file.
Returns
  • Completable that finishes after the writing is performed, either by returning `onComplete()` or `onError()`.
Throws
IllegalArgumentException If one of the passed annotations isn't attached to the document.