convert-stream 2.4.4__tar.gz → 2.5.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.
Files changed (32) hide show
  1. {convert_stream-2.4.4 → convert_stream-2.5.1}/PKG-INFO +3 -3
  2. {convert_stream-2.4.4 → convert_stream-2.5.1}/convert_stream/__init__.py +10 -15
  3. {convert_stream-2.4.4 → convert_stream-2.5.1}/convert_stream/_version.py +2 -2
  4. convert_stream-2.5.1/convert_stream/convert/__init__.py +6 -0
  5. {convert_stream-2.4.4/convert_stream/pdf → convert_stream-2.5.1/convert_stream/convert}/image_to_pdf.py +1 -1
  6. {convert_stream-2.4.4 → convert_stream-2.5.1}/convert_stream/doc_stream.py +19 -22
  7. {convert_stream-2.4.4 → convert_stream-2.5.1}/convert_stream/image/img_object.py +26 -15
  8. convert_stream-2.5.1/convert_stream/mod_types/__init__.py +11 -0
  9. convert_stream-2.5.1/convert_stream/mod_types/enums.py +37 -0
  10. {convert_stream-2.4.4 → convert_stream-2.5.1}/convert_stream/mod_types/modules.py +6 -6
  11. convert_stream-2.5.1/convert_stream/pdf/__init__.py +12 -0
  12. {convert_stream-2.4.4 → convert_stream-2.5.1}/convert_stream/pdf/pdf_document.py +14 -13
  13. {convert_stream-2.4.4 → convert_stream-2.5.1}/convert_stream/pdf/pdf_page.py +12 -9
  14. {convert_stream-2.4.4 → convert_stream-2.5.1}/convert_stream/table_files.py +1 -2
  15. {convert_stream-2.4.4 → convert_stream-2.5.1}/convert_stream/text/__init__.py +1 -0
  16. {convert_stream-2.4.4 → convert_stream-2.5.1}/convert_stream.egg-info/PKG-INFO +3 -3
  17. {convert_stream-2.4.4 → convert_stream-2.5.1}/convert_stream.egg-info/SOURCES.txt +3 -3
  18. {convert_stream-2.4.4 → convert_stream-2.5.1}/convert_stream.egg-info/requires.txt +2 -2
  19. {convert_stream-2.4.4 → convert_stream-2.5.1}/pyproject.toml +4 -3
  20. convert_stream-2.4.4/convert_stream/mod_types/__init__.py +0 -13
  21. convert_stream-2.4.4/convert_stream/mod_types/enums.py +0 -65
  22. convert_stream-2.4.4/convert_stream/mod_types/table_types.py +0 -19
  23. convert_stream-2.4.4/convert_stream/pdf/__init__.py +0 -14
  24. {convert_stream-2.4.4 → convert_stream-2.5.1}/README.md +0 -0
  25. {convert_stream-2.4.4 → convert_stream-2.5.1}/convert_stream/__main__.py +0 -0
  26. {convert_stream-2.4.4/convert_stream/pdf → convert_stream-2.5.1/convert_stream/convert}/pdf_to_image.py +0 -0
  27. {convert_stream-2.4.4 → convert_stream-2.5.1}/convert_stream/image/__init__.py +0 -0
  28. {convert_stream-2.4.4 → convert_stream-2.5.1}/convert_stream/text/find_text.py +0 -0
  29. {convert_stream-2.4.4 → convert_stream-2.5.1}/convert_stream/text/terminal.py +0 -0
  30. {convert_stream-2.4.4 → convert_stream-2.5.1}/convert_stream.egg-info/dependency_links.txt +0 -0
  31. {convert_stream-2.4.4 → convert_stream-2.5.1}/convert_stream.egg-info/top_level.txt +0 -0
  32. {convert_stream-2.4.4 → convert_stream-2.5.1}/setup.cfg +0 -0
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: convert_stream
3
- Version: 2.4.4
3
+ Version: 2.5.1
4
4
  Summary: Manipulação de documentos PDF e Imagens. Converter, Ler, rotacionar exportar etc.
5
5
  Author: Bruno Chaves
6
6
  Requires-Python: >=3.11
7
7
  Description-Content-Type: text/markdown
8
- Requires-Dist: soup_files>=1.4
8
+ Requires-Dist: soup_files>=1.4.2
9
9
  Requires-Dist: PyMuPDF
10
10
  Requires-Dist: scipy
11
11
  Requires-Dist: reportlab
@@ -15,7 +15,7 @@ Requires-Dist: pandas
15
15
  Requires-Dist: Pillow>=11.3.0
16
16
  Requires-Dist: opencv-python
