11 Replies Latest reply on Jun 9, 2008 12:05 AM by Zaid Al-Hilali

    Script to export layers to pdf

      Is there a script that can export the top-level Layers of an Adobe Illustrator CS3 document as a multi-PAGE PDF?
        • 1. Re: Script to export layers to pdf
          Level 1
          This was the script I used in CS2, but it will not work in CS3.  Can anyone help<br /><br />const mm = 72/25.4;<br /><br />var doc = app.activeDocument;<br /><br />var bleedBorder = 5 *mm;<br />var dialogStr = 'Write PDFpreset name';<br />var NamePreset = '[Illustrator Default]';<br /><br />var strColor = new CMYKColor();<br />var nameLayer = 'effect';<br />     strColor.cyan = 0;<br />     strColor.magenta = 0;<br />     strColor.yellow = 0;<br />     strColor.black = 0;<br />     <br />if (documents.length > 0){<br />     if (str = prompt (dialogStr, NamePreset)) {<br />          NamePreset = str;<br />          var saveOpts = new PDFSaveOptions();     <br />          saveOpts.pDFPreset = NamePreset;     <br />          h = doc.height;<br />          w = doc.width;<br />          if (doc.saved==false) doc.save();<br />          var mLayer= doc.layers.add();          <br />          mLayer.name = nameLayer;<br />          var rect = mLayer.pathItems.rectangle (h + bleedBorder, 0 - bleedBorder, w + bleedBorder*2, h + bleedBorder*2);<br />          rect.fillColor = strColor;<br />          rect.stroked = false;<br />          rect.opacity = 100.0;<br />          mLayer.zOrder(ZOrderMethod.SENDTOBACK);<br />          mLayer.locked = true;<br />          for (i=0; i<doc.layers.length; i++)<br />               if (doc.layers[i].locked == false) doc.layers[i].visible = false;<br />          fullDocName = doc.fullName;<br />          var param = doc.name.split('.');<br />          realDocName = param[0];<br />          for (i=0; i<doc.layers.length; i++){<br />               if (i-1<0) doc.layers[i].visible = true;<br />               else {<br />                    doc.layers[i-1].visible = false;<br />                    doc.layers[i].visible = true;<br />               }<br />               if (doc.layers[i].locked == false) {     <br />                    docName = '_sb_'+realDocName+doc.layers[i].name;     <br />                    var saveName = new File ( doc.path + "/" + docName );<br />                    doc.saveAs( saveName, saveOpts );<br />               }<br />          }<br />          doc.close(SaveOptions.DONOTSAVECHANGES);<br />          doc = null;<br />          app.open (fullDocName);<br />     }<br />}
          • 2. Re: Script to export layers to pdf
            Did you ever find a script to do this for CS3? I'm looking to do the same thing.
            • 3. Re: Script to export layers to pdf
              what format do I save this file as, and where do I put it in order to access it from inside illustrator?
              • 4. Re: Script to export layers to pdf
                Level 1
                ok, got it to work. thanks. Any word on a cs3 version? We are finally upgrading, but now this will break.
                • 5. Re: Script to export layers to pdf
                  That's exactly the type of script i need right now, i m working on a document that has over 55 layers and i need to save it as 1 pdf, how do i create this script using which software and how do i save it and make it work?
                  • 6. Re: Script to export layers to pdf
                    I get error messages when i try Jennifer Cohens script.
                    any solutions someone?
                    I need it for CS2.
                    • 7. Re: Script to export layers to pdf
                      Level 1
                      Jennifer Cohens script does just save every layer as a pdf-file.
                      i need something that produces a multipage pdf (each page one layer).
                      • 8. Re: Script to export layers to pdf
                        Level 1
                        very active forum...
                        • 9. Re: Script to export layers to pdf
                          Larry G. Schneider Adobe Community Professional & MVP
                          Your easiest choice is to use Acrobat and combine the PDFs into a single file.
                          • 10. Re: Script to export layers to pdf
                            Level 1
                            Ya but i need to create it on the fly with a script.

                            function create_pdf(){

                            doc = activeDocument;
                            pages = doc.layers.length;

                            for (i=0; i<[pages]; i++) {

                            docRef = doc.layers[i];
                            docRef.visible = false;

                            for (i=0; i<doc.layers.length; i++) {
                            doc.layers[i].visible = true;
                            docRef = activeDocument;
                            printJobOptions= new PrintJobOptions();
                            options = new PrintOptions();
                            options.jobOptions = printJobOptions;
                            printJobOptions.collate = true;
                            printJobOptions.designation = PrintArtworkDesignation.ALLLAYERS;
                            printJobOptions.reverse = false;
                            docPath = new File("~/printJobTest1.ps");
                            printJobOptions.file = docPath;
                            doc.layers[i].visible = false;

                            This is nearly what i want... except it prints all on one page.. so i need to find the trick that changes the page index while printing.. Any idea?
                            I think with the right modification this script will do the job for everyone who needs it.
                            • 11. Re: Script to export layers to pdf
                              Zaid Al-Hilali Level 1
                              I've used a number of scripts before for InDesign, they worked for me. However I tried Cohen's script in post 1, on Illustrator CS2 but it doesn't show in the Script list! What's the procedures for Illustrator, is this a JavaScript, I assume this scrip works for Mac and PC?