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.
Files changed (27) hide show
  1. {convert_stream-1.4 → convert_stream-1.4.1}/PKG-INFO +1 -1
  2. {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/_version.py +2 -2
  3. {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/convert.py +20 -6
  4. {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/pdf_document.py +53 -27
  5. {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream.egg-info/PKG-INFO +1 -1
  6. {convert_stream-1.4 → convert_stream-1.4.1}/pyproject.toml +1 -1
  7. {convert_stream-1.4 → convert_stream-1.4.1}/README.md +0 -0
  8. {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/__init__.py +0 -0
  9. {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/__main__.py +0 -0
  10. {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/image_to_pdf.py +0 -0
  11. {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/imagelib.py +0 -0
  12. {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/models/__init__.py +0 -0
  13. {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/models/m_text.py +0 -0
  14. {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/models/models_image.py +0 -0
  15. {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/models/models_pdf.py +0 -0
  16. {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/pdf_compress.py +0 -0
  17. {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/pdf_page.py +0 -0
  18. {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/pdf_to_images.py +0 -0
  19. {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/progress/__init__.py +0 -0
  20. {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/progress/progress_bar.py +0 -0
  21. {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/table_files.py +0 -0
  22. {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream/text.py +0 -0
  23. {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream.egg-info/SOURCES.txt +0 -0
  24. {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream.egg-info/dependency_links.txt +0 -0
  25. {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream.egg-info/requires.txt +0 -0
  26. {convert_stream-1.4 → convert_stream-1.4.1}/convert_stream.egg-info/top_level.txt +0 -0
  27. {convert_stream-1.4 → convert_stream-1.4.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: convert_stream
3
- Version: 1.4
3
+ Version: 1.4.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
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env python3
2
2
  # -*- coding: utf-8 -*-
3
- __version__ = '1.4'
3
+ __version__ = '1.4.1'
4
4
  __author__ = 'Bruno Chaves'
5
5
  __license__ = 'MIT'
6
6
  __module_name__ = 'convert_stream'
7
- __modify_date__ = '2025-07-11'
7
+ __modify_date__ = '2025-07-20'
@@ -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
- self.add_images([ImageObject.create_from_file(f) for f in files])
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
- docpdf: DocumentPdf = DocumentPdf(
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.pages,
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 get_document_with_text(self, text: str) -> DocumentPdf:
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 get_document_with_text(self, text) -> DocumentPdf:
373
- """
374
- Retorna uma lista de páginas que contêm o texto especificado.
375
- Se o texto não for encontrado, retorna uma lista vazia.
376
- """
377
- doc = DocumentPdf(self.library)
378
- for page in self._pages_list:
379
- current_text: str = page.to_string()
380
- if (current_text is not None) and (text in current_text):
381
- doc.add_page(page)
382
- return doc
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 get_document_with_text(self, text) -> DocumentPdf:
622
- """
623
- Retorna uma lista de páginas que contêm o texto especificado.
624
- Se o texto não for encontrado, retorna uma lista vazia.
625
- """
626
- doc = DocumentPdf(self.library)
627
- for page in self._pages_list:
628
- current_text: str = page.to_string()
629
- if (current_text is not None) and (text in current_text):
630
- doc.add_page(page)
631
- return doc
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
- return self.document.get_document_with_text(text)
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:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: convert_stream
3
- Version: 1.4
3
+ Version: 1.4.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
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "convert_stream"
7
- version = "1.4"
7
+ version = "1.4.1"
8
8
  authors = [
9
9
  { name="Bruno Chaves"},
10
10
  ]
File without changes
File without changes