17
17
  Requires-Dist: requests>=2.32.4
18
- Requires-Dist: sheet_stream
18
+ Requires-Dist: sheet_stream>=0.1.3
19
19
 
20
20
  # Configuração instalação:
21
21
  pip3 install -r requirements.txt
@@ -8,11 +8,17 @@ from ._version import (
8
8
  __module_name__, __author__, __license__, __modify_date__, __version__
9
9
  )
10
10
  from .mod_types import (
11
- LibPDF, LibImage, LibPdfToImage, LibImageToPdf, DictTextTable, RotationAngle,
11
+ LibPDF, LibImage, LibPdfToImage, LibImageToPdf, RotationAngle,
12
12
  )
13
- from .image import ImageObject, CollectionImages
14
- from .pdf import DocumentPdf, PageDocumentPdf, CollectionPagePdf, ConvertPdfToImages, ConvertImageToPdf
15
- from .pdf.pdf_document import SearchableTextPdf
13
+ from .image import ImageObject, CollectionImages, ProcessImageScanner
14
+ from .pdf import (
15
+ DocumentPdf, PageDocumentPdf, CollectionPagePdf, SearchableTextPdf
16
+ )
17
+ from .convert import (
18
+ ConvertPdfToImages, ConvertImageToPdf, ABCConvertPdf, ABCConvertImageToPdf,
19
+ DEFAULT_LIB_PDF_TO_IMG, DEFAULT_LIB_IMAGE_TO_PDF, LibPdfToImage, LibImageToPdf,
20
+ )
21
+
16
22
  from .doc_stream import PdfStream, SplitPdf
17
23
  from .table_files import PdfFinder
18
24
  from .text import print_title, print_line, FindStrings
@@ -71,14 +77,3 @@ def read_image(img: Union[str, File, bytes, BytesIO]) -> PdfStream:
71
77
  raise ValueError()
72
78
  return _pdf_stream
73
79
 
74
-
75
- __all__ = [
76
- '__modify_date__', '__author__', '__license__', '__module_name__', '__version__',
77
- 'PdfStream', 'DocumentPdf', 'PageDocumentPdf', 'CollectionPagePdf', 'CollectionImages',
78
- 'ImageObject', 'File', 'Directory', 'LibraryDocs', 'InputFiles', 'SearchableTextPdf',
79
- 'PdfFinder', 'SplitPdf', 'LibImageToPdf', 'RotationAngle', 'ConvertImageToPdf',
80
- 'ConvertPdfToImages', 'LibPDF', 'LibImage', 'LibPdfToImage',
81
- 'read_pdf', 'read_files_pdf', 'read_image', 'DictTextTable',
82
- 'print_title', 'print_line', 'FindStrings',
83
- ]
84
-
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env python3
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
- __version__ = '2.2.7'
4
+ __version__ = '2.5'
5
5
  __author__ = 'Bruno Chaves'
6
6
  __license__ = 'MIT'
7
7
  __module_name__ = 'convert_stream'
8
- __modify_date__ = '2025-09-08'
8
+ __modify_date__ = '2025-11-15'
9
9
 
@@ -0,0 +1,6 @@
1
+ from .image_to_pdf import (
2
+ ABCConvertImageToPdf, ConvertImageToPdf, DEFAULT_LIB_IMAGE_TO_PDF, LibImageToPdf,
3
+ )
4
+ from .pdf_to_image import (
5
+ ABCConvertPdf, ConvertPdfToImages, DEFAULT_LIB_PDF_TO_IMG, LibPdfToImage
6
+ )
@@ -145,7 +145,7 @@ class ImplementImageToPdfPil(ABCConvertImageToPdf):
145
145
  if not MOD_IMG_PIL:
146
146
  raise RuntimeError("A biblioteca 'Pillow' não está disponível.")
147
147
 
148
- if self.collection_images:
148
+ if self.collection_images.length == 0:
149
149
  raise ValueError("A lista de imagens não pode estar vazia.")
150
150
 
151
151
  if land_scape:
@@ -4,21 +4,18 @@
4
4
  Módulo para trabalhar com pdfs e imagens
