# How to print all the picture in the root directory?

I have many pictures in the root directory like this:

I want print all of them in .pdf files. It is too effortless to do it one by one. How to do it efficiently. Thank you!

• Look like you’re using Mac OS X … in that case you can use the “Preview” app to generate such a PDF … why do you want to do it with TeX? – Tobi Jan 12 '16 at 16:06
• I'm curious as if there is a solution for that though. Sure you can always use an external app, but as a MS user, I'm not always happy with the default picture printing software. I really wonder whether such an approach exists or not. – Sergei Poulp Jan 12 '16 at 16:13
• My OS is Linux, I think there is no any other software on my computer can do this. – zzy Jan 12 '16 at 16:22
• Btw on linux, there are certainly other software to do this. My thirst thoughts is ImageMagick or GraphicsMagick with the compose option and then a conversion to pdf. – sztruks Jan 12 '16 at 16:52

Background: I have a folder tree with 4,500 *.jpg pictures in it. I have been working on an automated way to print all the the pictures into a single pdf file. So far, if you put this program in the directory with the pictures and then compile it, you will get a pdf will all of the pictures in that folder. I have made the change to print *.png files and verified it works on my system. Win 8.1.

I have also not edited out any of the in progress discussions which include the references to how I solved certain problems. Open issues: Extra periods in file names have to be removed manually; Only able to do one folder at a time and really would like to be able to loop thru the full tree.

\documentclass[12pt,letterpaper,landscape]{book}
\usepackage[margin=.5in]{geometry}
\usepackage{graphicx}
\usepackage[space]{grffile} % Suggested by http://tex.stackexchange.com/questions/8422/how-to-include-graphics-with-spaces-in-their-path

%% Suggested by  http://tex.stackexchange.com/questions/69142/include-figure-from-macro-with-underscore-in-filename
\newcommand{\PlotFrameB}[1]{%
\begin{center}\includegraphics[min size={\textwidth}{0.9\textheight},max size={\textwidth}{0.9\textheight}]{#1}\par \textbf{{#1}}\end{center}\endgroup}
\def\PlotFrame{\begingroup
\catcode\_=12
\PlotFrameB}
%%%%%%%

%%Suggested by http://tex.stackexchange.com/questions/53458/inserting-figures-using-loops/53645#53645
\edef\subdir{"Sub Dir/"}

\graphicspath{{\subdir}}
%% Removed  from path above
\immediate\write18{cmd /c dir /b \subdir\space *.png > imagelist.txt}
%%%%%%%%

\begin{document}
\textbf{Known and Solved Problems}
\begin{itemize}
\item Doing all of the below in Win 8.1, MikTeX 2.9
\item \textbf{SOLVED} Using graphics files with spaces in the file names.
\begin{verbatim}
...
\usepackage[space]{grffile}
...
\end{verbatim}
\item \textbf{SOLVED} Using graphics files with underscores in the file names.
\begin{verbatim}
...
\newcommand{\PlotFrameB}[1]{%
\begin{center}%
\includegraphics[min size={\textwidth}{0.9\textheight},%
max size={\textwidth}{0.9\textheight}]{#1}\par \textbf{{#1}}%
\end{center}\endgroup}
\def\PlotFrame{\begingroup
\catcode\_=12
\PlotFrameB}
...
\end{verbatim}
\item \textbf{SOLVED} How to maximize the size of the picture when either height or width could be the limiting factor\par
\begin{verbatim}
...
\usepackage{graphicx}
...
... \includegraphics[min size={\textwidth}{0.9\textheight},max size={\textwidth}{0.9\textheight}]{#1} ...
...
\end{verbatim}
\item  \textbf{SOLVED} How to loop through all the pictures with *.jpg extension in the folder
\begin{verbatim}
...
\makeatletter
\begingroup
\endlinechar=-1\relax
\loop
\filename@parse{\data}
\PlotFrame{"\filename@base"}\endgraf\newpage
\repeat
\endgroup
\makeatother
...
\end{verbatim}
\item  How to set the graphics paths so only one copy of this program is needed to go thru all the photos in tree and build about 4500 pages at once.
\end{itemize}
\newpage

\makeatletter