pdf / test_document.py
fokan's picture
Upload 35 files
86fce4f verified
#!/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")