This is probably not the solution you're looking for:
You can use, e.g., LaTeX to achieve this. You need to generate the TeX-file another way, e.g., your favorite programming language.
This requires you to know how to programme, use LaTeX and, of course, install the required tools.
In case you're interested, I can elaborate on this and add sample scripts.
Edit:
I made a little FreeBASIC programme (bit dirty but does the job) to generate the .tex-file. This can then be used to generate the final pdf-file with, e.g., Miktex and TexnicCenter.
- Download and extract the FreeBASIC compiler from http://www.freebasic.net/ (I used
FreeBASIC-1.05.0-win64.zip
).
- Save the code below as, say
code.bas
, and compile it with fbc.exe code.bas
.
- Drag and drop the folders "Report 1", "Report 2" etc. onto the new executable
code.exe
. This will generate the files "Report 1.tex", "Report 2.tex" in their respective folder.
- Download and install Miktex from http://www.miktex.org/ (enable on-the-fly installation of packages during setup) and TexnicCenter from http://www.texniccenter.org/download/ and open the report files in TexnicCenter. I'm not certain if you need to make any changes to the default settings but the internet is full of resources for this. When compiling
LaTeX -> PDF
it should install the missing packages.
Sourcecode: Processes explicitly the mentioned folder structure and filenames and nothing more.
' Drag and drop folders onto the executable in order to generate a .tex-file
' which can be used to merge the pdfs in each passed folder using LaTeX.
'
#include "vbcompat.bi"
sub expandEnviron__isFileOrFolder ( byref strPath as string )
dim iLetter as integer
if left(strPath,1)="%" then
for iLetter=2 to len(strPath)
if mid(strPath,iLetter,1)="%" then
strPath=environ(mid(strPath,2,iLetter-2))+right(strPath,len(strPath)-iLetter)
exit for
end if
next iLetter
end if
end sub
function isFileOrFolder ( byref strPath as string, byval expPath as string ptr = 0 ) as integer
' return value:
' 0: path doesn't exist
' 1: file
' 2: folder
'
dim strDir as string = curdir
dim as string strPathCopy
dim as string ptr pPath
if expPath then
*expPath = strPath
expandEnviron__isFileOrFolder(*expPath)
pPath = expPath
else
strPathCopy = strPath
expandEnviron__isFileOrFolder(strPathCopy)
pPath = @strPathCopy
end if
if fileExists(*pPath) then
return 1
elseif ( chdir(*pPath) = 0 ) then
chdir(strDir)
return 2
else
return 0
end if
end function
color(1,15)
cls
if command(1) = "" then
print "Drag and drop folders onto the executable."
sleep
end
end if
dim as string basedir
dim as string strPath = ""
dim as integer i = 1
' Process all command line arguments i.e process all folders.
while command(i) <> ""
basedir = command(i)
dim as string basedirName
' Make sure the argument is indeed a folder.
if isFileOrFolder(basedir,@strPath) = 2 then
if right(strPath,1) = "\" then basedir = left(strPath,len(strPath)-1)
basedirName = right(basedir,len(basedir)-instrrev(basedir,"\"))
print ""
print baseDirName
'
' Print some LaTeX commands.
open basedir+"\"+baseDirName+".tex" for output as #1
print #1, $"\documentclass{scrreprt}"
print #1, $"\usepackage{grffile}"
print #1, $"\usepackage{pdfpages}"
print #1, $"\usepackage{bookmark}"
print #1, $"\hypersetup{pageanchor=false}"
print #1, $"\begin{document}"
print #1, $"\pagestyle{empty}"
print #1, $"\pagenumbering{gobble}"
print #1, "%"
'
' Process contents.pdf.
dim as string tmp = basedir+"\contents.pdf"
if isFileOrFolder(tmp) = 1 then
print #1, $"\includepdf[pages=-]{contents.pdf}"
else
color(12,15):print chr(9);"missing contents.pdf":color(1,15)
end if
'
' Process execsummary.pdf.
tmp = basedir+$"\execsummary.pdf"
if isFileOrFolder(tmp) = 1 then
print #1, $"\includepdf[pages=-]{execsummary.pdf}"
else
color(12,15):print chr(9);"missing execsummary.pdf":color(1,15)
end if
'
' Process all subfolders named "chapter 1", "chapter 2" etc.
' If "chapter 4" exists but "chapter 3" does not, then "chapter 4" and
' all after that will be ignored.
dim as integer chapter_link_cnt = 0
dim as integer j = 1
dim as string nextChapterDir = basedir+$"\chapter "+str(j)
while isFileOrFolder(nextChapterDir) = 2
print #1, "%"
dim as integer k = 1
'
' Process all files named "page 1", "page 2" etc.
dim as string nextPage = nextChapterDir + $"\page "+str(k)+".pdf"
while isFileOrFolder(nextPage) = 1
if k = 1 then
chapter_link_cnt += 1
print #1, $"\includepdf[link,linkname=l";str(chapter_link_cnt); _
",pages=-]{chapter ";str(j);"/page ";str(k);".pdf}"
print #1, $"\bookmark[dest=l";str(chapter_link_cnt); _
".1]{chapter ";str(j);"}"
else
print #1, $"\includepdf[pages=-]{chapter ";str(j);"/page ";str(k);".pdf}"
end if
k += 1
nextPage = nextChapterDir + $"\page "+str(k)+".pdf"
wend
j += 1
nextChapterDir = basedir+$"\chapter "+str(j)
wend
'
print #1, $"\end{document}"
close #1
else
print ""
color(12,15):print "Error (not a folder): ";command(i):color(1,15)
end if
i += 1
wend
print ""
print ""
print "Done."
sleep
In case you want to use a different language (perhaps it can be done with a powershell script), here is a sample tex-file:
\documentclass{scrreprt}
\usepackage{grffile}
\usepackage{pdfpages}
\usepackage{bookmark}
\hypersetup{pageanchor=false}
\begin{document}
\pagestyle{empty}
\pagenumbering{gobble}
%
\includepdf[pages=-]{contents.pdf}
\includepdf[pages=-]{execsummary.pdf}
%
\includepdf[link,linkname=l1,pages=-]{chapter 1/page 1.pdf}
\bookmark[dest=l1.1]{chapter 1}
\includepdf[pages=-]{chapter 1/page 2.pdf}
%
\includepdf[link,linkname=l2,pages=-]{chapter 2/page 1.pdf}
\bookmark[dest=l2.1]{chapter 2}
\includepdf[pages=-]{chapter 2/page 2.pdf}
%
\includepdf[link,linkname=l3,pages=-]{chapter 3/page 1.pdf}
\bookmark[dest=l3.1]{chapter 3}
\includepdf[pages=-]{chapter 3/page 2.pdf}
\includepdf[pages=-]{chapter 3/page 3.pdf}
\includepdf[pages=-]{chapter 3/page 4.pdf}
\end{document}