The SDK depends on forked versions of PdfiumAndroid and AndroidPdfViewer whose artifacts are stored on iText Artifactory. Artifacts will be loaded during the SDK build by gradle.
If you want to build SDK with custom version of PdfiumAndroid or\and AndroidPdfViewer you need to clone repositories, make necessary changes and then publish them to local maven storage. So SDK will use custom local artifacts as dependencies.
Do not use spaces in your local paths/directories, as it can lead to all sorts of errors related to Android NDK, ndk-build or cmake.
If you are having problems related to Android NDK, make sure to follow the correct setup procedure: https://developer.android.com/studio/projects/install-ndk
The SDK provides different Fragments and classes to manipulate PDF files.
You can create a new instance of PdfFragment via code:
private fun showPdfFragment(pdfUri: Uri) {
// See PdfConfig for all available customization options
val config = PdfConfig(pdfUri = pdfUri, showScrollIndicator = true)
// Create PdfFragment
val pdfFragment = PdfFragment.newInstance(pdfConfig)
// show fragment, e.g. via supportFragmentManager
}
You can also inflate a PDF fragment via XML. In thise case, the fragment is customizable via different styleables, such as app:enable_split_view, etc.
<!-- The PDF fragment can be configured in XML via different styleables, such as app:enable_split_view, etc. -->
<androidx.fragment.app.FragmentContainerView
android:id="@+id/pdf_fragment_container"
android:name="com.itextpdf.android.library.fragments.PdfFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:background_color="#F4EFBB"
app:display_file_name="true"
app:file_name="sample_1.pdf"
app:file_uri="file:///storage/emulated/0/Android/data/com.itextpdf.android.app/cache/sample_1_copy.pdf"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:enable_split_view="false"
app:page_spacing="400"
app:primary_color="#217C12"
app:secondary_color="#C6E6C1" />
You can directly launch fragment to split PDF documents via...
private fun showSplitFragment(pdfUri: Uri) {
val config = PdfConfig(pdfUri = pdfUri, showScrollIndicator = true)
val splitFragment = SplitDocumentFragment.newInstance(config)
// show fragment, e.g. via supportFragmentManager
}
You can directly manipulate PDF files without showing a Fragment-UI by using the PDFManipulator:
val manipulator = PdfManipulator.create(requireContext(), pdfUri)
manipulator.addTextAnnotationToPdf(...)
manipulator.splitPdfWithSelection(...)
manipulator.addMarkupAnnotationToPdf(...)
// etc...
You can receive fragment results by registering a fragment result listener to your fragmentManager.
private fun listenForPdfFragmentResult(fragmentManager: FragmentManager) {
fragmentManager.setFragmentResultListener(PdfFragment.REQUEST_KEY, this) { requestKey: String, bundle: Bundle ->
// Retrieve fragment result from bundle
val result: PdfResult? = bundle.getParcelable(PdfFragment.RESULT_FILE)
when (result) {
is PdfResult.CancelledByUser -> // ...
is PdfResult.PdfEdited -> // ...
is PdfResult.PdfSplit -> // ...
is PdfResult.NoChanges -> // ...
null -> // ...
}
}
}