File size: 1,363 Bytes
86fce4f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python3
"""

Create a simple test DOCX document for testing the converter

"""

from docx import Document

# Create a new document
doc = Document()

# Add a title
doc.add_heading('Document Title', 0)

# Add a paragraph
p = doc.add_paragraph('This is a simple test document to test the DOCX to PDF converter. ')
p.add_run('This text is in bold.').bold = True
p.add_run(' And this is ')
p.add_run('italic text.').italic = True

# Add another heading
doc.add_heading('Heading 1', level=1)
doc.add_paragraph('This is a paragraph under Heading 1.')

# Add a table
table = doc.add_table(rows=3, cols=3)
table.style = 'Table Grid'
hdr_cells = table.rows[0].cells
hdr_cells[0].text = 'Header 1'
hdr_cells[1].text = 'Header 2'
hdr_cells[2].text = 'Header 3'

# Add data to the table
for i in range(1, 3):
    row_cells = table.rows[i].cells
    row_cells[0].text = f'Row {i}, Col 1'
    row_cells[1].text = f'Row {i}, Col 2'
    row_cells[2].text = f'Row {i}, Col 3'

# Add another paragraph
doc.add_paragraph('This document contains:')
doc.add_paragraph('• A title', style='List Bullet')
doc.add_paragraph('• Some formatted text', style='List Bullet')
doc.add_paragraph('• A table', style='List Bullet')

# Save the document
doc.save('test_document.docx')
print("Test document created: test_document.docx")