convert-stream 1.4__tar.gz → 1.4.1__tar.gz
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.
- {convert_stream-1.4 → convert_stream-1.4.1}/PKG-INFO +1 -1
- {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/_version.py +2 -2
- {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/convert.py +20 -6
- {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/pdf_document.py +53 -27
- {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream.egg-info/PKG-INFO +1 -1
- {convert_stream-1.4 → convert_stream-1.4.1}/pyproject.toml +1 -1
- {convert_stream-1.4 → convert_stream-1.4.1}/README.md +0 -0
- {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/__init__.py +0 -0
- {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/__main__.py +0 -0
- {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/image_to_pdf.py +0 -0
- {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/imagelib.py +0 -0
- {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/models/__init__.py +0 -0
- {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/models/m_text.py +0 -0
- {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/models/models_image.py +0 -0
- {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/models/models_pdf.py +0 -0
- {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/pdf_compress.py +0 -0
- {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/pdf_page.py +0 -0
- {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/pdf_to_images.py +0 -0
- {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/progress/__init__.py +0 -0
- {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/progress/progress_bar.py +0 -0
- {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/table_files.py +0 -0
- {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/text.py +0 -0
- {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream.egg-info/SOURCES.txt +0 -0
- {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream.egg-info/dependency_links.txt +0 -0
- {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream.egg-info/requires.txt +0 -0
- {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream.egg-info/top_level.txt +0 -0
- {convert_stream-1.4 → convert_stream-1.4.1}/setup.cfg +0 -0
|
@@ -206,11 +206,23 @@ class PdfStream(ABCDocumentStream):
|
|
|
206
206
|
file_type: LibraryDocs = LibraryDocs.PDF,
|
|
207
207
|
max_files: int = 4000
|
|
208
208
|
):
|
|
209
|
+
"""
|
|
210
|
+
Adicionar PDFs e imagens de uma pasta.
|
|
211
|
+
@param d:
|
|
212
|
+
@param file_type: tipo de documento a ser adicionado
|
|
213
|
+
@param max_files: máximo de arquivos a serem adicionados da pasta atual
|
|
214
|
+
@return:
|
|
215
|
+
"""
|
|
209
216
|
files = InputFiles(d, maxFiles=max_files).get_files(file_type=file_type)
|
|
210
217
|
if file_type == LibraryDocs.PDF:
|
|
211
218
|
self.add_files_pdf(files)
|
|
212
219
|
elif file_type == LibraryDocs.IMAGE:
|
|
213
|
-
|
|
220
|
+
try:
|
|
221
|
+
for file in files:
|
|
222
|
+
img = ImageObject.create_from_file(file)
|
|
223
|
+
self.add_image(img)
|
|
224
|
+
except Exception as err:
|
|
225
|
+
print(err)
|
|
214
226
|
|
|
215
227
|
def add_page_pdf_bytes(self, bt: bytes):
|
|
216
228
|
_page = PageDocumentPdf.create_from_page_bytes(bt, library=self.library_pdf)
|
|
@@ -242,14 +254,16 @@ class PdfStream(ABCDocumentStream):
|
|
|
242
254
|
self.progress_bar.stop()
|
|
243
255
|
|
|
244
256
|
def to_file_pdf(self, f: File):
|
|
257
|
+
"""
|
|
258
|
+
Exportar as páginas para um arquivo PDF.
|
|
259
|
+
@param f:
|
|
260
|
+
@return:
|
|
261
|
+
"""
|
|
245
262
|
if self.is_null():
|
|
246
263
|
print(
|
|
247
264
|
f'{__class__.__name__} Nenhuma página foi adiconada, adicione páginas ao documento para prosseguir!'
|
|
248
265
|
)
|
|
249
|
-
|
|
250
|
-
self.library_pdf, progress_bar=self.progress_bar, pages=self.pages
|
|
251
|
-
)
|
|
252
|
-
docpdf.to_file_pdf(f)
|
|
266
|
+
self.document.to_file_pdf(f)
|
|
253
267
|
|
|
254
268
|
def to_files_pdf(self, outdir: Directory, *, prefix='documento', replace: bool = False):
|
|
255
269
|
if self.is_null():
|
|
@@ -290,7 +304,7 @@ class PdfStream(ABCDocumentStream):
|
|
|
290
304
|
return DocumentPdf(
|
|
291
305
|
self.library_pdf,
|
|
292
306
|
progress_bar=self.progress_bar,
|
|
293
|
-
pages=self.
|
|
307
|
+
pages=self.document.get_pages(),
|
|
294
308
|
maximum_pages=self.document.get_maximum_pages(),
|
|
295
309
|
)
|
|
296
310
|
|
|
@@ -145,7 +145,11 @@ class ABCDocumentPdf(ABC):
|
|
|
145
145
|
pass
|
|
146
146
|
|
|
147
147
|
@abstractmethod
|
|
148
|
-
def
|
|
148
|
+
def find(self, text: str) -> PageDocumentPdf:
|
|
149
|
+
pass
|
|
150
|
+
|
|
151
|
+
@abstractmethod
|
|
152
|
+
def find_all(self, text: str) -> List[PageDocumentPdf]:
|
|
149
153
|
pass
|
|
150
154
|
|
|
151
155
|
|
|
@@ -369,17 +373,22 @@ class DocumentPyPdf2(ABCDocumentPdf):
|
|
|
369
373
|
new_pages.append(pg)
|
|
370
374
|
return new_pages
|
|
371
375
|
|
|
372
|
-
def
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
376
|
+
def find(self, text: str) -> PageDocumentPdf | None:
|
|
377
|
+
for _page in self.get_pages():
|
|
378
|
+
value = _page.to_string()
|
|
379
|
+
if (value is not None) and (value != ""):
|
|
380
|
+
if text in value:
|
|
381
|
+
return _page
|
|
382
|
+
|
|
383
|
+
def find_all(self, text: str) -> List[PageDocumentPdf]:
|
|
384
|
+
_pages: List[PageDocumentPdf] = []
|
|
385
|
+
for pg in self.get_pages():
|
|
386
|
+
value = pg.to_string()
|
|
387
|
+
if (value is None) or (value == ''):
|
|
388
|
+
continue
|
|
389
|
+
if text in value:
|
|
390
|
+
_pages.append(pg)
|
|
391
|
+
return _pages
|
|
383
392
|
|
|
384
393
|
|
|
385
394
|
class DocumentFitz(ABCDocumentPdf):
|
|
@@ -618,17 +627,22 @@ class DocumentFitz(ABCDocumentPdf):
|
|
|
618
627
|
new_pages.append(pg)
|
|
619
628
|
return new_pages
|
|
620
629
|
|
|
621
|
-
def
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
630
|
+
def find(self, text: str) -> PageDocumentPdf | None:
|
|
631
|
+
for _page in self.get_pages():
|
|
632
|
+
value = _page.to_string()
|
|
633
|
+
if (value is not None) and (value != ""):
|
|
634
|
+
if text in value:
|
|
635
|
+
return _page
|
|
636
|
+
|
|
637
|
+
def find_all(self, text: str) -> List[PageDocumentPdf]:
|
|
638
|
+
_pages: List[PageDocumentPdf] = []
|
|
639
|
+
for pg in self.get_pages():
|
|
640
|
+
value = pg.to_string()
|
|
641
|
+
if (value is None) or (value == ''):
|
|
642
|
+
continue
|
|
643
|
+
if text in value:
|
|
644
|
+
_pages.append(pg)
|
|
645
|
+
return _pages
|
|
632
646
|
|
|
633
647
|
|
|
634
648
|
class DocumentPdf(object):
|
|
@@ -651,12 +665,12 @@ class DocumentPdf(object):
|
|
|
651
665
|
self._maximum_pages: int = maximum_pages
|
|
652
666
|
self.library: LibraryPDF = library
|
|
653
667
|
if self.library == LibraryPDF.PYPDF:
|
|
654
|
-
self.document: ABCDocumentPdf = DocumentPyPdf2(progress_bar=progress_bar)
|
|
668
|
+
self.document: ABCDocumentPdf = DocumentPyPdf2(progress_bar=progress_bar, pages=pages)
|
|
655
669
|
elif self.library == LibraryPDF.FITZ:
|
|
656
|
-
self.document: ABCDocumentPdf = DocumentFitz(progress_bar=progress_bar)
|
|
670
|
+
self.document: ABCDocumentPdf = DocumentFitz(progress_bar=progress_bar, pages=pages)
|
|
657
671
|
else:
|
|
658
672
|
raise NotImplementedError(f'{__class__.__name__}\nLibraryPDF não implementada: {type(library)}')
|
|
659
|
-
self.document.pages = pages
|
|
673
|
+
#self.document.pages = pages
|
|
660
674
|
self.document.num_pages = len(pages)
|
|
661
675
|
|
|
662
676
|
@property
|
|
@@ -773,7 +787,19 @@ class DocumentPdf(object):
|
|
|
773
787
|
Retorna um novo documento com as páginas que contém o texto informado no parâmetro,
|
|
774
788
|
se o texto não for encontrado, retorna um documento vazio.
|
|
775
789
|
"""
|
|
776
|
-
|
|
790
|
+
|
|
791
|
+
return DocumentPdf(
|
|
792
|
+
LibraryPDF.FITZ,
|
|
793
|
+
maximum_pages=self.get_maximum_pages(),
|
|
794
|
+
progress_bar=self.progress_bar,
|
|
795
|
+
pages=self.document.find_all(text),
|
|
796
|
+
)
|
|
797
|
+
|
|
798
|
+
def find(self, text: str) -> PageDocumentPdf | None:
|
|
799
|
+
return self.document.find(text)
|
|
800
|
+
|
|
801
|
+
def find_all(self, text: str) -> List[PageDocumentPdf]:
|
|
802
|
+
return self.document.find_all(text)
|
|
777
803
|
|
|
778
804
|
@classmethod
|
|
779
805
|
def create_from_file(cls, file: File, *, library: LibraryPDF = LibraryPDF.FITZ) -> DocumentPdf:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|