|
| 1 | +# Supported Operations |
| 2 | + |
| 3 | +This document lists all operations currently supported by the Nutrient DWS API through this Python client. |
| 4 | + |
| 5 | +## Direct API Methods |
| 6 | + |
| 7 | +The following methods are available on the `NutrientClient` instance: |
| 8 | + |
| 9 | +### 1. `flatten_annotations(input_file, output_path=None)` |
| 10 | +Flattens all annotations and form fields in a PDF, converting them to static page content. |
| 11 | + |
| 12 | +**Parameters:** |
| 13 | +- `input_file`: PDF file (path, bytes, or file-like object) |
| 14 | +- `output_path`: Optional path to save output |
| 15 | + |
| 16 | +**Example:** |
| 17 | +```python |
| 18 | +client.flatten_annotations("document.pdf", "flattened.pdf") |
| 19 | +``` |
| 20 | + |
| 21 | +### 2. `rotate_pages(input_file, output_path=None, degrees=0, page_indexes=None)` |
| 22 | +Rotates pages in a PDF. |
| 23 | + |
| 24 | +**Parameters:** |
| 25 | +- `input_file`: PDF file |
| 26 | +- `output_path`: Optional output path |
| 27 | +- `degrees`: Rotation angle (90, 180, 270, or -90) |
| 28 | +- `page_indexes`: Optional list of page indexes to rotate (0-based) |
| 29 | + |
| 30 | +**Example:** |
| 31 | +```python |
| 32 | +# Rotate all pages 90 degrees |
| 33 | +client.rotate_pages("document.pdf", "rotated.pdf", degrees=90) |
| 34 | + |
| 35 | +# Rotate specific pages |
| 36 | +client.rotate_pages("document.pdf", "rotated.pdf", degrees=180, page_indexes=[0, 2]) |
| 37 | +``` |
| 38 | + |
| 39 | +### 3. `ocr_pdf(input_file, output_path=None, language="english")` |
| 40 | +Applies OCR to make a PDF searchable. |
| 41 | + |
| 42 | +**Parameters:** |
| 43 | +- `input_file`: PDF file |
| 44 | +- `output_path`: Optional output path |
| 45 | +- `language`: OCR language - supported values: |
| 46 | + - `"english"` or `"eng"` - English |
| 47 | + - `"deu"` or `"german"` - German |
| 48 | + |
| 49 | +**Example:** |
| 50 | +```python |
| 51 | +client.ocr_pdf("scanned.pdf", "searchable.pdf", language="english") |
| 52 | +``` |
| 53 | + |
| 54 | +### 4. `watermark_pdf(input_file, output_path=None, text=None, image_url=None, width=200, height=100, opacity=1.0, position="center")` |
| 55 | +Adds a watermark to all pages of a PDF. |
| 56 | + |
| 57 | +**Parameters:** |
| 58 | +- `input_file`: PDF file |
| 59 | +- `output_path`: Optional output path |
| 60 | +- `text`: Text for watermark (either text or image_url required) |
| 61 | +- `image_url`: URL of image for watermark |
| 62 | +- `width`: Width in points (required) |
| 63 | +- `height`: Height in points (required) |
| 64 | +- `opacity`: Opacity from 0.0 to 1.0 |
| 65 | +- `position`: One of: "top-left", "top-center", "top-right", "center", "bottom-left", "bottom-center", "bottom-right" |
| 66 | + |
| 67 | +**Example:** |
| 68 | +```python |
| 69 | +# Text watermark |
| 70 | +client.watermark_pdf( |
| 71 | + "document.pdf", |
| 72 | + "watermarked.pdf", |
| 73 | + text="CONFIDENTIAL", |
| 74 | + width=300, |
| 75 | + height=150, |
| 76 | + opacity=0.5, |
| 77 | + position="center" |
| 78 | +) |
| 79 | +``` |
| 80 | + |
| 81 | +### 5. `apply_redactions(input_file, output_path=None)` |
| 82 | +Applies redaction annotations to permanently remove content. |
| 83 | + |
| 84 | +**Parameters:** |
| 85 | +- `input_file`: PDF file with redaction annotations |
| 86 | +- `output_path`: Optional output path |
| 87 | + |
| 88 | +**Example:** |
| 89 | +```python |
| 90 | +client.apply_redactions("document_with_redactions.pdf", "redacted.pdf") |
| 91 | +``` |
| 92 | + |
| 93 | +### 6. `merge_pdfs(input_files, output_path=None)` |
| 94 | +Merges multiple PDF files into one. |
| 95 | + |
| 96 | +**Parameters:** |
| 97 | +- `input_files`: List of PDF files to merge |
| 98 | +- `output_path`: Optional output path |
| 99 | + |
| 100 | +**Example:** |
| 101 | +```python |
| 102 | +client.merge_pdfs( |
| 103 | + ["document1.pdf", "document2.pdf", "document3.pdf"], |
| 104 | + "merged.pdf" |
| 105 | +) |
| 106 | +``` |
| 107 | + |
| 108 | +## Builder API |
| 109 | + |
| 110 | +The Builder API allows chaining multiple operations: |
| 111 | + |
| 112 | +```python |
| 113 | +client.build(input_file="document.pdf") \ |
| 114 | + .add_step("rotate-pages", {"degrees": 90}) \ |
| 115 | + .add_step("ocr-pdf", {"language": "english"}) \ |
| 116 | + .add_step("watermark-pdf", { |
| 117 | + "text": "DRAFT", |
| 118 | + "width": 200, |
| 119 | + "height": 100, |
| 120 | + "opacity": 0.3 |
| 121 | + }) \ |
| 122 | + .add_step("flatten-annotations") \ |
| 123 | + .execute(output_path="processed.pdf") |
| 124 | +``` |
| 125 | + |
| 126 | +### Supported Builder Actions |
| 127 | + |
| 128 | +1. **flatten-annotations** - No parameters required |
| 129 | +2. **rotate-pages** - Parameters: `degrees`, `page_indexes` (optional) |
| 130 | +3. **ocr-pdf** - Parameters: `language` |
| 131 | +4. **watermark-pdf** - Parameters: `text` or `image_url`, `width`, `height`, `opacity`, `position` |
| 132 | +5. **apply-redactions** - No parameters required |
| 133 | + |
| 134 | +## API Limitations |
| 135 | + |
| 136 | +The following operations are **NOT** currently supported by the API: |
| 137 | + |
| 138 | +- Document conversion (Office to PDF, HTML to PDF) |
| 139 | +- PDF to image export |
| 140 | +- PDF splitting |
| 141 | +- Form filling |
| 142 | +- Digital signatures |
| 143 | +- Compression/optimization |
| 144 | +- Linearization |
| 145 | +- Creating redactions (only applying existing ones) |
| 146 | +- Instant JSON annotations |
| 147 | +- XFDF annotations |
| 148 | + |
| 149 | +## Language Support |
| 150 | + |
| 151 | +OCR currently supports: |
| 152 | +- English (`"english"` or `"eng"`) |
| 153 | +- German (`"deu"` or `"german"`) |
| 154 | + |
| 155 | +## File Input Types |
| 156 | + |
| 157 | +All methods accept files as: |
| 158 | +- String paths: `"document.pdf"` |
| 159 | +- Path objects: `Path("document.pdf")` |
| 160 | +- Bytes: `b"...pdf content..."` |
| 161 | +- File-like objects: `open("document.pdf", "rb")` |
| 162 | + |
| 163 | +## Error Handling |
| 164 | + |
| 165 | +Common exceptions: |
| 166 | +- `AuthenticationError` - Invalid or missing API key |
| 167 | +- `APIError` - General API errors with status code |
| 168 | +- `ValidationError` - Invalid parameters |
| 169 | +- `FileNotFoundError` - File not found |
| 170 | +- `ValueError` - Invalid input values |
0 commit comments