pdfdancer-client-python 0.2.19__py3-none-any.whl → 0.2.21__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pdfdancer-client-python might be problematic. Click here for more details.
- pdfdancer/__init__.py +2 -0
- pdfdancer/image_builder.py +30 -0
- pdfdancer/models.py +545 -58
- pdfdancer/page_builder.py +92 -0
- pdfdancer/paragraph_builder.py +392 -177
- pdfdancer/path_builder.py +252 -0
- pdfdancer/pdfdancer_v1.py +61 -22
- pdfdancer/types.py +112 -103
- {pdfdancer_client_python-0.2.19.dist-info → pdfdancer_client_python-0.2.21.dist-info}/METADATA +1 -1
- pdfdancer_client_python-0.2.21.dist-info/RECORD +16 -0
- pdfdancer_client_python-0.2.19.dist-info/RECORD +0 -15
- {pdfdancer_client_python-0.2.19.dist-info → pdfdancer_client_python-0.2.21.dist-info}/WHEEL +0 -0
- {pdfdancer_client_python-0.2.19.dist-info → pdfdancer_client_python-0.2.21.dist-info}/licenses/LICENSE +0 -0
- {pdfdancer_client_python-0.2.19.dist-info → pdfdancer_client_python-0.2.21.dist-info}/licenses/NOTICE +0 -0
- {pdfdancer_client_python-0.2.19.dist-info → pdfdancer_client_python-0.2.21.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
from .exceptions import ValidationException
|
|
6
|
+
from .models import Orientation, PageRef, PageSize, AddPageRequest
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class PageBuilder:
|
|
10
|
+
"""
|
|
11
|
+
Fluent builder for adding pages with optional orientation, size, and index.
|
|
12
|
+
|
|
13
|
+
Usage:
|
|
14
|
+
pdf.new_page().at_index(1).landscape().a4().add()
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
def __init__(self, client: 'PDFDancer') -> None:
|
|
18
|
+
if client is None:
|
|
19
|
+
raise ValidationException("Client cannot be null")
|
|
20
|
+
|
|
21
|
+
self._client = client
|
|
22
|
+
self._page_index: Optional[int] = None
|
|
23
|
+
self._orientation: Optional[Orientation] = None
|
|
24
|
+
self._page_size: Optional[PageSize] = None
|
|
25
|
+
|
|
26
|
+
def at_index(self, page_index: int) -> 'PageBuilder':
|
|
27
|
+
if page_index is None:
|
|
28
|
+
raise ValidationException("Page index cannot be null")
|
|
29
|
+
if page_index < 0:
|
|
30
|
+
raise ValidationException("Page index must be greater than or equal to 0")
|
|
31
|
+
self._page_index = int(page_index)
|
|
32
|
+
return self
|
|
33
|
+
|
|
34
|
+
def orientation(self, orientation: Orientation) -> 'PageBuilder':
|
|
35
|
+
if orientation is None:
|
|
36
|
+
raise ValidationException("Orientation cannot be null")
|
|
37
|
+
if isinstance(orientation, str):
|
|
38
|
+
normalized = orientation.strip().upper()
|
|
39
|
+
orientation = Orientation(normalized)
|
|
40
|
+
self._orientation = orientation
|
|
41
|
+
return self
|
|
42
|
+
|
|
43
|
+
def portrait(self) -> 'PageBuilder':
|
|
44
|
+
self._orientation = Orientation.PORTRAIT
|
|
45
|
+
return self
|
|
46
|
+
|
|
47
|
+
def landscape(self) -> 'PageBuilder':
|
|
48
|
+
self._orientation = Orientation.LANDSCAPE
|
|
49
|
+
return self
|
|
50
|
+
|
|
51
|
+
def page_size(self, page_size: PageSize) -> 'PageBuilder':
|
|
52
|
+
if page_size is None:
|
|
53
|
+
raise ValidationException("Page size cannot be null")
|
|
54
|
+
self._page_size = PageSize.coerce(page_size)
|
|
55
|
+
return self
|
|
56
|
+
|
|
57
|
+
def a4(self) -> 'PageBuilder':
|
|
58
|
+
self._page_size = PageSize.A4
|
|
59
|
+
return self
|
|
60
|
+
|
|
61
|
+
def letter(self) -> 'PageBuilder':
|
|
62
|
+
self._page_size = PageSize.LETTER
|
|
63
|
+
return self
|
|
64
|
+
|
|
65
|
+
def a3(self) -> 'PageBuilder':
|
|
66
|
+
self._page_size = PageSize.A3
|
|
67
|
+
return self
|
|
68
|
+
|
|
69
|
+
def a5(self) -> 'PageBuilder':
|
|
70
|
+
self._page_size = PageSize.A5
|
|
71
|
+
return self
|
|
72
|
+
|
|
73
|
+
def legal(self) -> 'PageBuilder':
|
|
74
|
+
self._page_size = PageSize.LEGAL
|
|
75
|
+
return self
|
|
76
|
+
|
|
77
|
+
def custom_size(self, width: float, height: float) -> 'PageBuilder':
|
|
78
|
+
self._page_size = PageSize(name=None, width=width, height=height)
|
|
79
|
+
return self
|
|
80
|
+
|
|
81
|
+
def add(self) -> PageRef:
|
|
82
|
+
request = self._build_request()
|
|
83
|
+
return self._client._add_page(request)
|
|
84
|
+
|
|
85
|
+
def _build_request(self) -> Optional[AddPageRequest]:
|
|
86
|
+
if self._page_index is None and self._orientation is None and self._page_size is None:
|
|
87
|
+
return None
|
|
88
|
+
return AddPageRequest(
|
|
89
|
+
page_index=self._page_index,
|
|
90
|
+
orientation=self._orientation,
|
|
91
|
+
page_size=self._page_size
|
|
92
|
+
)
|