convert-stream 1.1__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 convert-stream might be problematic. Click here for more details.

@@ -0,0 +1,171 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ #
4
+ from __future__ import annotations
5
+ from abc import abstractmethod, ABC
6
+ from typing import List
7
+
8
+ from soup_files import File, Directory
9
+ from convertlib.models.m_imgelib import ABCImageObject, LibraryImage
10
+ from convertlib.models.m_pdf_page import ABCPagePdf, LibraryPDF
11
+ from convertlib.models.m_pdf_document import ABCDocumentPdf, ABCPagePdf
12
+
13
+
14
+ class ABCConvertPdf(ABC):
15
+ """
16
+ Converte um documento PDF ou Página de PDF em imagem(s).
17
+ """
18
+ def __init__(self):
19
+ super().__init__()
20
+
21
+ @abstractmethod
22
+ def from_page_bytes(self, page_bytes:bytes, dpi:int=200) -> ABCImageObject:
23
+ """
24
+ Converte os bytes de uma página PDF em objeto Imagem.
25
+ """
26
+ pass
27
+
28
+ @abstractmethod
29
+ def from_page_pdf(self, page:ABCPagePdf, dpi:int=200) -> ABCImageObject:
30
+ """
31
+ Converte o um objeto PageDocumentPdf() em objeto Imagem.
32
+ """
33
+ pass
34
+
35
+ @abstractmethod
36
+ def inner_images(self, page_bytes:bytes) -> List[ABCImageObject]:
37
+ """
38
+ Converte todas as imagens embutidas em uma página PDF para uma lista de objetos Imagem.
39
+ """
40
+ pass
41
+
42
+
43
+ class ABCImageConvertPdf(ABC):
44
+ """Convete uma imagem em uma página PDF."""
45
+ def __init__(self, library_image:LibraryImage=LibraryImage.OPENCV):
46
+ super().__init__()
47
+ self.library_image:LibraryImage = library_image
48
+
49
+ @abstractmethod
50
+ def from_image_file(self, file:File) -> ABCPagePdf:
51
+ """
52
+ Converte um arquivo de imagem em página PDF.
53
+ """
54
+ pass
55
+
56
+ @abstractmethod
57
+ def from_image(self, img:ABCImageObject) -> ABCDocumentPdf:
58
+ """Converte um objeto imagem em uma página PDF."""
59
+ pass
60
+
61
+ @abstractmethod
62
+ def from_image_bytes(self, img_bytes:bytes) -> ABCPagePdf:
63
+ """Converte os bytes de uma imagem e uma página PDF."""
64
+ pass
65
+
66
+
67
+ class ABCDocumentStream(ABC):
68
+ """
69
+ Objeto para manipular a exportação de dados PDF
70
+ """
71
+ def __init__(self, *, library_pdf=LibraryPDF.FITZ, library_image=LibraryImage.OPENCV):
72
+ self.library_pdf:LibraryPDF = library_pdf
73
+ self.liabrary_image:LibraryImage = library_image
74
+
75
+ @abstractmethod
76
+ def is_null(self) -> bool:
77
+ pass
78
+
79
+ @abstractmethod
80
+ def clear(self):
81
+ pass
82
+
83
+ @abstractmethod
84
+ def to_file_pdf(self, f:File):
85
+ """
86
+ Exporta os dados para um arquivo PDF no disco.
87
+ """
88
+ pass
89
+
90
+ @abstractmethod
91
+ def to_files_pdf(self, outdir:Directory, *, prefix='pag'):
92
+ """Exporta cada página para um novo arquivo PDF no disco"""
93
+ pass
94
+
95
+ @abstractmethod
96
+ def to_files_image(self, d:Directory, *, prefix:str='página-para-imagem'):
97
+ """
98
+ Exporta cada página PDF como um arquivo de imagem.
99
+ """
100
+ pass
101
+
102
+ @abstractmethod
103
+ def to_images(self) -> List[ABCImageObject]:
104
+ """Retorna uma lista de imagens, dos documentos adicionados."""
105
+ pass
106
+
107
+ @abstractmethod
108
+ def to_document(self) -> ABCDocumentPdf:
109
+ """Converte os itens adicionados em documento"""
110
+ pass
111
+
112
+ def inner_images(self) -> List[ABCImageObject]:
113
+ """
114
+ Retorna uma lista com todas as imagens presentes em todas as páginas
115
+ """
116
+ pass
117
+
118
+ @abstractmethod
119
+ def inner_images_to_files(self, d:Directory, prefix:str='página-para-imagens') -> None:
120
+ """
121
+ Salva todas as imagens presentes nas páginas em arquivos de imagem.
122
+ """
123
+ pass
124
+
125
+ @abstractmethod
126
+ def add_page(self, p:ABCPagePdf):
127
+ """Adiciona uma página PDF"""
128
+ pass
129
+
130
+ @abstractmethod
131
+ def add_pages(self, pages:List[ABCPagePdf]):
132
+ pass
133
+
134
+ @abstractmethod
135
+ def add_page_pdf_bytes(self, bt:bytes):
136
+ """Adicona os bytes de uma página PDF."""
137
+ pass
138
+
139
+ @abstractmethod
140
+ def add_file_pdf(self, f:File):
141
+ pass
142
+
143
+ @abstractmethod
144
+ def add_files_pdf(self, files:List[File]):
145
+ pass
146
+
147
+ @abstractmethod
148
+ def add_document(self, doc:ABCDocumentPdf):
149
+ pass
150
+
151
+ @abstractmethod
152
+ def add_image(self, image: ABCImageObject):
153
+ pass
154
+
155
+ @abstractmethod
156
+ def set_paisagem(self):
157
+ """Define todas as páginas como paisagem."""
158
+ pass
159
+
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+
@@ -0,0 +1,139 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ #
4
+ from __future__ import annotations
5
+ from abc import abstractmethod, ABC
6
+ from enum import Enum
7
+ from io import BytesIO
8
+ from typing import List, Dict
9
+ from pandas import DataFrame
10
+
11
+ from soup_files import File
12
+ from convertlib.models.m_pdf_page import LibraryPDF, ABCPagePdf
13
+
14
+
15
+ class ABCDocumentPdf(ABC):
16
+ def __init__(self, library:LibraryPDF=LibraryPDF.PYPDF):
17
+ self.__pages:List[ABCPagePdf] = []
18
+ self.__num_pages:int = 0
19
+ self.library:LibraryPDF = library
20
+ self.__max_num_pages:int= 4000
21
+
22
+ @property
23
+ def max_num_pages(self) -> int:
24
+ return self.__max_num_pages
25
+
26
+ @max_num_pages.setter
27
+ def max_num_pages(self, new:int):
28
+ if isinstance(new, int):
29
+ self.__max_num_pages = new
30
+
31
+ @property
32
+ def num_pages(self) -> int:
33
+ return self.__num_pages
34
+
35
+ @num_pages.setter
36
+ def num_pages(self, new:int):
37
+ if not isinstance(new, int):
38
+ print(f'Número inválido...')
39
+ return
40
+ self.__num_pages = new
41
+
42
+ @property
43
+ def pages(self) -> List[ABCPagePdf]:
44
+ return self.__pages
45
+
46
+ @pages.setter
47
+ def pages(self, new:List[ABCPagePdf]):
48
+ if not isinstance(new, list):
49
+ raise ValueError(f'{__class__.__name__}Erro: Use List[PagePdf], não {type(new)}')
50
+ self.__pages = new
51
+
52
+ @abstractmethod
53
+ def is_null(self) -> bool:
54
+ pass
55
+
56
+ @abstractmethod
57
+ def add_file_pdf(self, file:File):
58
+ pass
59
+
60
+ @abstractmethod
61
+ def add_page(self, page:ABCPagePdf) -> bool:
62
+ pass
63
+
64
+ @abstractmethod
65
+ def add_pages(self, pages:List[ABCPagePdf]):
66
+ pass
67
+
68
+ @abstractmethod
69
+ def add_bytes_page(self, page_bytes:bytes):
70
+ pass
71
+
72
+ @abstractmethod
73
+ def add_bytes_file_pdf(self, file_bytes:BytesIO):
74
+ pass
75
+
76
+ @abstractmethod
77
+ def add_file_url(self, url:str):
78
+ pass
79
+
80
+ @abstractmethod
81
+ def remove_page(self, page_number:int) -> None:
82
+ pass
83
+
84
+ @abstractmethod
85
+ def remove_pages(self, num_pages:List[int]):
86
+ pass
87
+
88
+ @abstractmethod
89
+ def rotate_page(self, page_number: int, degrees: int):
90
+ pass
91
+
92
+ @abstractmethod
93
+ def set_paisagem(self):
94
+ pass
95
+
96
+ @abstractmethod
97
+ def to_file_pdf(self, file:File):
98
+ pass
99
+
100
+ @abstractmethod
101
+ def to_data(self, separator='\n') -> DataFrame:
102
+ pass
103
+
104
+ @abstractmethod
105
+ def to_list(self, separator='\n') -> List[str]:
106
+ pass
107
+
108
+ @abstractmethod
109
+ def to_excel(self, file:File, *, separator:str='\n'):
110
+ pass
111
+
112
+ @abstractmethod
113
+ def clear(self):
114
+ pass
115
+
116
+ @abstractmethod
117
+ def get_page_number(self, num:int) -> ABCPagePdf:
118
+ pass
119
+ @abstractmethod
120
+ def get_pages_numbers(self, numbers:List[int]) -> List[ABCPagePdf]:
121
+ pass
122
+
123
+ @abstractmethod
124
+ def get_document_with_text(self, text:str) -> ABCDocumentPdf:
125
+ pass
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+
139
+
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ #
4
+ from __future__ import annotations
5
+ from abc import abstractmethod, ABC
6
+ from enum import Enum
7
+ from typing import List, Dict
8
+ from pandas import DataFrame
9
+
10
+ from soup_files import File
11
+ from convertlib.models.m_text import TableText
12
+
13
+
14
+ class LibraryPDF(Enum):
15
+ """Enumerar as libs para manipulação de PDF"""
16
+ PYPDF = 'pypdf2'
17
+ FITZ = 'fitz'
18
+ CANVAS = 'canvas'
19
+ PILPDF = 'pil'
20
+
21
+
22
+ # Representação de uma página PDF.
23
+ class ABCPagePdf(ABC):
24
+ """Abstração de uma página PDF"""
25
+
26
+ def __init__(self):
27
+ super().__init__()
28
+ self.page:object = None
29
+ self.page_number: int = 0
30
+ self.current_library: LibraryPDF = None
31
+
32
+ @abstractmethod
33
+ def to_string(self) -> str:
34
+ pass
35
+
36
+ @abstractmethod
37
+ def to_list(self, separator:str='\n') -> List[str]:
38
+ pass
39
+
40
+ @abstractmethod
41
+ def to_table(self, separator:str='\n') -> TableText:
42
+ pass
43
+
44
+ @abstractmethod
45
+ def to_bytes(self) -> bytes:
46
+ pass
47
+
48
+ @abstractmethod
49
+ def is_paisagem(self) -> bool:
50
+ pass
51
+
52
+ @abstractmethod
53
+ def set_paisagem(self):
54
+ pass
55
+
56
+ @abstractmethod
57
+ def set_page_pypdf2(self):
58
+ pass
59
+
60
+ @abstractmethod
61
+ def set_page_fitz(self):
62
+ pass
63
+
64
+ @abstractmethod
65
+ def rotate(self, degrees: int):
66
+ pass
67
+
68
+ @classmethod
69
+ def create_from_page_bytes(cls, page_bytes:bytes) -> ABCPagePdf:
70
+ pass
71
+
72
+ @classmethod
73
+ def create_from_page_fitz(cls, page:object) -> ABCPagePdf:
74
+ pass
75
+
76
+ @classmethod
77
+ def create_from_page_pypdf2(cls, page:object) -> ABCPagePdf:
78
+ pass
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+