Skip to main content
Known Participant
October 2, 2021
Answered

How to Export separate pdf files from a book, but keep their original file names?! Help

  • October 2, 2021
  • 2 replies
  • 996 views

I have a book with 40 different files in it, each with their own file name. 

 

How do I select the entire book, export into separate pdf pages, and keep each of their original file names??

 

The only options are to create a single pdf with all the files in it, or to create separate pdfs, but with a new name, the same name for all of the files, but maybe with a different number at the end of each pdf , not their actual original individual file names

 

Im currently using way too many steps in order to achieve this... is there an easy way to do this in indesign?

 

 

This topic has been closed for replies.
Correct answer m1b

You're welcome! Try this:

1. Select the text from my post - just the "code" styled part.
2. Make a new text file in Notepad or TextEdit (must be plain text—not rich text).
3. Paste the script code copied in step 1.
4. Save as "Export Book As Individual PDFs.js" (note: file extension is "js") to your desktop.
5. In Indesign, open the Script panel, right-click on on User folder and choose "Reveal".
6. Move the file you saved in step 4 to the User folder that should now be visible.
7. Back in Indesign, the script should appear in the User folder of Scripts Panel.
8. Double click to run the script.

- Mark

2 replies

Community Expert
October 2, 2021

Hi Melissa,

see also into the script pdf_individuals.jsx written by Peter Kahrel, in case you need to export to PDF Interactive as well:

 

Export book documents to individual PDF files
by Peter Kahrel
Version history: 21 June 2020: Added support for interactive PDF export.

https://creativepro.com/files/kahrel/indesign/pdf_individuals.html

 

FWIW:

I tweaked the width and height values of the UI a bit so that I can see longer file names.

And I reduced the overall height of the script's UI so that it will better fit to my laptop's screen when the book contains a large number of documents like in this case:

 

 

Regards,
Uwe Laubender

( ACP )

m1b
Community Expert
Community Expert
October 2, 2021

Hi, I've put together a script that (I think) will do what you want. Just change the parameters to your needs. Let me know if it works for you.

- Mark

 

/*

    Export Book As Individual PDFs

    by m1b, posted here: https://community.adobe.com/t5/indesign-discussions/how-to-export-separate-pdf-files-from-a-book-but-keep-their-original-file-names-help/m-p/12418944#M447167

*/

function main() {

    exportBookAsIndividualPDFs({

        // 2-number array of 1-based document numbers
        // range: undefined, will export all documents of book
        // range: [1, 4], exports only the first 4 documents of book
        range: undefined,

        // name of folder to export pdfs into
        // will be created if it doesn't exist
        // folder is in same folder as book
        folderName: 'PDFs',

        // the PDF preset name
        PDFPresetName: '[Press Quality]'

    });

    function exportBookAsIndividualPDFs(params) {
        var range = params.range,
            folderName = params.folderName,
            presetName = params.PDFPresetName;

        folderName = folderName || 'PDFs';
        PDFPresetName = presetName || '[Press Quality]';

        try {

            var myPDFExportPreset = app.pdfExportPresets.itemByName(PDFPresetName)
            if (!myPDFExportPreset.isValid)
                throw 'PDF Preset "' + PDFPresetName + '" is not valid.';

            if (app.books.length == 0)
                throw 'No books currently open.'

            var book = app.books[0],
                exportPath = book.filePath + '/' + folderName + '/',
                exportFolder = new Folder(exportPath);

            // prepare the document range, if specified
            if (range == undefined || range.length != 2)
                range = [1, book.bookContents.length];

            // get the book contents
            var bkContents = book.bookContents.itemByRange(range[0] - 1, range[1] - 1);
            if (bkContents.constructor.name != 'BookContent')
                throw 'Could not get book content for range ' + range + '.'

            // this gets file references
            var exportDocs = bkContents.fullName;

            // set up folder
            if (!exportFolder.exists)
                exportFolder.create();

            // export each document
            var i;
            for (i = 0, r = range[0] - 1; r < range[1]; i++, r++) {
                var doc = exportDocs[i],
                    filename = doc.name.replace(/\.indd$/, '.pdf'),
                    exportFile = File(exportPath + filename);

                // export
                book.exportFile(
                    ExportFormat.PDF_TYPE,
                    exportFile,
                    false,
                    myPDFExportPreset,
                    [book.bookContents.item(r)]
                );
            }

            // done
            alert(i + ' PDFs exported.');
            // reveal folder
            exportFile.parent.execute();

        } catch (error) {
            alert('Export failed\n' + error);
        }
    }

} // end main

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Export Book As Individual PDFs');

 

Known Participant
October 2, 2021

This is fantastic that you got back to me and spent time creating a script for me, I appreciate it so much, thank you! 

 

Is there anyway, if you dont mind, that you would be able to attach the script file so that I can load it into ID for testing? I am not too sure, yet, on how to edit and save out the script file as an scpt or jsx 

 

 

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
October 2, 2021

You're welcome! Try this:

1. Select the text from my post - just the "code" styled part.
2. Make a new text file in Notepad or TextEdit (must be plain text—not rich text).
3. Paste the script code copied in step 1.
4. Save as "Export Book As Individual PDFs.js" (note: file extension is "js") to your desktop.
5. In Indesign, open the Script panel, right-click on on User folder and choose "Reveal".
6. Move the file you saved in step 4 to the User folder that should now be visible.
7. Back in Indesign, the script should appear in the User folder of Scripts Panel.
8. Double click to run the script.

- Mark