Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
projeto-recortador-pdf
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Pedro Bueno
projeto-recortador-pdf
Commits
23e4331b
Commit
23e4331b
authored
May 14, 2026
by
Guilherme da Silva Rolim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Verificação
parent
e3de1613
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
17 deletions
+23
-17
app.py
app.py
+23
-17
No files found.
app.py
View file @
23e4331b
...
...
@@ -4,14 +4,24 @@ import fitz # PyMuPDF
import
os
import
zipfile
from
PIL
import
Image
import
sqlite3
app
=
Flask
(
__name__
)
UPLOAD_FOLDER
=
'uploads'
os
.
makedirs
(
UPLOAD_FOLDER
,
exist_ok
=
True
)
def
init_db
():
conn
=
sqlite3
.
connect
(
'database.db'
)
conn
.
execute
(
'''CREATE TABLE IF NOT EXISTS configuracoes
(id INTEGER PRIMARY KEY AUTOINCREMENT, nome TEXT, coords TEXT)'''
)
conn
.
close
()
@app.route
(
'/'
)
def
index
():
return
render_template
(
'index.html'
)
conn
=
sqlite3
.
connect
(
'database.db'
)
configs
=
conn
.
execute
(
'SELECT * FROM configuracoes'
)
.
fetchall
()
conn
.
close
()
return
render_template
(
'index.html'
,
configs
=
configs
)
@app.route
(
'/upload_preview'
,
methods
=
[
'POST'
])
def
upload_preview
():
...
...
@@ -28,8 +38,10 @@ def preview(filename, pagnumber):
if
not
os
.
path
.
exists
(
pdf_path
):
return
"Erro"
,
404
doc
=
fitz
.
open
(
pdf_path
)
# Garante que a página solicitada existe no PDF
total
=
len
(
doc
)
pagnumber
=
max
(
0
,
min
(
pagnumber
,
total
-
1
))
if
pagnumber
>=
total
:
pagnumber
=
total
-
1
if
pagnumber
<
0
:
pagnumber
=
0
page
=
doc
[
pagnumber
]
pix
=
page
.
get_pixmap
(
dpi
=
100
)
...
...
@@ -42,13 +54,7 @@ def processar():
filename
=
request
.
form
[
'filename'
]
inicio
=
int
(
request
.
form
[
'inicio'
])
fim
=
int
(
request
.
form
[
'fim'
])
# x, y, w, h, dispW, dispH, realW, realH
data
=
list
(
map
(
float
,
request
.
form
[
'coords'
]
.
split
(
','
)))
x
,
y
,
w
,
h
,
dispW
,
dispH
,
realW
,
realH
=
data
scale_x
=
realW
/
dispW
scale_y
=
realH
/
dispH
c
=
list
(
map
(
float
,
request
.
form
[
'coords'
]
.
split
(
','
)))
pdf_path
=
os
.
path
.
join
(
UPLOAD_FOLDER
,
filename
)
doc
=
fitz
.
open
(
pdf_path
)
...
...
@@ -59,16 +65,13 @@ def processar():
if
p
>=
len
(
doc
):
break
page
=
doc
[
p
]
pix
=
page
.
get_pixmap
(
dpi
=
300
)
img
_full
=
Image
.
frombytes
(
"RGB"
,
[
pix
.
width
,
pix
.
height
],
pix
.
samples
)
img
=
Image
.
frombytes
(
"RGB"
,
[
pix
.
width
,
pix
.
height
],
pix
.
samples
)
dpi_m
=
300
/
100
left
=
x
*
scale_x
*
dpi_m
top
=
y
*
scale_y
*
dpi_m
right
=
(
x
+
w
)
*
scale_x
*
dpi_m
bottom
=
(
y
+
h
)
*
scale_y
*
dpi_m
s
=
300
/
100
# Escala Preview vs Corte Final
area
=
(
c
[
0
]
*
s
,
c
[
1
]
*
s
,
(
c
[
0
]
+
c
[
2
])
*
s
,
(
c
[
1
]
+
c
[
3
])
*
s
)
img_cortada
=
img
_full
.
crop
((
left
,
top
,
right
,
bottom
)
)
img_name
=
f
"pagina_{p
+1
}.png"
img_cortada
=
img
.
crop
(
area
)
img_name
=
f
"pagina_{p}.png"
img_path
=
os
.
path
.
join
(
UPLOAD_FOLDER
,
img_name
)
img_cortada
.
save
(
img_path
)
zip_f
.
write
(
img_path
,
img_name
)
...
...
@@ -78,4 +81,6 @@ def processar():
return
send_file
(
zip_path
,
as_attachment
=
True
)
if
__name__
==
'__main__'
:
init_db
()
app
.
run
(
debug
=
True
)
#mt fodinha kjk#
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment