API Reference
Complete class and method reference for DroidPDF.
com.droidpdf.core
PdfDocument
| Method | Description |
PdfDocument(outputStream) | Create a new PDF for writing |
PdfDocument(reader) | Open an existing PDF for reading |
PdfDocument(reader, outputStream) | Open for modification |
addNewPage(pageSize?) | Add a blank page (default A4) |
getPage(index) | Get page by 0-based index |
numberOfPages | Total page count |
removePage(index) | Remove a page |
movePage(from, to) | Move a page |
close() | Write and close the document |
PdfPage
| Method | Description |
width / height | Page dimensions in points |
setRotation(degrees) | Set rotation (0/90/180/270) |
addAnnotation(dict) | Add an annotation |
addFont(dict) | Register a font resource |
addXObject(obj) | Register an image resource |
PageSize
| Constant | Size (points) |
PageSize.A4 | 595 × 842 |
PageSize.A3 | 842 × 1191 |
PageSize.A5 | 420 × 595 |
PageSize.LETTER | 612 × 792 |
PageSize.LEGAL | 612 × 1008 |
PageSize(w, h) | Custom size |
PdfReader
| Method | Description |
PdfReader(inputStream) | Parse an existing PDF |
getObject(objNum) | Get a parsed object by number |
resolve(obj) | Resolve indirect references |
getCatalog() | Get the document catalog |
TextExtractor
| Method | Description |
TextExtractor(reader) | Create from a PdfReader |
extractAll() | Extract text from all pages |
extractFromPage(index) | Extract text from one page |
search(query) | Search text (case-insensitive) |
com.droidpdf.content
PdfFont
| Method | Description |
PdfFont.helvetica() | Helvetica (standard) |
PdfFont.helveticaBold() | Helvetica Bold |
PdfFont.timesRoman() | Times Roman |
PdfFont.courier() | Courier |
PdfFont.createFromTtf(stream) | Load TTF font |
PdfFont.createFromOtf(stream) | Load OTF font |
registerOn(page) | Register on page, returns name |
getTextWidth(text, size) | Measure text width in points |
com.droidpdf.layout
Document
| Method | Description |
Document(pdfDoc, pageSize?) | Create layout document |
add(element) | Add a layout element |
setMargins(top, right, bottom, left) | Set page margins |
close() | Finalize and close |
Paragraph / Table / Image
See the Text, Images & Tables documentation for usage details.
com.droidpdf.manipulation
PdfMerger
val merger = PdfMerger(outputStream)
merger.merge(inputStream1) // all pages
merger.merge(inputStream2, 2, 5) // pages 2-5
merger.close()
PdfSplitter
val splitter = PdfSplitter(inputStream)
splitter.extractPages(1, 3, outputStream) // pages 1-3
splitter.extractPages(listOf(1,3,5), output) // specific pages
splitter.splitByPage { page -> getOutputStream(page) }
com.droidpdf.annotations
| Class | Type |
PdfTextAnnotation | Sticky note |
PdfHighlightAnnotation | Text highlight |
PdfUnderlineAnnotation | Text underline |
PdfStrikeoutAnnotation | Strikethrough |
PdfFreeTextAnnotation | Text box |
PdfStampAnnotation | Stamp (Approved, Draft, etc.) |
PdfSquareAnnotation | Rectangle |
PdfCircleAnnotation | Circle / Ellipse |
PdfLineAnnotation | Line |
PdfInkAnnotation | Freehand drawing |
PdfLinkAnnotation | Hyperlink |
| Class | Type |
TextField | Text input |
CheckboxField | Checkbox |
RadioButtonField | Radio button group |
DropdownField | Dropdown / Combo box |
PdfAcroForm | Form field manager |
com.droidpdf.security
PdfEncryption.Builder
val encryption = PdfEncryption.Builder()
.setUserPassword("user123")
.setOwnerPassword("admin456")
.setKeyLength(256) // 128 or 256
.allowPrinting(true)
.allowCopying(false)
.build()