5
5
  """
6
6
  from __future__ import annotations
7
- from convert_stream.mod_types.modules import (
8
- DEFAULT_LIB_PDF, DEFAULT_LIB_IMAGE, DEFAULT_LIB_PDF_TO_IMG, DEFAULT_LIB_IMAGE_TO_PDF,
9
- )
10
7
  from convert_stream.mod_types.enums import LibPDF, LibImage, LibPdfToImage
11
8
  from convert_stream.pdf.pdf_page import PageDocumentPdf
12
9
  from convert_stream.image.img_object import ImageObject, CollectionImages
13
10
  from convert_stream.pdf.pdf_document import DocumentPdf, CollectionPagePdf
14
- from convert_stream.pdf.image_to_pdf import LibImageToPdf, ConvertImageToPdf
15
- from convert_stream.pdf.pdf_to_image import ConvertPdfToImages
11
+ from convert_stream.convert.image_to_pdf import LibImageToPdf, ConvertImageToPdf
12
+ from convert_stream.convert.pdf_to_image import ConvertPdfToImages
16
13
  from soup_files import File, Directory, ProgressBarAdapter
17
14
 
18
15
 
19
16
  class ImageStream(CollectionImages):
20
17
 
21
- def __init__(self, images: list[ImageObject]) -> None:
18
+ def __init__(self, images: list[ImageObject] = None) -> None:
22
19
  super().__init__(images)
23
20
 
24
21
  def add_image_bytes(self, bt: bytes) -> None:
@@ -39,7 +36,7 @@ class PdfStream(object):
39
36
  ) -> None:
40
37
  self.dpi = dpi
41
38
  self.progress: ProgressBarAdapter = pbar
42
- self.collection_pages: CollectionPagePdf = CollectionPagePdf([])
39
+ self.collection_pages: CollectionPagePdf = CollectionPagePdf()
43
40
  self.collection_images: CollectionImages = CollectionImages([], lib_img=lib_img)
44
41
  self.collection_images.set_pbar(self.progress)
45
42
  self.collection_pages.set_pbar(self.progress)
@@ -132,25 +129,25 @@ class PdfStream(object):
132
129
  return _doc
133
130
 
134
131
  def thresold(self, *, land_scape: bool = False, a4: bool = False) -> DocumentPdf:
135
- if self.collection_images.length == 0:
136
- images: list[ImageObject] = []
137
- else:
138
- images: list[ImageObject] = self.collection_images.copy()
139
132
 
140
133
  if not self.collection_pages.is_empty:
141
134
  # Converter as páginas PDF em imagens.
142
135
  conv_pdf_to_img: ConvertPdfToImages = self.convert_pdf_to_images
143
- images.extend(
144
- conv_pdf_to_img.to_images(dpi=self.dpi, lib_image=self.lib_img),
145
- )
146
- if len(images) == 0:
136
+ _images: list[ImageObject] = conv_pdf_to_img.to_images(dpi=self.dpi, lib_image=self.lib_img)
137
+ _collection = CollectionImages(_images)
138
+ else:
139
+ _collection = CollectionImages()
140
+
141
+ if self.collection_images.length > 0:
142
+ _collection.add_images(self.collection_images)
143
+ if _collection.length == 0:
147
144
  raise ValueError('Adicione imagens para prosseguir!')
148
- if land_scape:
149
- for img in images:
150
- img.set_landscape()
151
- for i in images:
152
- i.set_threshold_gray()
153
- conv_img_to_pdf = ConvertImageToPdf(CollectionImages(images), lib_img_to_pdf=self.lib_img_to_pdf)
145
+
146
+ for num, i in enumerate(_collection):
147
+ if land_scape:
148
+ _collection[num].set_landscape()
149
+ _collection[num].set_threshold_black(max_value=255)
150
+ conv_img_to_pdf = ConvertImageToPdf(_collection, lib_img_to_pdf=self.lib_img_to_pdf)
154
151
  return conv_img_to_pdf.to_document(a4=a4)
155
152
 
156
153
  def to_files_images(
@@ -163,7 +160,7 @@ class PdfStream(object):
163
160
  raise ValueError('Adicione imagens e/ou documentos para prosseguir!')
164
161
  self.progress.start()
165
162
 
166
- image_stream = ImageStream([])
163
+ image_stream = ImageStream()
167
164
  image_stream.set_pbar(self.progress)
168
165
  if not self.collection_images.is_empty:
169
166
  image_stream.add_images(self.collection_images)
@@ -4,17 +4,16 @@
4
4
  Módulo para trabalhar com imagens
5
5
  """
6
6
  from __future__ import annotations
7
-
8
7
  import os.path
9
8
  from typing import Union
10
9
  from abc import ABC, abstractmethod
11
- from soup_files import File, Directory, InputFiles, LibraryDocs, ProgressBarAdapter
10
+ from soup_files import File, Directory, InputFiles, LibraryDocs, ProgressBarAdapter, TextProgress
12
11
  from io import BytesIO
13
12
  import numpy as np
14
13
  from scipy.ndimage import uniform_filter
15
14
  from sheet_stream.type_utils import get_hash_from_bytes, MetaDataFile, MetaDataItem
