Fitting text to exact specific size

I would like to make my text fit a certain size "box" at a specific location. The two problems I am encountering are as follows:

This long string should wrap when it hits the 4.5 inch limit but it does not:

\documentclass[landscape]{article}
\usepackage[top=1.5in, bottom=1.125in, left=.25in, right=6.25in,textwidth=4.5in, textheight=5.875in]{geometry}

\begin{document}
ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd
\end{document}


And this one just remains constant but I would like to force it to fit the entire 4.5in x 5.875in box, as in enlarge the text to make it fit the box.

\documentclass[landscape]{article}
\usepackage[top=1.5in, bottom=1.125in, left=.25in, right=6.25in,textwidth=4.5in, textheight=5.875in]{geometry}

\begin{document}
{\Huge This should fit in a 4.5in x 5.875in box but that is close to the left edge of paper, but it is not conforming to the box size desired....
\end{document}


Thanks for the help.

• Welcome to TeX.SE... note that you can indent your text by 4 spaces or with the {} code button on the editor to format your text as a code block. – cslstr Mar 26 '14 at 3:18
• A suggestion: Do us a favour and change your username to something more telling than "user1234". – Speravir Mar 26 '14 at 3:39
• First, you can only wrap text between words (or using hyphenation). To expand or contract text (or anything for that matter) to a specific size, use \resizebox from the graphics or graphix packages. – John Kormylo Mar 26 '14 at 3:46
• Related: tex.stackexchange.com/questions/123614/… and, of course, the very popular tex.stackexchange.com/questions/166418/… – Steven B. Segletes Mar 26 '14 at 10:42

This could be a job for the fitbox options of package tcolorbox. As commented, your first text needs hyphenations. But your second text can sized using the following code. I added a yellow background to show the 4.5in x 5.875in box.

Note that I included a scalable font package (lmodern) to enable the font scaling mechanism.

\documentclass[landscape]{article}
\usepackage[top=1.5in, bottom=1.125in, left=.25in, right=6.25in,textwidth=4.5in, textheight=5.875in]{geometry}
\usepackage{lmodern}% for scalable fonts!
\usepackage[many]{tcolorbox}

\begin{document}
\tcboxfit[blank,width=4.5in,height=5.875in,
fit basedim=20pt,fit fontsize macros,valign=center,
frame style={fill=yellow!50!white}% remove this line to remove the yellow background
]%
{\Huge This should fit in a 4.5in x 5.875in box but that is close to the left edge of paper, but it is not conforming to the box size desired....}
\end{document}


The first code adapts the font to fit the text inside the given box. Still, at the top and bottom of the box remain two very small blank areas. If it is important to remove them, a final stretching can be added using the following code. Note that the outer box is just for coloring the example.

\documentclass[landscape]{article}
\usepackage[top=1.5in, bottom=1.125in, left=.25in, right=6.25in,textwidth=4.5in, textheight=5.875in]{geometry}
\usepackage{lmodern}% for scalable fonts!
\usepackage[many]{tcolorbox}

\begin{document}
\tcbox[blank,width=4.5in,height=5.875in,frame style={fill=yellow!50!white}]{% just for the background
%
\resizebox{4.5in}{5.875in}{\tcboxfit[blank,width=4.5in,fit height from=5in to 5.875in,fit basedim=20pt,fit fontsize macros]%
{\Huge This should fit in a 4.5in x 5.875in box but that is close to the left edge of paper, but it is not conforming to the box size desired....}}
%
}% just for the background
\end{document}