DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: program to create a printout from a directory of PDF files  (Read 6,073 times)

questorfla

  • Fighting Slime all the Time
  • Supporting Member
  • Joined in 2012
  • **
  • Posts: 570
program to create a printout from a directory of PDF files
« on: January 28, 2015, 06:22 AM »
This is or should be a simple task and maybe Nitro or even Adobe reader could do it.  Once upon a time, I ran across a very neat program that could take a folder full of pdfs and in short order create a "Flah" type "Flipping Book".  Nothin gto fancy but it was impressive at the time. 
The actual NEED is to simply have a way to maintain the directory structure the files are stored in. This is the correct order for what is needed and preorganized to present an electronic version o9f the files in a directory organized like the printed notebook would have been.  The "Flipping book" would have been a nifty addition that the user could copy to a few flash drives to hand out at a meeting if necessary to allow each person to "flip" though their copy at the pace they wanted to. 
The need for this though is to allow the Users here to have a way to actually print out a pre-organized "notebook" of sorts to carry with them on a business trip .
There have been enough times when the lack of an internet connection or failure of their laptop of some other reason left them high and dry when their only copy to present is on their website if it cannot be accessed.

To resolve this, i only needed tobe able to print out the pre-organized folder and sub folders that contain the files in the order in which they are stored.  It sounded easy enough until tried it.
I may be trying too hard but I have access to the actual web-server so the files do not require downloading for me to do something like this.  While I would like to offer the electronic version of "the book" the programs i tested for doing this took an extremely long time and so far i have not gotten any output that i could use, although i admit i have not tried that many nor for that long.

I thought i would get some opinions if anyone else has ever tried to print out a "booklet" or "notebook" in the same format as the files are stored on the harddrive.  They are all just PDF files in organized sub folders.  It seems ther should be a simple enough utility that could be set to print all pdf's in the folder and sub folders while putting in a separator sheet labelled with the name of the sub folders as they change.
If anyone knows of one that would do this I would be more than happy to purchase it.  The one very high-tech version i was hopeful for had just about every feature in the world and would probably need me to run every print job.  The program was full of features but required tech support from China and their time is a bit off from the time i normally work.
This is something i need to keep simple enough to allow the Users who own the files to connect through the server to print them out in the office.  The Old Flash/Html-pdf  Flipping book program i don't remember as being that hard but so far I cannot find the one from 3 years back.

For most of these people i need something not much more complicated than "Print"  :)  All ideas appreciate.  I have a copy of Nitro pdf and one of Adobe Pdf from about a year back (ver 12 maybe) if there is a procedure in either to handle things like this.

Thanks

4wd

  • Pedantic Old Bastard
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,652
    • Coding Snacks
Re: program to create a printout from a directory of PDF files
« Reply #1 on: February 03, 2015, 12:41 PM »
If I'm understanding this correctly, you want every PDF in a folder tree concatenated with a header page between each folder of PDFs stating the folder the following group of PDFs appear in.

If that's the case then here's something from the "I thought DOS was dead department":

StrangePDFThing.cmd
Code: (generic)
@if (@CodeSection == @Batch) @then
    rem StrangePDFThing.cmd
    @echo off
    color 1a
    setlocal EnableExtensions
    setlocal DisableDelayedExpansion
    
    echo Select SOURCE folder
    for /F "delims=" %%S in ('CScript //nologo //E:JScript "%~F0"') do (
        set srce=%%S
    )
    if "%srce%"=="" goto :End
    echo Selected folder: "%srce%"
    
    set spath=%srce%
    set wdir=%cd%
    echo.%srce% > %TEMP%\header.txt
    %wdir%\txttopdf.exe -pfn101 -pfs20 -pot %TEMP%\header.txt %TEMP%\header.pdf
    pushd %srce%
    echo.Processing: "%srce%"
    %wdir%\pdftk.exe %TEMP%\header.pdf *.pdf cat output %TEMP%\out.pdf
    popd
    del %TEMP%\header.pdf
    ren %TEMP%\out.pdf temp.pdf
    
    dir /b /s /ad "%spath%" | sort >%TEMP%\sPDFt.txt
    for /f "tokens=*" %%a in (%TEMP%\sPDFt.txt) do call :DoSomething "%%~a"

    goto :End

    :DoSomething
    echo.Processing: "%~1"
    pushd "%~1"
    if not exist "*.pdf" goto :SkipIt
    echo.%~1 > %TEMP%\header.txt
    %wdir%\txttopdf.exe -pfn101 -pfs20 -pot %TEMP%\header.txt %TEMP%\header.pdf
    %wdir%\pdftk.exe %TEMP%\temp.pdf %TEMP%\header.pdf *.pdf cat output %TEMP%\out.pdf
    popd
    del %TEMP%\header.pdf
    del %TEMP%\temp.pdf
    ren %TEMP%\out.pdf temp.pdf
    :SkipIt
    goto :EOF
    endlocal

    :End
    del %TEMP%\sPDFt.txt
    del %TEMP%\header.txt
    ren %TEMP%\temp.pdf Combined.pdf
    move %TEMP%\Combined.pdf %wdir%
    exit
    
    End of Batch section
@end


// JScript section

// Creates a dialog box that enables the user to select a folder and display it.
var title = "Select a folder", rootFolder = 0x11;
var shl = new ActiveXObject("Shell.Application");
var folder = shl.BrowseForFolder(0, title, 0, rootFolder);
WScript.Stdout.WriteLine(folder ? folder.self.path : "");

Requirements:
TxtToPDF - from Adult PDF  (to generate the header sheets)
PDFtk - from PDF Labs  (to concatenate all the PDFs)

These are both free and they don't need to be installed to use, just run each installer through UniExtract and grab the files from the {app} folder.  Put them in the same folder as the command file so that you have the following:

help.html
libiconv2.dll
main.jpg
pdftk.exe
PdftkXp.exe
setting.jpg
sPDFt.cmd
TxtToPDF.exe

To run, just double-click the sPDFt.cmd file.

It creates a file called Combined.pdf in the same folder as the command file.  It worked here, limited testing done.

NOTE: It will completely die if any of the PDFs are protected, (ie. the protected PDF is unable to be appended which will screw up the whole procedure).

Source code included for you to self-modify  ;)
"I will not follow where the path may lead, but I will go where there is no path, and I will leave a trail." - Muriel Strode, 1903

Original address: https://www.donationcoder.com/forum/index.php?topic=40103.0