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

Function to add blank lines to a predetermined number in DOCX #251

Open
nonprofittechy opened this issue Feb 2, 2024 · 2 comments
Open
Labels
enhancement New feature or request

Comments

@nonprofittechy
Copy link
Member

It would be handy to have a function that shortens the syntax for something like this:

{{p some_answer }}
{%p line for line in range(10-((some_answer/80) | int) %} (where 80 is the actual number of characters that fit on a line, at least on average--you can check what actually fits on your page based on the font, etc, and 10 represents the existing number of blank lines (replace with real numbers))
____________________
{%p endfor %}
@nonprofittechy
Copy link
Member Author

Even better if we could just use a tab stop and use an underline to the end of the margin?

@nonprofittechy
Copy link
Member Author

See this snippet suggested by ChatGPT:

from docx import Document
from docx.shared import Pt

# Create a new Document
doc = Document()

# Add a paragraph
p = doc.add_paragraph()

# Set a single tab stop at the right margin (assumed to be at 6 inches for US Letter size)
tab_stop = p.paragraph_format.tab_stops.add_tab_stop(Pt(6*72), leader='underline')

# Add underlined text with a right tab to extend the underline
run = p.add_run('Your Text Here\t')
run.underline = True

# Save the document
doc.save('your_doc.docx')

@nonprofittechy nonprofittechy added the enhancement New feature or request label Apr 26, 2024
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

1 participant