Java interface changes for PDF Toolbox SDK
There are several changes in naming and behavior in the Java interface to bear in mind when migrating from the the 3-Heights® PDF Toolbox API to the PDF Toolbox SDK.
Namespaces
The company namespace of PDF Tools AG is com.pdf_tools, both in the 3-Heights® PDF Toolbox API and in the PDF Toolbox SDK.
In the 3-Heights® PDF Toolbox API, most interface elements reside in the namespace com.pdf_tools.pdf, except for the following type, which reside directly in com.pdf_tools:
- Point
- Rectangle
- Size
- ErrorCode
- ErrorCodeException
- FileStream
- MemoryStream
- Stream
The PDF Toolbox SDK introduces the following new namespaces:
| Namespace | Area of usage |
|---|---|
com.pdf_tools.fourheights.pdftoolbox | Base namespace |
com.pdf_tools.fourheights.pdftoolbox.geometry | Geometric related |
com.pdf_tools.fourheights.pdftoolbox.geometry.real | For floating point numbers |
com.pdf_tools.fourheights.pdftoolbox.geometry.integer | For integer numbers |
com.pdf_tools.fourheights.pdftoolbox.pdf | General PDF related |
com.pdf_tools.fourheights.pdftoolbox.pdf.annotations | Annotation related |
com.pdf_tools.fourheights.pdftoolbox.pdf.content | Page content related |
com.pdf_tools.fourheights.pdftoolbox.Pdf.Forms | Form field related |
com.pdf_tools.fourheights.pdftoolbox.pdf.navigation | Document navigation related |
The Sdk class
License keys and product version
In the 3-Heights® PDF Toolbox API, the public methods setLicenseKey and getProductVersion of the common base class internal.NativeObject allows setting a license key and querying the version of the API.
In the PDF Toolbox SDK, this functionality has been moved to the class Sdk. Specifically:
Sdk.initializemust be called to set a license key. See also License keys.Sdk.getVersiongets the API’s version number as a string.
The PDF Producer entry
In the 3-Heights® PDF Toolbox API, when creating a PDF, the Metadata object sets the PDF’s Producer entry via the method Metadata.setProducer.
In the PDF Toolbox SDK, the class pdf.Metadata has no method pdf.Metadata.setProducer. Instead, the Producer entry for all output PDFs is preconfigured as a string consisting of two parts:
- The first part (the “base” part) is encoded in the license key. Hence, this part is determined when buying a license from Pdftools.
- The second part (the “suffix” part) is configured when calling
Sdk.initializeas an argument. It is recommended to use the suffix solely for version information.
The assembled Producer entry can be obtained after callingSdk.initializeusing the methodSdk.getProducerFullName.
AutoCloseable implementation removed
In the PDF Toolbox SDK, the implementation of the AutoCloseable interface has been removed from all but the following classes:
DocumentContentGeneratorTextGeneratorStream
Native resources are now released automatically when getting or appending a page.
Structs extend NativeBase
In the 3-Heights® PDF Toolbox API, interface elements documented as struct are independent Java classes.
In the PDF Toolbox SDK, these structs are still Java classes, but they now extend com.pdf_tools.fourheights.pdftoolbox.internal.NativeBase. As a consequence, an attempt to load the native library (if not already loaded) is done when constructing a struct. This is due to the static constructor in this base class.