Skip to content

Commit 8b2a245

Browse files
committed
first commit
0 parents  commit 8b2a245

File tree

6 files changed

+94
-0
lines changed

6 files changed

+94
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
venv/

__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .utils import from_buffer

pyjpdf.py

Whitespace-only changes.

teste.pdf

330 KB
Binary file not shown.

teste2.pdf

1.1 MB
Binary file not shown.

utils.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import subprocess
2+
import platform
3+
from io import BytesIO
4+
import tempfile
5+
import pyautogui, pyperclip,time
6+
7+
def from_buffer(stream):
8+
"""Read the buffer and return the data."""
9+
return stream
10+
11+
def from_path(path):
12+
"""Read the file and return the data."""
13+
with open(path, 'rb') as stream:
14+
return from_buffer(BytesIO(stream.read()))
15+
16+
def _openChromePDF(stream):
17+
"""Open the PDF in Chrome."""
18+
# Leitura dos dados do stream sem fechar o arquivo
19+
data = stream.read()
20+
if platform.system() == 'Windows':
21+
chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe'
22+
command = [chrome_path, '-']
23+
elif platform.system() == 'Darwin':
24+
command = ['open', '-na', 'Google Chrome', '--args', '-']
25+
elif platform.system() == 'Linux':
26+
with tempfile.NamedTemporaryFile(suffix=".pdf",mode='wb') as temp:
27+
temp.write(data)
28+
temp.flush()
29+
command = ['xdg-open', temp.name]
30+
process = subprocess.run(command, input=data, check=True, capture_output=True)
31+
copy_text()
32+
print(process.stdout)
33+
print(process.stderr)
34+
else:
35+
raise NotImplementedError('Your OS is not supported.')
36+
37+
if platform.system() != 'Linux':
38+
process = subprocess.run(command, input=data, check=True, capture_output=True)
39+
print(process.stdout)
40+
print(process.stderr)
41+
42+
def copy_text():
43+
# Ajuste as coordenadas conforme necessário para a posição do texto no PDF
44+
pyautogui.moveTo(500, 500) # Ajuste as coordenadas conforme necessário
45+
pyautogui.click()
46+
47+
# Seleciona todo o texto (Ctrl + A)
48+
pyautogui.hotkey('ctrl', 'a')
49+
50+
# Copia o texto (Ctrl + C)
51+
pyautogui.hotkey('ctrl', 'c')
52+
53+
def paste_to_file(file_path):
54+
# Pausa para dar tempo de copiar o texto
55+
time.sleep(1)
56+
57+
# Cola o texto em um arquivo
58+
pyautogui.hotkey('ctrl', 'v')
59+
60+
# Salva o arquivo (Ctrl + S)
61+
pyautogui.hotkey('ctrl', 's')
62+
pyautogui.write(file_path)
63+
pyautogui.press('enter')
64+
65+
from selenium import webdriver
66+
from selenium.webdriver.common.keys import Keys
67+
import time
68+
69+
from selenium import webdriver
70+
import time
71+
72+
# Iniciar o WebDriver do Selenium
73+
driver = webdriver.Chrome(executable_path='/usr/lib/chromium-browser/chromedriver')
74+
75+
# URL do PDF ou link para um arquivo PDF
76+
url_pdf = 'file:///home/lordwaif/PyJPDF/teste2.pdf'
77+
78+
# Navegar até o link do PDF
79+
driver.get(url_pdf)
80+
81+
# Esperar alguns segundos para garantir que o PDF seja carregado
82+
time.sleep(5)
83+
84+
# Fechar o navegador
85+
driver.quit()
86+
87+
88+
if __name__ == '__main__':
89+
#_openChromePDF(from_path('teste.pdf'))
90+
#paste_to_file('teste.txt')
91+
...
92+

0 commit comments

Comments
 (0)