File size: 1,228 Bytes
66340f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
48
49
50
51
52
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import letter
from reportlab.lib.styles import ParagraphStyle
from reportlab.lib.units import inch
from reportlab.lib.enums import TA_CENTER
from reportlab.platypus import Paragraph
import docx


def dummy_pdf(text: str, temp_file_path="/tmp/temp_file"):
    c = canvas.Canvas(temp_file_path, pagesize=letter)

    style = ParagraphStyle(
        name="Normal", alignment=TA_CENTER, fontName="Helvetica", fontSize=12
    )

    p = Paragraph(text, style=style)
    p.wrapOn(c, inch * 6, inch * 4)
    p.drawOn(c, inch * 2, inch * 5)

    c.save()

    return temp_file_path


def dummy_txt(text: str):
    temp_file_path = "/tmp/temp_file"

    with open(temp_file_path, "w") as file:
        file.write(text)

    return temp_file_path


def dummy_docx(text: str):
    temp_file_path = "/tmp/temp_file"

    document = docx.Document()

    document.add_paragraph(text)

    # add a table to the document
    table = document.add_table(rows=3, cols=3)
    for i in range(3):
        row_cells = table.rows[i].cells
        for j in range(3):
            row_cells[j].text = f"Row {i+1}, Column {j+1}"

    document.save(temp_file_path)

    return temp_file_path