2

I have many pictures in the root directory like this:enter image description here

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!

  • 2
    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
4

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}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.