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!
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!
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[export]{adjustbox}
\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
%% Suggested by http://tex.stackexchange.com/questions/172996/adjustbox-and-includegraphics-page-selection
\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}
\usepackage[export]{adjustbox}
...
... \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
\newread\reader
\openin\reader=imagelist.txt\relax
\begingroup
\endlinechar=-1\relax
\loop
\readline\reader to \data
\unless\ifeof\reader
\filename@parse{\data}
\PlotFrame{"\filename@base"}\endgraf\newpage
\repeat
\endgroup
\closein\reader
\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
\newread\reader
\openin\reader=imagelist.txt\relax
\begingroup
\endlinechar=-1\relax
\loop
\readline\reader to \data
\unless\ifeof\reader
\filename@parse{\data}
\PlotFrame{"\filename@base"}\endgraf\newpage
\repeat
\endgroup
\closein\reader
\makeatother
\end{document}