11 Replies Latest reply on Aug 1, 2017 11:21 PM by tobiask43046735

    export each layer of a InDesign file (with 5 pages) to its own PDF.

    Dawn Stiles

      I'm not sure if this is possible...but I am looking for a way (possibly a script?) to export each layer of a InDesign file to its own PDF.

      I have a 5 page indesign file and each page has 3 layers, so the exported pdf would have 15 pages. Does anyone know of a way to do this?

       

       

       

      [Moved by moderator from InDesign to InDesign Scripting]

       

       

      .

        • 1. Re: export each layer of a InDesign file (with 5 pages) to its own PDF.
          jane-e Adobe Community Professional

          Not knowing script, I would personally make five PDFs and combine them using Acrobat Pro. It would take less than five minutes (maybe three).

           

          But a scripter might be able to automate it for you. I can move this to the scripting forum.

          • 2. Re: export each layer of a InDesign file (with 5 pages) to its own PDF.
            Dawn Stiles Level 1

            If you could move this to the scripting forum that would be good, as sometimes  I could have up to 20 layers on 30 pages (600 pdfs)

            Many thanks

            • 3. Re: export each layer of a InDesign file (with 5 pages) to its own PDF.
              [Jongware] Most Valuable Participant

              InDesign cannot combine PDFs or generate more PDF pages than there are in the original document. When exporting one layer at a time you would end up with at least as many separate files as there are layers.

               

              As yours seems a rather strange document (I'm not doubting that you have good reasons to work this way! But as you found out, InDesign doesn't really have a workflow for this): would it be possible to have this hypothetical script add new pages for each layer, copying only what's on it, and then hide that layer? That is, is the contents of every single layer on its own an entire page?

              • 4. Re: export each layer of a InDesign file (with 5 pages) to its own PDF.
                Dawn Stiles Level 1

                What you mentioned is exactly what i need... the contents of every single layer on its own an entire page in a pdf.

                I'd love to know if this is possible??

                • 5. Re: export each layer of a InDesign file (with 5 pages) to its own PDF.
                  TᴀW Adobe Community Professional & MVP

                  It is doable, yes. Fairly simple. Just hide all layers, then loop through all layers making a different one visible each time, and each time export the document as PDFs file, one for each page.

                   

                  Definitely scriptable... If you'd like a quote, feel free to get in touch: admin [at] id-extras.com

                   

                  Ariel

                  • 6. Re: export each layer of a InDesign file (with 5 pages) to its own PDF.
                    tobiask43046735 Level 1

                    I wrote a Python script a while ago which might be helpful:

                     

                    #!/usr/bin/python
                    # -*- coding: utf-8 -*-
                    
                    from __future__ import print_function, division, absolute_import
                    from builtins import super
                    
                    import win32com.client
                    import sys
                    import os
                    from shutil import copyfile
                    
                    def patchWin32com():
                        # https://stackoverflow.com/q/9383307/321973
                        import winerror
                        from win32com.client.dynamic import ERRORS_BAD_CONTEXT
                        global ERRORS_BAD_CONTEXT
                        if not winerror.E_NOTIMPL in ERRORS_BAD_CONTEXT:
                            ERRORS_BAD_CONTEXT.append(winerror.E_NOTIMPL)
                    
                    patchWin32com()
                    
                    # http://help.adobe.com/livedocs/pdfl_sdk/9/PDFL_SDK9_HTMLHelp/API_References/Acrobat_API_Reference/PD_Layer/General.html#PDSaveFlags1443
                    PDSaveIncremental = 0x00
                    PDSaveFull = 0x01
                    PDSaveCopy = 0x02
                    PDSaveLinearized = 0x04
                    PDSaveWithPSHeader = 0x08
                    PDSaveBinaryOK = 0x10
                    PDSaveCollectGarbage = 0x20
                    PDSaveForceIncremental = 0x40
                    PDSaveKeepModDate = 0x80
                    
                    SAVEFLAG = PDSaveFull | PDSaveLinearized | PDSaveCollectGarbage
                    
                    def splitPDFvariants(pdffile):
                        """split PDF into logo/print versions
                        at the moment, only hides the layers from settings!"""
                        pdffile = os.path.abspath(pdffile)
                        acropdf = win32com.client.Dispatch('AcroExch.PDDoc')
                        for name, logo in (('digital', True), ('print', False)):
                            pdfcopy = pdffile.rstrip('.pdf') + '-' + name + '.pdf'
                            copyfile(pdffile, pdfcopy)
                            assert acropdf.Open(pdfcopy)
                            jso = acropdf.GetJSObject()
                            ocgs = jso.GetOCGs()
                            for ocg in ocgs:
                                if ocg.name == 'Logo':  # lock Logo to relevant state
                                    ocg.initState = logo
                                    ocg.state = logo
                                    ocg.locked = True
                            jso.SetOCGOrder([])  # remove layers from menu
                            assert acropdf.Save(SAVEFLAG, pdfcopy)
                            assert acropdf.Close()
                    
                    if __name__ == '__main__':
                        splitPDFvariants(sys.argv[1])
                    
                    
                    
                    
                    
                    
                    
                    
                    

                    It opens the input argument PDF (created via InDesign, using the "create layers" PDF export option) with Acrobat (Pro) and creates a "digital" and "print" version with the layer "Logo" on and off respectively. With some adaption you can loop through the layers and create individual PDFs for each, and with some more lines you can also merge those PDFs.

                     

                    Cheers,

                    Tobias

                    • 7. Re: export each layer of a InDesign file (with 5 pages) to its own PDF.
                      Dawn Stiles Level 1

                      Thanks Tobias.

                      Sorry I know next to nothing about scripting, what should I do with your Python script to make it a usable script in Indesign?

                      • 8. Re: export each layer of a InDesign file (with 5 pages) to its own PDF.
                        Obi-wan Kenobi Adobe Community Professional

                        Ariel is right! 

                         

                        I've just called it:  "0184_EachLayer-PageToPDF_MichelAllio.jsx"

                         

                        [not for free!]

                         

                        (^/)

                         

                        Capture d’écran 2017-07-30 à 16.08.55.png

                        • 10. Re: export each layer of a InDesign file (with 5 pages) to its own PDF.
                          Obi-wan Kenobi Adobe Community Professional

                          … Interesting, Script version 2: only the pages per layer with something on the layer will be exported as pdf!

                           

                          With the Script version 1, all the layers of all the pages have been treated => 20 pdf files!

                           

                          Capture d’écran 2017-07-30 à 21.55.15.png

                           

                          With the Script version 2, just 10 pdf files!

                           

                          Capture d’écran 2017-07-30 à 21.54.05.png

                           

                          (^/)

                          • 11. Re: export each layer of a InDesign file (with 5 pages) to its own PDF.
                            tobiask43046735 Level 1

                            Dawn Stiles  wrote

                             

                            Thanks Tobias.

                            Sorry I know next to nothing about scripting, what should I do with your Python script to make it a usable script in Indesign?

                            Sorry for the brevity, the script runs independently of InDesign. You just run it via command line and pass the PDF file path and name as argument, e.g.

                             

                            python exporter.py c:\users\me\Documents\somewhere\thing.pdf
                            

                             

                            You can run this on a machine without InDesign, but instead you need Acrobat Pro. This also works for other PDFs not generated by InDesign. But as mentioned, the scripts needs a few modifications to actually extract all layers, for which I'm currently lacking the time.

                             

                            Cheers,

                            Tobias