csc-cia-stne 0.1.29__py3-none-any.whl → 0.1.30__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.
@@ -7,6 +7,7 @@ from .func_get_secret import get_secret
7
7
  from .func_datetime import now_sp
8
8
  from .func_delete import delete_file, delete_folder
9
9
  from .func_validate_json import validate_json
10
+ from .func_pdf_extract import extrair_x_paginas_pdf, extrair_paginas_intervalo_pdf
10
11
 
11
12
  __all__ = [
12
13
  "titulo",
@@ -19,5 +20,7 @@ __all__ = [
19
20
  "now_sp",
20
21
  "delete_file",
21
22
  "delete_folder",
23
+ "extrair_x_paginas_pdf",
24
+ "extrair_paginas_intervalo_pdf",
22
25
  "validate_json"
23
26
  ]
@@ -0,0 +1,104 @@
1
+ from PyPDF2 import PdfReader, PdfWriter
2
+ from io import BytesIO
3
+ from typing import Optional
4
+
5
+ def extrair_x_paginas_pdf(file_path: str, pages_limit: int = 15) -> Optional[bytes]:
6
+ """
7
+ Extrai as primeiras X páginas de um arquivo PDF e retorna os bytes dessas páginas.
8
+
9
+ Args:
10
+ file_path (str): Caminho completo do arquivo PDF original.
11
+ pages_limit (int, optional): Número máximo de páginas a serem extraídas.
12
+ Defaults to 15.
13
+
14
+ Returns:
15
+ Optional[bytes]: Bytes do novo PDF contendo as primeiras X páginas,
16
+ ou None em caso de erro.
17
+
18
+ Note:
19
+ - Se o PDF tiver menos páginas que pages_limit, todas serão extraídas
20
+ - Utiliza PyPDF2 para manipulação do arquivo PDF
21
+ - Retorna None em caso de erro no processamento
22
+
23
+ Example:
24
+ >>> pdf_bytes = extrair_x_paginas_pdf("documento.pdf", 10)
25
+ >>> if pdf_bytes["success"]:
26
+ ... print(f"PDF extraído com {len(pdf_bytes["data"])} bytes")
27
+ """
28
+ try:
29
+ # Lê o arquivo PDF original
30
+ reader = PdfReader(file_path)
31
+ writer = PdfWriter()
32
+
33
+ # Extrai as primeiras 'pages_limit' páginas ou menos, caso o PDF tenha menos de 'pages_limit' páginas
34
+ for page_num in range(min(pages_limit, len(reader.pages))):
35
+ writer.add_page(reader.pages[page_num])
36
+
37
+ # Salva o novo PDF em um objeto BytesIO
38
+ pdf_bytes = BytesIO()
39
+ writer.write(pdf_bytes)
40
+ pdf_bytes.seek(0) # Move o cursor para o início do buffer
41
+ resposta = {"success": True, "error": None, "data": pdf_bytes.read()}
42
+ return resposta
43
+ except Exception as e:
44
+ resposta = {"success": False, "error": f"Erro ao extrair as primeiras {pages_limit} páginas do PDF: {str(e)}", "data": None}
45
+ return resposta
46
+
47
+ def extrair_paginas_intervalo_pdf(file_path: str, page_start: int = 1, pages_limit: int = 15) -> Optional[bytes]:
48
+ """
49
+ Extrai um número específico de páginas de um arquivo PDF a partir de uma página inicial.
50
+
51
+ Args:
52
+ file_path (str): Caminho completo do arquivo PDF original.
53
+ page_start (int, optional): Página inicial para começar a extração (1-indexed).
54
+ Defaults to 1.
55
+ pages_limit (int, optional): Número máximo de páginas a serem extraídas a partir
56
+ da página inicial. Defaults to 15.
57
+
58
+ Returns:
59
+ Optional[bytes]: Bytes do novo PDF contendo as páginas do intervalo especificado,
60
+ ou None em caso de erro.
61
+
62
+ Note:
63
+ - Se page_start for maior que o número total de páginas, retorna None
64
+ - Se o número de páginas restantes for menor que pages_limit, extrai apenas as disponíveis
65
+ - Utiliza PyPDF2 para manipulação do arquivo PDF
66
+ - Páginas são indexadas começando em 1 (não 0)
67
+
68
+ Example:
69
+ >>> # Extrai 5 páginas começando da página 3
70
+ >>> pdf_bytes = extrair_paginas_intervalo_pdf("documento.pdf", 3, 5)
71
+ >>> if pdf_bytes["success"]:
72
+ ... print(f"PDF extraído com {len(pdf_bytes["data"])} bytes")
73
+ """
74
+ try:
75
+ # Lê o arquivo PDF original
76
+ reader = PdfReader(file_path)
77
+ writer = PdfWriter()
78
+
79
+ # Converte page_start para índice 0-based
80
+ start_index = page_start - 1
81
+
82
+ # Verifica se a página inicial é válida
83
+ if start_index >= len(reader.pages) or start_index < 0:
84
+ resposta = {"success": False, "error": f"Página inicial {page_start} inválida. O PDF tem {len(reader.pages)} páginas.", "data": None}
85
+ return resposta
86
+
87
+ # Calcula o índice final baseado no limite de páginas
88
+ end_index = min(start_index + pages_limit, len(reader.pages))
89
+
90
+ # Extrai as páginas do intervalo especificado
91
+ for page_num in range(start_index, end_index):
92
+ writer.add_page(reader.pages[page_num])
93
+
94
+ # Salva o novo PDF em um objeto BytesIO
95
+ pdf_bytes = BytesIO()
96
+ writer.write(pdf_bytes)
97
+ pdf_bytes.seek(0) # Move o cursor para o início do buffer
98
+
99
+ resposta = {"success": True, "error": None, "data": pdf_bytes.read()}
100
+ return resposta
101
+
102
+ except Exception as e:
103
+ resposta = {"success": False, "error": f"Erro ao extrair páginas {page_start}-{page_start + pages_limit - 1} do PDF: {str(e)}", "data": None}
104
+ return resposta
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: csc_cia_stne
3
- Version: 0.1.29
3
+ Version: 0.1.30
4
4
  Summary: Biblioteca do time CSC-CIA utilizada no desenvolvimento de RPAs
5
5
  License: MIT
6
6
  Keywords: karavela,csc,cia,stone,rpa,botcity,stne
@@ -33,6 +33,7 @@ Requires-Dist: email-validator
33
33
  Requires-Dist: botcity-maestro-sdk
34
34
  Requires-Dist: psutil
35
35
  Requires-Dist: cryptography
36
+ Requires-Dist: PyPDF2
36
37
  Requires-Dist: pycurl
37
38
  Dynamic: license-file
38
39
 
@@ -17,12 +17,13 @@ csc_cia_stne/stne_admin.py,sha256=tbRN_l3y---GHlQoAAjlZP92wnVA73hUmk9hQxKavH8,28
17
17
  csc_cia_stne/wacess.py,sha256=g-bWZNpm_tU7UsW1G_rqh_2fW2KShvxZHGOerX8DuQw,26768
18
18
  csc_cia_stne/web.py,sha256=TBXUJ5eS36fytU3oFDuJsogi0sgw_qKgK-uphx4Nvxo,2506
19
19
  csc_cia_stne/utilitarios/__init__.py,sha256=ul7p-4XduFOQW2ldKSIbTQb3eq7h5O1l8IwSP7b5KgY,410
20
- csc_cia_stne/utilitarios/functions/__init__.py,sha256=1jKf5CbiBe5wRKu-npBe9AYqY8KybGbQXfHjZ8JR5wM,629
20
+ csc_cia_stne/utilitarios/functions/__init__.py,sha256=KPzb4b48YxWkn-9Pg4L3XHTWO3UqDiRXmTu1IyOJXMY,778
21
21
  csc_cia_stne/utilitarios/functions/func_b64.py,sha256=XGU34BIQQXWXBS0yM2B4A2wDlcrMl1unIJXjq4lpLnk,1254
22
22
  csc_cia_stne/utilitarios/functions/func_converters.py,sha256=EY1zvlBaRX7G1MceVSiRXwwKDQDZwUO9iECBL0fe5iU,481
23
23
  csc_cia_stne/utilitarios/functions/func_datetime.py,sha256=UA7ch4sQWTiYcz8r6LtGujIdpTU-Sht8qmTYvm9vhh0,257
24
24
  csc_cia_stne/utilitarios/functions/func_delete.py,sha256=o2h4leucTq5Cs0XxJ5aBzbRyuxusKXIoedn2tmxNp1E,2449
25
25
  csc_cia_stne/utilitarios/functions/func_get_secret.py,sha256=XFsAd9GnKnf9WLnARqNG2fFg5h_JEOxbVvt_78VFYh4,2959
26
+ csc_cia_stne/utilitarios/functions/func_pdf_extract.py,sha256=uuGecPx4gh6uVyCvrqstK97G11FP7Sz0iwr52MUgD48,4508
26
27
  csc_cia_stne/utilitarios/functions/func_recriar_pastas.py,sha256=4whZpB3aJQaCPJ3osMAQpKrzEhqYtJbljGWlx_OvKIM,826
27
28
  csc_cia_stne/utilitarios/functions/func_settings.py,sha256=XwlfqdcfocXQ8kTsDKZ6GsAtpzr0_u44AOTIMtdem7U,2059
28
29
  csc_cia_stne/utilitarios/functions/func_titulo.py,sha256=bH4tYxovTARF-g2kWUK_GIzzXt8egbVdp6mWD6fc_3I,5345
@@ -39,8 +40,8 @@ csc_cia_stne/utilitarios/web_screen/__init__.py,sha256=5QcOPXKd95SvP2DoZiHS0gaU6
39
40
  csc_cia_stne/utilitarios/web_screen/web_screen_abstract.py,sha256=PjL8Vgfj_JdKidia7RFyCkro3avYLQu4RZRos41sh3w,3241
40
41
  csc_cia_stne/utilitarios/web_screen/web_screen_botcity.py,sha256=Xi5YJjl2pcxlX3OimqcBWRNXZEpAE7asyUjDJ4Oho5U,12297
41
42
  csc_cia_stne/utilitarios/web_screen/web_screen_selenium.py,sha256=JLIcPJE9ZX3Pd6zG6oTRMqqUAY063UzLY3ReRlxmiSM,15581
42
- csc_cia_stne-0.1.29.dist-info/licenses/LICENCE,sha256=LPGMtgKki2C3KEZP7hDhA1HBrlq5JCHkIeStUCLEMx4,1073
43
- csc_cia_stne-0.1.29.dist-info/METADATA,sha256=sN19T2lC0fc6kk15iwjcobbX_1v_w9jhHWpbpHIvFCA,1530
44
- csc_cia_stne-0.1.29.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
45
- csc_cia_stne-0.1.29.dist-info/top_level.txt,sha256=ldo7GVv3tQx5KJvwBzdZzzQmjPys2NDVVn1rv0BOF2Q,13
46
- csc_cia_stne-0.1.29.dist-info/RECORD,,
43
+ csc_cia_stne-0.1.30.dist-info/licenses/LICENCE,sha256=LPGMtgKki2C3KEZP7hDhA1HBrlq5JCHkIeStUCLEMx4,1073
44
+ csc_cia_stne-0.1.30.dist-info/METADATA,sha256=VzrUhcUhi1RZ2i2aBwBczNzvOfPFmGtwA3wfQSyAvYc,1552
45
+ csc_cia_stne-0.1.30.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
46
+ csc_cia_stne-0.1.30.dist-info/top_level.txt,sha256=ldo7GVv3tQx5KJvwBzdZzzQmjPys2NDVVn1rv0BOF2Q,13
47
+ csc_cia_stne-0.1.30.dist-info/RECORD,,