artificialguybr commited on
Commit
abf1208
1 Parent(s): 2512841

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -14
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
- lines = para.text.split('\n')
45
- for line in lines:
46
- # Check if the line is too long and adjust
47
- if len(line) > 90: # Adjust this number based on your needs
48
- pdf.set_font('Arial', size=10) # Adjust font size
 
 
 
 
49
  else:
50
- pdf.set_font('Arial', size=12)
51
- pdf.multi_cell(0, 10, line)
 
 
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