Class PdfBatchUtils
java.lang.Object
org.openpdf.text.pdf.PdfBatchUtils
The PdfBatchUtils class provides high-level utilities for performing common PDF operations—such as merging, watermarking, encrypting, and splitting—in batch mode
using Java 21 virtual threads for efficient concurrent execution.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordEncrypt a PDF with given passwords and permissions.static final recordMerge several PDFs into one.static final recordSplit one PDF into per-page PDFs in the given directory (files will be named baseName_pageX.pdf).static final recordAdd a semi-transparent text watermark to all pages. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intaes128()AES 128 vs 256 convenience.static intaes256()static PdfBatch.BatchResult<Path> batchEncrypt(List<PdfBatchUtils.EncryptJob> jobs, Consumer<Path> onSuccess, Consumer<Throwable> onFailure) Batch encrypt.static PdfBatch.BatchResult<Path> batchMerge(List<PdfBatchUtils.MergeJob> jobs, Consumer<Path> onSuccess, Consumer<Throwable> onFailure) Batch merge.static PdfBatch.BatchResult<List<Path>> batchSplit(List<PdfBatchUtils.SplitJob> jobs, Consumer<List<Path>> onSuccess, Consumer<Throwable> onFailure) Batch split.static PdfBatch.BatchResult<Path> batchWatermark(List<PdfBatchUtils.WatermarkJob> jobs, Consumer<Path> onSuccess, Consumer<Throwable> onFailure) Batch watermark.private static voidSmall utility for closing Closeables, ignoring exceptions.static Pathencrypt(Path input, Path output, String userPassword, String ownerPassword, int permissions, int encryptionType) Encrypt one PDF.static PathMerge one set of inputs into a single output file.static intperms(boolean print, boolean modify, boolean copy, boolean annotate) Quick permissions helper.Split one PDF to per-page PDFs.static PathWatermark one PDF with text on every page (centered, diagonal).
-
Constructor Details
-
PdfBatchUtils
private PdfBatchUtils()
-
-
Method Details
-
merge
Merge one set of inputs into a single output file.- Throws:
IOExceptionDocumentException
-
batchMerge
public static PdfBatch.BatchResult<Path> batchMerge(List<PdfBatchUtils.MergeJob> jobs, Consumer<Path> onSuccess, Consumer<Throwable> onFailure) Batch merge. -
watermark
public static Path watermark(Path input, Path output, String text, float fontSize, float opacity) throws IOException, DocumentException Watermark one PDF with text on every page (centered, diagonal).- Throws:
IOExceptionDocumentException
-
batchWatermark
public static PdfBatch.BatchResult<Path> batchWatermark(List<PdfBatchUtils.WatermarkJob> jobs, Consumer<Path> onSuccess, Consumer<Throwable> onFailure) Batch watermark. -
encrypt
public static Path encrypt(Path input, Path output, String userPassword, String ownerPassword, int permissions, int encryptionType) throws IOException, DocumentException Encrypt one PDF.- Throws:
IOExceptionDocumentException
-
batchEncrypt
public static PdfBatch.BatchResult<Path> batchEncrypt(List<PdfBatchUtils.EncryptJob> jobs, Consumer<Path> onSuccess, Consumer<Throwable> onFailure) Batch encrypt. -
split
public static List<Path> split(Path input, Path outputDir, String baseName) throws IOException, DocumentException Split one PDF to per-page PDFs.- Throws:
IOExceptionDocumentException
-
batchSplit
public static PdfBatch.BatchResult<List<Path>> batchSplit(List<PdfBatchUtils.SplitJob> jobs, Consumer<List<Path>> onSuccess, Consumer<Throwable> onFailure) Batch split. -
perms
public static int perms(boolean print, boolean modify, boolean copy, boolean annotate) Quick permissions helper. -
aes128
public static int aes128()AES 128 vs 256 convenience. -
aes256
public static int aes256() -
closeQuietly
Small utility for closing Closeables, ignoring exceptions.
-