编写文档以输入 100 多个图像文件

编写文档以输入 100 多个图像文件

我想要实现的是将.jpg格式为图片的文档编译成一个pdf文件。问题是我不想一个接一个地输入所有文件。文件的名称遵循以下模式:

MSD 2013-10-15 00-20-27-72
MSD 2013-10-15 00-20-32-86

如何以算法的方式实现这一点?这些文件是使用一些 PowerPoint 演示文稿的快照创建的,PrtSc然后转换为.jpg格式。如果您能注意到,文件之间的唯一区别就是创建时间。

请注意,创建时图像文件应覆盖整个页面宽度和页面高度。

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\includegraphics{MSD 2013-10-15 00-20-27-72} % should cover entire page 1
\includegraphics{MSD 2013-10-15 00-20-32-86} % should cover entire page 2
.
.
.
\end{document}

使用回答下面,pdflatex 大声喊道:

! Dimension too large.
\pr@ship@end ...fi \endgroup {\dimen@ \ht \pr@box 
                                                  \ifdim \dimen@ <\z@ \dimen...
l.17 \end{document}

I can't work with sizes bigger than about 19 feet.
Continue and I'll use the largest value I can.

! Dimension too large.
\pr@ship@end ...men@ \pr@bb@iv \dimen@ii =\dimen@ 
                                                  \global \pdfvorigin \dimen...
l.17 \end{document}

I can't work with sizes bigger than about 19 feet.
Continue and I'll use the largest value I can.

! Dimension too large.
<recently read> \dimen@ 

l.17 \end{document}

I can't work with sizes bigger than about 19 feet.
Continue and I'll use the largest value I can.

! Dimension too large.
<recently read> \dimen@ 

l.17 \end{document}

I can't work with sizes bigger than about 19 feet.
Continue and I'll use the largest value I can.

! Dimension too large.
\pr@endbox ... \@undefined \voffset =-\ht \pr@box 
                                                  \hoffset =\z@ \fi \c@page ...
l.17 \end{document}

I can't work with sizes bigger than about 19 feet.
Continue and I'll use the largest value I can.

[1
! Huge page cannot be shipped out.
\pr@endbox ...y \pr@markerbox }\else \box \pr@box 
                                                  \fi }\global \advance \pr@...
l.17 \end{document}

The page just created is more than 18 feet tall or
more than 18 feet wide, so I suspect something went wrong.

The following box has been deleted: []

注意,必须从文件夹中读取每个图像文件。

答案1

修改以下内容。它仅适用于 Windows。使用 进行编译pdflatex -shell-escape filename.tex。已发布相同答案这里

代码

% filename.tex
\documentclass{article}
\usepackage[a6paper,margin=15mm]{geometry}
\usepackage{graphicx}
\edef\subdir{"Sub Dir/"}

\graphicspath{{\subdir}}
\immediate\write18{cmd /c dir /b \subdir\space *.png > imagelist.txt}


\begin{document}
\makeatletter
\newread\reader
\openin\reader=imagelist.txt\relax
\begingroup
\endlinechar=-1\relax
\loop
    \readline\reader to \data
    \unless\ifeof\reader
            \filename@parse{\data}\noindent  
            \includegraphics[scale=.5,ext=.\filename@ext,width=\textwidth,height=\textheight,keepaspectratio]{"\filename@base"}\newpage
\repeat
\endgroup
\closein\reader
\makeatother
\end{document}

文件结构

在此处输入图片描述

在此处输入图片描述

输出

为了证明我不是说谎……

在此处输入图片描述

答案2

我经常做类似下面的事情。创建(并保存)一个文件,例如 myphotos.tex,并添加所需的前言:

\documentclass{article}
\usepackage{graphicx}
\begin{document}

在命令行(Windows 下)发出以下命令

for %x in (*.jpg) do echo \includegraphics{%x}\clearpage >> myphotos.tex
echo \end{document} >> myphotos.tex

其他操作系统也可以这样做,尽管语法会有所不同。要将照片展开以填满整个页面,可以使用 \includegraphics 命令中的选项来缩放图片。例如,使用

\noindent\includegraphics[width=\textwidth,height=\textheight,keepaspectratio]

而不是\includegraphics上面的。

答案3

这将执行三个循环;参数\imageloop是“公共部分”,然后是搜索的开始分钟和结束分钟。如果小时也发生变化,则需要另一个循环。

我注释了“实际”打印函数,将其替换为测试。在我的计算机上,循环速度非常快,但是,\IfFileExists打印图像时,处理速度会相当慢。

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn
% #1 = fixed part
% #2 = starting minute
% #3 = ending minute
\NewDocumentCommand{\imageloop}{mmm}
 {
  \azet_imageloop:nnn { #1 } { #2 } { #3 }
 }
\cs_new_protected:Npn \azet_imageloop:nnn #1 #2 #3
 {
  \int_step_inline:nnnn { #2 } { 1 } { #3 }
   {
    \azet_imageloop_seconds:nn { #1 } { ##1 }
   }
 }
\cs_new_protected:Npn \azet_imageloop_seconds:nn #1 #2
 {
  \int_step_inline:nnnn { 0 } { 1 } { 59 }
   {
    \azet_imageloop_hundredths:nnn { #1 } { #2 } { ##1 }
   }
 }
\cs_new_protected:Npn \azet_imageloop_hundredths:nnn #1 #2 #3
 {
  \int_step_inline:nnnn { 0 } { 1 } { 99 }
   {
    \azet_imageloop_print:nnnn { #1 } { #2 } { #3 } { ##1 }
   }
 }

\cs_new:Npn \azet_imageloop_two:n #1
 {
  \int_compare:nT { #1 < 10 } { 0 } #1
 }

%\cs_new_protected:Npn \azet_imageloop_print:nnnn #1 #2 #3 #4
% {
%  \IfFileExists
%   {
%    #1-\azet_imageloop_two:n{#2}-\azet_imageloop_two:n{#3}-\azet_imageloop_two:n{#4}.jpg
%   }
%   {
%    \clearpage
%    \vspace*{\fill}
%    \includegraphics
%     {
%      #1-\azet_imageloop_two:n{#2}-\azet_imageloop_two:n{#3}-\azet_imageloop_two:n{#4}.jpg
%     }
%    \vfill
%   }
%   {} % nothing if the file doesn't exist
% }

%%% just for testing
\cs_new_protected:Npn \azet_imageloop_print:nnnn #1 #2 #3 #4
 {
  \par
  #1-\azet_imageloop_two:n{#2}-\azet_imageloop_two:n{#3}-\azet_imageloop_two:n{#4}.jpg
 }

\ExplSyntaxOff
\begin{document}
\imageloop{MSD 2013-10-15 00}{20}{20}
\end{document}

以下是前几行:

在此处输入图片描述

答案4

\def \SD #1-#2-#3-#4-#5-#6#7{\includegraphics[width=0.99\linewidth]
  {MSD #1-#2-#3-#4-#5-#6#7.jpg}\vfill\newpage}
  % Each "-" will match a hyphen "-" in the filename
\catcode`M=0 % M is now conveninetly synonym to \
\input{imagelist.tex} % MSD is like \SD so each line of this file now calls \SD.
\catcode`M=11 % clean up of M.

如果文件 imagelist.txt 的每一行也包含后缀 .jpg,那么您应该将“SD #1-#2-#3-#4-#5-#6#7”替换为“SD#1.jpg”。

相关内容