16
- from convert_stream.mod_types.enums import LibImage, RotationAngle
17
- from convert_stream.mod_types.table_types import ListItems
15
+ from convert_stream.mod_types.enums import RotationAngle
16
+ from sheet_stream import ListItems
18
17
  from convert_stream.mod_types.modules import (
19
18
  MOD_IMG_PIL, ModuleImage, DEFAULT_LIB_IMAGE,
20
19
  cv2, MatLike, Image, ImageFilter, LibImage
@@ -500,16 +499,28 @@ class ImageObject(object):
500
499
 
501
500
  class CollectionImages(ListItems):
502
501
 
503
- def __init__(self, images: list[ImageObject], *, lib_img: LibImage = LibImage.OPENCV) -> None:
502
+ def __init__(self, images: list[ImageObject] = None, *, lib_img: LibImage = LibImage.OPENCV) -> None:
504
503
  """
505
504
  Gerir uma lista de Imagens
506
505
  :type images: list[ImageObject]
507
506
  """
508
507
  super().__init__(images)
509
508
  self.lib_img: LibImage = lib_img
510
- self.pbar: ProgressBarAdapter = ProgressBarAdapter()
509
+ self.__pbar: TextProgress = TextProgress()
510
+ self.set_list_type(ImageObject)
511
511
  self.__count: int = 0
512
512
 
513
+ @property
514
+ def pbar(self) -> ProgressBarAdapter:
515
+ return self.__pbar.pbar
516
+
517
+ @pbar.setter
518
+ def pbar(self, pbar: ProgressBarAdapter) -> None:
519
+ self.__pbar.pbar = pbar
520
+
521
+ def set_list_type(self, cls_type=object):
522
+ super().set_list_type(ImageObject)
523
+
513
524
  def clear(self) -> None:
514
525
  super().clear()
515
526
  self.__count = 0
@@ -533,12 +544,12 @@ class CollectionImages(ListItems):
533
544
 
534
545
  def add_files_image(self, files: list[File]) -> None:
535
546
  self.pbar.start()
536
- max_num: int = len(files)
547
+ self.__pbar.total = len(files)
548
+ self.__pbar.start = 0
549
+ self.__pbar.text = 'Adicionando imagem'
550
+
537
551
  for num, f in enumerate(files):
538
- self.pbar.update(
539
- ((num+1) / max_num) * 100,
540
- f'Adicionando imagem: [{num+1} de {max_num}]'
541
- )
552
+ self.__pbar.set_update()
542
553
  self.append(ImageObject.create_from_file(f, lib_image=self.lib_img))
543
554
  self.pbar.stop()
544
555
 
@@ -559,7 +570,7 @@ class CollectionImages(ListItems):
559
570
  max_num = self.length
560
571
  img: ImageObject
561
572
  for n, img in enumerate(self):
562
- if img.metadata.file_path is not None:
573
+ if (img.metadata.file_path is not None) and (img.metadata.file_path != ''):
563
574
  filename = f'{os.path.basename(img.metadata.file_path)}-{n}.png'
564
575
  else:
565
576
  filename = f'{img.metadata.name}-{n}.png'
@@ -611,9 +622,9 @@ class ProcessImageScanner(object):
611
622
 
612
623
  def select_doc(self) -> ImageObject | None:
613
624
  """
614
- Detecta e recorta automaticamente a área do documento principal
615
- (texto ou folha digitalizada) em uma imagem.
616
- Retorna um novo ImageObject contendo apenas o recorte detectado.
625
+ Deteta e recorta automaticamente a área do documento principal
626
+ (texto ou folha digitalizada) em imagem.
627
+ Retorna um novo ImageObject contendo apenas o recorte detetado.
617
628
  """
618
629
  # Converte para matriz OpenCV
619
630
  img_cv: np.ndarray = cv2.imdecode(self.image.to_numpy(), cv2.IMREAD_COLOR)
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env python3
2
+
3
+ from __future__ import annotations
4
+ from .enums import (
5
+ RotationAngle, LibImage, LibPdfToImage, LibPDF, LibImageToPdf
6
+ )
7
+
8
+ __all__ = [
9
+ 'RotationAngle', 'LibPDF',
10
+ 'LibImageToPdf', 'LibPdfToImage', 'LibImage',
11
+ ]
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env python3
2
+ from enum import Enum
3
+
4
+
5
+ class LibPdfToImage(Enum):
6
+ """Enumerar as bibliotecas externas que convertem PDF em imagem"""
7
+ PDF_TO_IMG_FITZ = 'fitz'
8
+ NOT_IMPLEMENTED = 'null'
9
+
10
+
11
+ class LibImageToPdf(Enum):
12
+
13
+ IMAGE_TO_PDF_FITZ = 'fitz'
14
+ IMAGE_TO_PDF_CANVAS = 'canvas'
15
+ IMAGE_TO_PDF_PIL = 'pil'
16
+ NOT_IMPLEMENTED = 'null'
17
+
18
+
19
+ class LibPDF(Enum):
20
+
21
+ PYPDF = 'pypdf'
22
+ FITZ = 'fitz'
23
+ NOT_IMPLEMENTED = 'null'
24
+
25
+
26
+ class LibImage(Enum):
27
+
28
+ PIL = 'pil'
29
+ OPENCV = 'opencv'
30
+ NOT_IMPLEMENTED = 'null'
31
+
32
+
33
+ class RotationAngle(Enum):
34
+
35
+ ROTATION_90 = 90
36
+ ROTATION_180 = 180
37
+ ROTATION_270 = 270
@@ -29,15 +29,15 @@ try:
29
29
  from cv2.typing import MatLike
30
30
  MOD_IMG_OPENCV = True
31
31
  except ImportError:
32
- MatLike = FakeType
32
+ MatLike = object
33
33
 
34
34
  try:
35
35
  from PIL import Image
36
36
  from PIL import ImageOps, ImageFilter
37
37
  MOD_IMG_PIL = True
38
38
  except ImportError:
39
- Image = FakeType
40
- Image.Image = FakeType
39
+ Image = object
40
+ Image.Image = object
41
41
 
42
42
  if MOD_IMG_OPENCV and MOD_IMG_PIL:
43
43
  ModuleImage: TypeAlias = Union[MatLike, Image.Image]
@@ -50,7 +50,7 @@ elif MOD_IMG_PIL:
50
50
  DEFAULT_LIB_IMAGE = LibImage.PIL
51
51
  else:
52
52
  DEFAULT_LIB_IMAGE = LibImage.NOT_IMPLEMENTED
53
- ModuleImage = FakeType
53
+ ModuleImage: TypeAlias = Union[MatLike, Image]
54
54
 
55
55
  #=================================================================#
56
56
  # Módulos para PDF fitz e pypdf
@@ -90,8 +90,8 @@ elif MOD_PYPDF:
90
90
  ModDocPdf = Union[PdfWriter]
91
91
  DEFAULT_LIB_PDF = LibPDF.PYPDF
92
92
  else:
93
- ModPagePdf = FakeType # fallback para runtime
94
- ModDocPdf = FakeType
93
+ ModPagePdf = Union[PageObject, fitz.Page]
94
+ ModDocPdf = Union[fitz.Document, PdfWriter]
95
95
  DEFAULT_LIB_PDF = LibPDF.NOT_IMPLEMENTED
96
96
 
97
97
  #=================================================================#
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env python3
2
+ from .pdf_page import PageDocumentPdf
3
+ from .pdf_document import (
4
+ DocumentPdf, CollectionPagePdf, SearchableTextPdf, ABCDocument,
5
+ MOD_FITZ, MOD_PYPDF, ModDocPdf,
6
+ )
7
+
8
+ __all__ = [
9
+ 'DocumentPdf', 'CollectionPagePdf', 'PageDocumentPdf',
10
+ 'SearchableTextPdf', 'ModDocPdf', 'ABCDocument', 'MOD_PYPDF', 'MOD_FITZ',
11
+ ]
12
+
@@ -9,14 +9,10 @@ from io import BytesIO
9
9
  from typing import Union
10
10
  import pandas as pd
11
11
  from soup_files import File, Directory, LibraryDocs, InputFiles, ProgressBarAdapter, JsonConvert
12
- from sheet_stream.type_utils import (
13
- get_hash_from_bytes, MetaDataFile, MetaDataItem
12
+ from sheet_stream import (
13
+ ListItems, HeadCell, HeadValues, ColumnsTable, TableDocuments, ListColumnBody, ListString,
14
+ MetaDataItem, MetaDataFile, get_hash_from_bytes,
14
15
  )
15
-
16
- from sheet_stream.type_utils import (
17
- ListItems, HeadCell, HeadValues, ColumnsTable, TableDocuments, ListColumnBody, ListString
18
- )
19
- from convert_stream.mod_types.table_types import DictTextTable, ColumnBody
20
16
  from convert_stream.mod_types.enums import LibPDF
21
17
  from convert_stream.mod_types.modules import (
22
18
  DEFAULT_LIB_PDF, ModDocPdf, PdfWriter, PdfReader, fitz, MOD_FITZ, MOD_PYPDF
@@ -70,7 +66,7 @@ class SearchableTextPdf(object):
70
66
  """
71
67
  def __init__(self, silent: bool = False):
72
68
  self.silent = silent
73
- self.elements: dict[str, ColumnBody] = DictTextTable.create_void_dict()
69
+ self.elements: TableDocuments = TableDocuments.create_void_dict()
74
70
 
75
71
  def __repr__(self):
76
72
  return f'SearchableTextPdf: {self.elements}'
@@ -221,9 +217,9 @@ class ImplementDocumentFitz(ABCDocument):
221
217
  """
222
218
  Implementação usando a biblioteca fitz.
223
219
  """
224
- def __init__(self, mod_doc_pdf: ModDocPdf):
220
+ def __init__(self, mod_doc_pdf: fitz.Document):
225
221
  super().__init__(mod_doc_pdf)
226
- self.mod_doc_pdf: ModDocPdf = mod_doc_pdf
222
+ self.mod_doc_pdf: fitz.Document = mod_doc_pdf
227
223
  self.lib_pdf: LibPDF = LibPDF.FITZ
228
224
 
229
225
  def lenght(self) -> int:
@@ -592,11 +588,12 @@ class DocumentPdf(object):
592
588
  list_data: list[TableDocuments] = []
593
589
  pages: list[PageDocumentPdf] = self.to_pages()
594
590
 
591
+ _mp: TableDocuments
595
592
  for page_pdf in pages:
596
- _mp: TableDocuments = self._create_map(page_pdf, separator=separator)
593
+ _mp = self._create_map(page_pdf, separator=separator)
597
594
  list_data.append(_mp)
598
595
  if len(list_data) == 0:
599
- return DictTextTable.create_void_dict()
596
+ return TableDocuments.create_void_dict()
600
597
  return concat_table(list_data)
601
598
 
602
599
  def to_data(self, separator: str = '\n') -> pd.DataFrame:
@@ -712,9 +709,10 @@ class CollectionPagePdf(ListItems):
712
709
  """
713
710
  Gerir uma coleção de páginas PDF.
714
711
  """
715
- def __init__(self, pages: list[PageDocumentPdf]) -> None:
712
+ def __init__(self, pages: list[PageDocumentPdf] = None) -> None:
716
713
  super().__init__(pages)
717
714
  self.pbar: ProgressBarAdapter = ProgressBarAdapter()
715
+ self.set_list_type(PageDocumentPdf)
718
716
 
719
717
  @property
720
718
  def name(self) -> str | None:
@@ -722,6 +720,9 @@ class CollectionPagePdf(ListItems):
722
720
  return None
723
721
  return self[0].__hash__()
724
722
 
723
+ def set_list_type(self, cls_type=PageDocumentPdf):
724
+ super().set_list_type(PageDocumentPdf)
725
+
725
726
  def set_pbar(self, p: ProgressBarAdapter):
726
727
  self.pbar = p
727
728
 
@@ -6,11 +6,8 @@
6
6
  from __future__ import annotations
7
7
  from abc import ABC, abstractmethod
8
8
  import pandas as pd
9
-
9
+ from sheet_stream import ListString, TableDocuments
10
10
  from convert_stream.mod_types.enums import LibPDF
11
- from convert_stream.mod_types.table_types import (
12
- DictTextTable, ListString
13
- )
14
11
  from convert_stream.mod_types.modules import (
15
12
  ModPagePdf, PageObject, fitz
16
13
  )
@@ -230,10 +227,16 @@ class PageDocumentPdf(object):
230
227
  return ListString([])
231
228
  return ListString(txt.split(separator))
232
229
 
233
- def to_dict(self, separator: str = '\n') -> DictTextTable:
230
+ def to_dict(self, separator: str = '\n') -> TableDocuments:
231
+ """
232
+ Converte o texto da página em tabela/dicionário
233
+ """
234
234
  _values = self.to_list(separator)
235
- return DictTextTable.create_from_values(
236
- _values, page_num=f'{self.number_page}', file_type='.pdf'
235
+ return TableDocuments.create_from_values(
236
+ _values,
237
+ page_num=f'{self.number_page}',
238
+ file_type='.pdf',
239
+ file_path=self.metadata.file_path
237
240
  )
238
241
 
239
242
  def to_map(self, separator: str = '\n') -> pd.DataFrame:
@@ -246,9 +249,9 @@ class PageDocumentPdf(object):
246
249
  fd = FindText(self.to_string(), separator=separator)
247
250
  return fd.find(text, iqual=iqual, case=case)
248
251
 
249
- def find_all(self, text: str, *, separator: str = '\n', iqual: bool = False, case: bool = True) -> list[str]:
252
+ def find_all(self, text: str, *, separator: str = '\n', iqual: bool = False, case: bool = True) -> ListString:
250
253
  fd = FindText(self.to_string(), separator=separator)
251
- return fd.find_all(text, iqual=iqual, case=case)
254
+ return ListString(fd.find_all(text, iqual=iqual, case=case))
252
255
 
253
256
  def get_width(self) -> float:
254
257
  return self.implement_page_pdf.get_width()
@@ -3,12 +3,11 @@
3
3
  from __future__ import annotations
4
4
  from io import BytesIO
5
5
  from soup_files import File, Directory, InputFiles, LibraryDocs
6
-
7
6
  from convert_stream import PageDocumentPdf
8
7
  from convert_stream.text.find_text import FindText
9
8
  from convert_stream.pdf.pdf_document import SearchableTextPdf, DocumentPdf
10
- from convert_stream.mod_types.table_types import ColumnsTable
11
9
  from convert_stream.image import ImageObject
10
+ from sheet_stream import ColumnsTable, TableDocuments
12
11
 
13
12
 
14
13
  class PdfFinder(object):
@@ -8,4 +8,5 @@ from sheet_stream import ConvertStringDate, fmt_col_to_date
8
8
  __all__ = [
9
9
  'ConvertStringDate', 'print_title', 'print_line', 'fmt_col_to_date',
10
10
  'show_info', 'Colors', 'show_error', 'show_warning', 'FindText',
11
+ 'FindStrings',
11
12
  ]
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: convert_stream
3
- Version: 2.4.4
3
+ Version: 2.5.1
4
4
  Summary: Manipulação de documentos PDF e Imagens. Converter, Ler, rotacionar exportar etc.
5
5
  Author: Bruno Chaves
6
6
  Requires-Python: >=3.11
7
7
  Description-Content-Type: text/markdown
8
- Requires-Dist: soup_files>=1.4
8
+ Requires-Dist: soup_files>=1.4.2
9
9
  Requires-Dist: PyMuPDF
10
10
  Requires-Dist: scipy
11
11
  Requires-Dist: reportlab
@@ -15,7 +15,7 @@ Requires-Dist: pandas
15
15
  Requires-Dist: Pillow>=11.3.0
16
16
  Requires-Dist: opencv-python
17
17
  Requires-Dist: requests>=2.32.4
18
- Requires-Dist: sheet_stream
18
+ Requires-Dist: sheet_stream>=0.1.3
19
19
 
20
20
  # Configuração instalação:
21
21
  pip3 install -r requirements.txt
@@ -10,17 +10,17 @@ convert_stream.egg-info/SOURCES.txt
10
10
  convert_stream.egg-info/dependency_links.txt
11
11
  convert_stream.egg-info/requires.txt
12
12
  convert_stream.egg-info/top_level.txt
13
+ convert_stream/convert/__init__.py
14
+ convert_stream/convert/image_to_pdf.py
15
+ convert_stream/convert/pdf_to_image.py
13
16
  convert_stream/image/__init__.py
14
17
  convert_stream/image/img_object.py
15
18
  convert_stream/mod_types/__init__.py
16
19
  convert_stream/mod_types/enums.py
17
20
  convert_stream/mod_types/modules.py
18
- convert_stream/mod_types/table_types.py
19
21
  convert_stream/pdf/__init__.py
20
- convert_stream/pdf/image_to_pdf.py
21
22
  convert_stream/pdf/pdf_document.py
22
23
  convert_stream/pdf/pdf_page.py
23
- convert_stream/pdf/pdf_to_image.py
24
24
  convert_stream/text/__init__.py
25
25
  convert_stream/text/find_text.py
26
26
  convert_stream/text/terminal.py
@@ -1,4 +1,4 @@
1
- soup_files>=1.4
1
+ soup_files>=1.4.2
2
2
  PyMuPDF
3
3
  scipy
4
4
  reportlab
@@ -8,4 +8,4 @@ pandas
8
8
  Pillow>=11.3.0
9
9
  opencv-python
10
10
  requests>=2.32.4
11
- sheet_stream
11
+ sheet_stream>=0.1.3
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "convert_stream"
7
- version = "2.4.4"
7
+ version = "2.5.1"
8
8
  authors = [
9
9
  { name="Bruno Chaves"},
10
10
  ]
@@ -14,7 +14,7 @@ readme = "README.md"
14
14
  requires-python = ">=3.11"
15
15
 
16
16
  dependencies = [
17
- "soup_files>=1.4",
17
+ "soup_files>=1.4.2",
18
18
  "PyMuPDF",
19
19
  "scipy",
20
20
  "reportlab",
@@ -24,12 +24,13 @@ dependencies = [
24
24
  "Pillow>=11.3.0",
25
25
  "opencv-python",
26
26
  "requests>=2.32.4",
27
- "sheet_stream",
27
+ "sheet_stream>=0.1.3",
28
28
  ]
29
29
 
30
30
  [tool.setuptools]
31
31
  packages = [
32
32
  "convert_stream",
33
+ "convert_stream.convert",
33
34
  "convert_stream.mod_types",
34
35
  "convert_stream.pdf",
35
36
  "convert_stream.image",
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env python3
2
- #
3
- from __future__ import annotations
4
- from .enums import (
5
- RotationAngle, ColumnsTable, LibImage, LibPdfToImage, LibPDF, LibImageToPdf
6
- )
7
- from .table_types import DictTextTable
8
-
9
-
10
- __all__ = [
11
- 'DictTextTable', 'RotationAngle', 'LibPDF',
12
- 'LibImageToPdf', 'LibPdfToImage', 'LibImage',
13
- ]
@@ -1,65 +0,0 @@
1
- #!/usr/bin/env python3
2
- from enum import Enum
3
-
4
-
5
- class ColumnsTable(Enum):
6
- """
7
- Classe enum para padronizar os nomes das tabelas geradas por este módulo.
8
- """
9
-
10
- NUM_LINE = 'LINHA'
11
- NUM_PAGE = 'PÁGINA'
12
- TEXT = 'TEXTO'
13
- FILE_PATH = 'ARQUIVO'
14
- FILE_NAME = 'NOME_ARQUIVO'
15
- DIR = 'PASTA'
16
- FILETYPE = 'TIPO_ARQUIVO'
17
- KEY = 'KEY'
18
-
19
- @classmethod
20
- def to_list(cls) -> list[str]:
21
- return [
22
- cls.NUM_LINE.value,
23
- cls.NUM_PAGE.value,
24
- cls.TEXT.value,
25
- cls.FILE_PATH.value,
26
- cls.FILE_NAME.value,
27
- cls.FILETYPE.value,
28
- cls.DIR.value,
29
- cls.KEY.value,
30
- ]
31
-
32
-
33
- class LibPdfToImage(Enum):
34
- """Enumerar as bibliotecas externas que convertem PDF em imagem"""
35
- PDF_TO_IMG_FITZ = 'fitz'
36
- NOT_IMPLEMENTED = 'null'
37
-
38
-
39
- class LibImageToPdf(Enum):
40
-
41
- IMAGE_TO_PDF_FITZ = 'fitz'
42
- IMAGE_TO_PDF_CANVAS = 'canvas'
43
- IMAGE_TO_PDF_PIL = 'pil'
44
- NOT_IMPLEMENTED = 'null'
45
-
46
-
47
- class LibPDF(Enum):
48
-
49
- PYPDF = 'pypdf'
50
- FITZ = 'fitz'
51
- NOT_IMPLEMENTED = 'null'
52
-
53
-
54
- class LibImage(Enum):
55
-
56
- PIL = 'pil'
57
- OPENCV = 'opencv'
58
- NOT_IMPLEMENTED = 'null'
59
-
60
-
61
- class RotationAngle(Enum):
62
-
63
- ROTATION_90 = 90
64
- ROTATION_180 = 180
65
- ROTATION_270 = 270
@@ -1,19 +0,0 @@
1
- #!/usr/bin/env python3
2
-
3
- from __future__ import annotations
4
- from sheet_stream import (
5
- ColumnsTable, ListString, ListItems, ListColumnBody, ArrayString, TableDocuments, TableRow, TableTextKeyWord
6
- )
7
- from sheet_stream.type_utils import HeadCell
8
-
9
-
10
- class ColumnBody(ListColumnBody):
11
-
12
- def __init__(self, col_name: HeadCell | str, col_body: list[str]):
13
- super().__init__(col_name, col_body)
14
-
15
-
16
- class DictTextTable(TableDocuments):
17
-
18
- def __init__(self, body_list: list[ListColumnBody]):
19
- super().__init__(body_list)
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env python3
2
-
3
- from .pdf_page import PageDocumentPdf
4
- from .pdf_document import (
5
- DocumentPdf, CollectionPagePdf
6
- )
7
- from .pdf_to_image import ConvertPdfToImages
8
- from .image_to_pdf import ConvertImageToPdf
9
-
10
- __all__ = [
11
- 'ConvertPdfToImages', 'ConvertImageToPdf', 'DocumentPdf',
12
- 'CollectionPagePdf', 'PageDocumentPdf',
13
- ]
14
-
File without changes
File without changes