Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document generator improvement #7

Open
SquakR opened this issue Mar 31, 2022 · 1 comment
Open

Document generator improvement #7

SquakR opened this issue Mar 31, 2022 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@SquakR
Copy link
Member

SquakR commented Mar 31, 2022

The current implementation of the document generator which generates a Word or Pdf document depending on the template requires manual unzipping a Word file and extracting a xml document. Generating a Word or Pdf file from a template is a common task that can be useful to many users. Therefore, this feature can be extracted in another independent library with the following API.

document_generator = DocumentGenerator(
    template='document_template.docx',
    name='my_document',
    output_dir='~/documents',
    variables={'variable1': 'value1', 'variable2': 'value2'}
)
word_path1 = document_generator.generate_docx() 
# word_path1 = '/home/user/documents/my_document.docx'
word_path2 = document_generator.generate_docx(
    name='another_document',
    output_dir='~/another_documents/',
    variables={'variable1': 'value1', 'variable2': 'value2'}
)
# word_path2 = '/home/user/documents/another_document.docx'
pdf_path = document_generator.generate_pdf()
# pdf_path = '/home/user/documents/my_document.pdf'
@SquakR SquakR added the enhancement New feature or request label Mar 31, 2022
@SquakR
Copy link
Member Author

SquakR commented Mar 31, 2022

Also, instead of our own solution, we should consider the python-docx-template library. If we use this library, we only need to implement the conversion from docx to pdf because there is no ready solution for Linux.

word_to_pdf(input_path='~/documents/document.docx', output_path='~/documents/document.pdf')

The only problem is that the library uses Jinja2 instead of Django templates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants