I'm writing some software that takes a Microsoft Word document, replaces variables inside, then prints the final document onto an ID card. The document has limited space and must fit on a single page, but needs to include the person's photo, as well as first and last names, which can get quite long

The document is laid out inside of a table so common elements remain in the same spot (e.g. barcode is always at the bottom, but when I put in a really long first or last name, the text wraps and pushes everything onto two pages, which I don't want.

There's an option to fit the text to the table, but that changes the font width (not the font size), so long names look horizontally squashed, and if the user has a short name (like Leo), the whole name is spaced out across the page (so L is on the left, E in the middle, and O on the right)

Sample card with stretched names

(The blue box is where the logo will go, the green box, the photo)

Is there a way to fit the text into the table without causing the text to "justify", or cause the font to shrink horizontally?

EDIT: I'd just be happy to stop the justification, and leave the font squished.

EDIT 2: I've tried just about everything, save running some kind of macro that measures the text and shrinks it down (too complex, not worth it for only about six out of the 1000 cards I need to produce). My eventual compromise (not answer, I'm still looking for one!) was to set the row height to be exact (not "at least") so when new text gets entered, it's truncated. Because we have the photo and user's ID (e.g. Leo Superlongfirstnamethatdoesn'texist's user ID would be something like SUPELEO1), that's enough for positive ID.

For completeness, I've tried aligning text using both paragraph and cell alignment, creating another table within the cell (so I could set one as "auto width" with "fit text" enabled and the other, to fixed width, without fit-text. Turns out auto-width doesn't work with a table inside a cell. So I'm all out of ideas!

  • I don't think it very convenient and practical to fit every word page individually to the size. If you do so, you have to assign a learned person to do all these adjustments as and when a new requirement arrives. You should rather think about deciding all these before hand for each field/ item and fix that in the word file itself so that it gets fixed on entry itself, and then any page and every page can be fitted. That L e o looks odd broken like this, shall look better if it a single word without spaces in between and is centered horizontally. – VSRawat Feb 8 '19 at 17:02
  • 1
    @VSRawat: "L E O" is how Word adjusted the text. It's not me putting spaces in, it's Word's "Fit Text to Table" option that is trying to spread one word across the whole width of the cell. Also because it's an identifying name, I needed to have all text visible, because if the name is "Leo Johnston-Smith", it wouldn't be right to have the card say "Leo Johnston-" My eventual fix was to just find the cards that needed manual adjusting and just shrink the font size until it fit. A manual process, but it works. – Grayda Feb 9 '19 at 1:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.