Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -32,28 +32,30 @@ def word_to_pdf(docx_file):
|
|
| 32 |
pdf_filename = "output.pdf"
|
| 33 |
|
| 34 |
doc = Document(docx_file)
|
| 35 |
-
pdf = FPDF()
|
| 36 |
-
|
| 37 |
-
# Add Arial font
|
| 38 |
-
pdf.add_font('Arial', '', 'Arial.ttf', uni=True)
|
| 39 |
-
pdf.set_font('Arial', size=12)
|
| 40 |
-
|
| 41 |
pdf.add_page()
|
|
|
|
| 42 |
|
| 43 |
for para in doc.paragraphs:
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
else:
|
| 50 |
-
pdf.
|
| 51 |
-
|
|
|
|
|
|
|
| 52 |
|
| 53 |
pdf.output(pdf_filename)
|
| 54 |
return pdf_filename
|
| 55 |
|
| 56 |
-
|
| 57 |
with gr.Blocks() as app:
|
| 58 |
gr.Markdown(title_and_description)
|
| 59 |
|
|
|
|
| 32 |
pdf_filename = "output.pdf"
|
| 33 |
|
| 34 |
doc = Document(docx_file)
|
| 35 |
+
pdf = FPDF(format='A4')
|
| 36 |
+
pdf.set_auto_page_break(auto=True, margin=15)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
pdf.add_page()
|
| 38 |
+
pdf.set_font('Arial', size=12)
|
| 39 |
|
| 40 |
for para in doc.paragraphs:
|
| 41 |
+
text = para.text.strip()
|
| 42 |
+
if not text: # Ignorar linhas vazias
|
| 43 |
+
continue
|
| 44 |
+
# Quebrar o texto em várias linhas se necessário
|
| 45 |
+
words = text.split()
|
| 46 |
+
line = ''
|
| 47 |
+
for word in words:
|
| 48 |
+
if pdf.get_string_width(line + word) < (pdf.w - 2 * pdf.l_margin):
|
| 49 |
+
line += word + ' '
|
| 50 |
else:
|
| 51 |
+
pdf.cell(0, 10, line, ln=True)
|
| 52 |
+
line = word + ' '
|
| 53 |
+
if line:
|
| 54 |
+
pdf.cell(0, 10, line, ln=True)
|
| 55 |
|
| 56 |
pdf.output(pdf_filename)
|
| 57 |
return pdf_filename
|
| 58 |
|
|
|
|
| 59 |
with gr.Blocks() as app:
|
| 60 |
gr.Markdown(title_and_description)
|
| 61 |
|