Class PDFreactor
PDFreactor
converts HTML and XML documents into PDF or image.
This sample demonstrates the use of PDFreactor:
PDFreactor
pdfReactor = new PDFreactor
();
Configuration
config = new Configuration
();
//required
config.setDocument("https://www.realobjects.com/");
Result
result = pdfReactor.convert(config);
byte[] pdf = result.getDocument();
Important: On a system without a graphical environment you have to enable the headless mode by setting the appropriate system property. Please see the manual for details.
For more information please have a look at the PDFreactor manual.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionconvert
(Configuration configuration) Converts the specifiedConfiguration
into PDF or image.convert
(Configuration configuration, OutputStreamProvider function) Converts the specifiedConfiguration
into PDF or image and writes it intoOutputStream
(s) created by the supplied function.convert
(Configuration configuration, OutputStream outputStream) Converts the specifiedConfiguration
into PDF or image and writes it directly in the suppliedOutputStream
.byte[]
convertAsBinary
(Configuration configuration) Converts the specifiedConfiguration
into PDF or image.void
convertAsBinary
(Configuration configuration, OutputStream outputStream) Converts the specifiedConfiguration
into PDF or image and writes it directly in the suppliedOutputStream
.static final void
preinit()
Pre-initializes parts of PDFreactor in separate threads to improve the performance of the first conversion.
-
Field Details
-
VERSION
-
-
Constructor Details
-
PDFreactor
public PDFreactor()
-
-
Method Details
-
convert
Converts the specified
Configuration
into PDF or image.- Parameters:
configuration
- TheConfiguration
.- Returns:
- The
Result
. - Throws:
PDFreactorException
- If the conversion could not be completed.
-
convertAsBinary
Converts the specified
Configuration
into PDF or image.- Parameters:
configuration
- TheConfiguration
.- Returns:
- The resulting PDF or image.
- Throws:
PDFreactorException
- If the conversion could not be completed.
-
convertAsBinary
public void convertAsBinary(Configuration configuration, OutputStream outputStream) throws PDFreactorException Converts the specified
Configuration
into PDF or image and writes it directly in the suppliedOutputStream
.- Parameters:
configuration
- TheConfiguration
.outputStream
- TheOutputStream
to write into.- Throws:
PDFreactorException
- If the conversion could not be completed.
-
convert
public Result convert(Configuration configuration, OutputStream outputStream) throws PDFreactorException Converts the specified
Configuration
into PDF or image and writes it directly in the suppliedOutputStream
.Note that the
Result.getDocument()
and theResult.getDocumentArray()
methods will always returnnull
.- Parameters:
configuration
- TheConfiguration
.outputStream
- TheOutputStream
to write into.- Returns:
- The
Result
. - Throws:
PDFreactorException
- If the conversion could not be completed.
-
convert
public Result convert(Configuration configuration, OutputStreamProvider function) throws PDFreactorException Converts the specified
Configuration
into PDF or image and writes it intoOutputStream
(s) created by the supplied function.The supplied function must take an
OutputItemImpl
and returns anOutputStream
This convert method can be used to write results directly to
OutputStream
(s).Note that the
Result.getDocument()
and theResult.getDocumentArray()
methods will always returnnull
.Note that multiple images are generate for image
Configuration.OutputFormat
if
Configuration.OutputFormat.setMultiImage(Boolean)
is not explicitly set to false.- Parameters:
configuration
- TheConfiguration
.function
- The function which creates OutputStreams.- Returns:
- The
Result
. - Throws:
PDFreactorException
- If the conversion could not be completed or theOutputStream
could not be created by the supplied function.
-
preinit
public static final void preinit()Pre-initializes parts of PDFreactor in separate threads to improve the performance of the first conversion. This is only relevant in environments where the performance of the first conversion is important, e.g. command-line or cloud. This method should be called as early as possible, but even calling it right before conversions improves performance. Calling this method repeatedly is fast and safe to do, as it has no further effect.
-