Skip to content

Commit cdac459

Browse files
committed
feat: improve documentation and add tests for existing features
This PR verifies and improves the implementation of three quick-win features that were already implemented in the recent refactoring: 1. Image Watermark Support (Issue #11) - Already supports FileInput (str, Path, bytes, file-like, URL) - Improved docstring with comprehensive examples - Added unit tests for bytes and Path inputs 2. Multi-Language OCR Support (Issue #10) - Already supports List[OcrLanguage] for multiple languages - Improved docstring with multi-language examples - Added unit tests for three languages and ISO codes 3. Selective Annotation Flattening (Issue #12) - Already supports annotation_ids parameter (str or int) - Improved docstring with examples for string, int, and mixed IDs - Added comprehensive unit tests for all ID types All features maintain backward compatibility. 257 unit tests passing.
1 parent 96e4e57 commit cdac459

File tree

2 files changed

+404
-6
lines changed

2 files changed

+404
-6
lines changed

src/nutrient_dws/client.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -440,18 +440,35 @@ async def watermark_image(
440440
441441
Args:
442442
file: The input file to watermark
443-
image: The watermark image
443+
image: The watermark image. Can be a file path (string or Path),
444+
bytes, file-like object, or a URL to a remote image.
444445
options: Watermark options
445446
446447
Returns:
447448
The watermarked document
448449
449450
Example:
450451
```python
451-
result = await client.watermark_image('document.pdf', 'watermark.jpg', {
452+
# Using a local file path
453+
result = await client.watermark_image('document.pdf', 'watermark.png', {
452454
'opacity': 0.5
453455
})
454456
457+
# Using a Path object
458+
from pathlib import Path
459+
result = await client.watermark_image('document.pdf', Path('logo.png'))
460+
461+
# Using bytes (e.g., from a database or API)
462+
with open('logo.png', 'rb') as f:
463+
image_bytes = f.read()
464+
result = await client.watermark_image('document.pdf', image_bytes)
465+
466+
# Using a remote URL
467+
result = await client.watermark_image(
468+
'document.pdf',
469+
'https://example.com/logo.png'
470+
)
471+
455472
# Access the watermarked PDF buffer
456473
pdf_buffer = result['buffer']
457474
```
@@ -531,15 +548,20 @@ async def ocr(
531548
532549
Args:
533550
file: The input file to perform OCR on
534-
language: The language(s) to use for OCR
551+
language: The language(s) to use for OCR. Can be a single language
552+
or a list of languages for multi-language documents.
535553
536554
Returns:
537555
The OCR result
538556
539557
Example:
540558
```python
559+
# Single language OCR
541560
result = await client.ocr('scanned-document.pdf', 'english')
542561
562+
# Multi-language OCR for documents with mixed content
563+
result = await client.ocr('multilang-document.pdf', ['english', 'german', 'french'])
564+
543565
# Access the OCR-processed PDF buffer
544566
pdf_buffer = result['buffer']
545567
```
@@ -952,7 +974,9 @@ async def flatten(
952974
953975
Args:
954976
pdf: The PDF file to flatten
955-
annotation_ids: Optional specific annotation IDs to flatten
977+
annotation_ids: Optional list of specific annotation IDs to flatten.
978+
If not provided, all annotations are flattened. IDs can be
979+
strings or integers.
956980
957981
Returns:
958982
The flattened document
@@ -962,8 +986,14 @@ async def flatten(
962986
# Flatten all annotations
963987
result = await client.flatten('annotated-document.pdf')
964988
965-
# Flatten specific annotations by ID
989+
# Flatten specific annotations by string ID
966990
result = await client.flatten('annotated-document.pdf', ['annotation1', 'annotation2'])
991+
992+
# Flatten specific annotations by integer ID
993+
result = await client.flatten('annotated-document.pdf', [1, 2, 3])
994+
995+
# Mix of string and integer IDs
996+
result = await client.flatten('annotated-document.pdf', ['note1', 2, 'highlight3'])
967997
```
968998
"""
969999
# Validate PDF

0 commit comments

Comments
 (0)