4 Replies Latest reply: Jun 20, 2012 2:49 PM by Muppet Mark RSS

    Embed pdf in document

    Darcus78

      Hi all

       

      First post and first script

       

      Im trying to add a pdf on top of an existing PDF in illustrator using a script. This is supposed to be done by anyone at my firm so that is why I want it in a script. I also have a lot of other functions that works that will do some other stuff with this document.

       

      Created this from the scripting guide but it doesnt work. Im pretty sure its the embedDoc var thats empty and i dont understand why.

      Im not sure if the File "points" to the directory of the script or the original file but Ive tried both ofcoarse.

       

      This is the masterpiece

       

      var embedDoc = new File("/temp/testfile1.pdf");

      if ( app.documents.length > 0 && embedDoc.exists ) {

      var doc = app.activeDocument;

      var placed = doc.groupItems.createFromFile( embedDoc );

      }else {alert("suck")}

       

      //Marcus

        • 1. Re: Embed pdf in document
          Muppet Mark Community Member

          I would not have thought your path was valid have you tried to just test that condition on its own?

           

          alert ( File("/temp/testfile1.pdf").exists );

          • 2. Re: Embed pdf in document
            Darcus78 Community Member

            Hi Mark

             

            Thanks for that reply

             

            Well I definitly think your right on this one but where does the path begin. When I removed the app.documents.length from the if statement it went to the alert() function.

            If I start the path with / it should start from where the original file is right?

            • 3. Re: Embed pdf in document
              [Jongware] CommunityMVP

              / always starts at the root of your current drive. What *that* means depends on your OS!

               

              You'd get the path from your current file by something like

               

              currPath = app.activeDocument.path;

               

              .. then you can add your temp folder with

               

              embedDoc = new File(currPath+'/temp/testfile.pdf");

               

              .. but *only* if that sub-folder actually exists in the path you stored the file in. The actual code depends entirely on your workflow, I guess.

              • 4. Re: Embed pdf in document
                Muppet Mark Community Member

                Are you debugging your script in the ESTK or just writing it in a text editor? What OS are you on? Where is this PDF file? ( the full path )