16 Replies Latest reply on Mar 4, 2012 12:12 PM by Muppet Mark

    How to request - Updating an embedded image in a PDF using Actions but not all actions are recorded

    Bob Smith LS2

      i am trying to create an Action in CS3 but some of my actions are not been recorded.

       

      What i want to do is run the Batch option on a folder with a 1,000 PDFs in it. The PDFs

      (which were created in Illustrator CS3) consist of a single page with a single embedded

      image at the foot of the page. I am trying to update that embedded image.


      The Actions i am trying to record are...


      1) Select the single image in the Links palette.
      2) Choose the "Relink.." option in the drop down menu of the Links palette.
      3) Navigate to the new image and select "Place".
      4) Save and close document.


      But the first two actions are not been recorded.


      How do i get around this problem ?


      Note: From trying this manually the new image seems to take on the horizontal and

      vertical scaling of the previous image which is what i want. But if i am going to have to

      do a script then that is a factor that may have to be incorporated into the script.

       

      Any help appreciated.

        • 1. Re: How to request - Updating an embedded image in a PDF using Actions but not all actions are recorded
          Muppet Mark Level 5

          Bob, firstly yes script should be able to do this quite easy… Is the image to be replaced the same one in all cases or does each file have a new image?

          • 2. Re: How to request - Updating an embedded image in a PDF using Actions but not all actions are recorded
            Bob Smith LS2 Level 1

            It is the same image in all cases. It has the same dimensions as the embedded image.

            • 3. Re: How to request - Updating an embedded image in a PDF using Actions but not all actions are recorded
              Muppet Mark Level 5

              Sounds reasonably straight forward then… The biggest issue would be the files that need procesing… Where are they on system? i.e. In one directory and just the files in question or mixed with other files in loads of directories…

              • 4. Re: How to request - Updating an embedded image in a PDF using Actions but not all actions are recorded
                Bob Smith LS2 Level 1

                All files to be processed are in one directory(folder) and it is just the files in question.

                • 5. Re: How to request - Updating an embedded image in a PDF using Actions but not all actions are recorded
                  Muppet Mark Level 5

                  The embedded image in question is it the only one in files? or is there a way for script to identify it?

                  • 6. Re: How to request - Updating an embedded image in a PDF using Actions but not all actions are recorded
                    Bob Smith LS2 Level 1

                    Yes. It is called image2.jpg

                     

                    If its any help this is how the folder is organised.

                     

                    The main folder is called "workingfolder"

                    Inside "workingfolder" is "image2.jpg" and 2 folders called "pdffolder" (which contains the PDFs) and "pdfoutput" which is a destination folder for the PDFs to be saved to when the image has been updated. Note: If the script doesn't save the updated PDF to a new folder then i can live with that.

                    • 7. Re: How to request - Updating an embedded image in a PDF using Actions but not all actions are recorded
                      Muppet Mark Level 5

                      Can you post a web link to a sample file or two… I can script this either way… For save as I would need to know the correct options to pass…

                      • 8. Re: How to request - Updating an embedded image in a PDF using Actions but not all actions are recorded
                        Bob Smith LS2 Level 1

                        Sorry, i can't post any samples.

                        I don't know what options are.

                        Go for which ever is the easiest method for you.

                        • 9. Re: How to request - Updating an embedded image in a PDF using Actions but not all actions are recorded
                          Muppet Mark Level 5

                          The easiest is to just save over existing… Give this a test… And I mean on just a handfull of copied files… If it works for you run on your real directory ONLY after making a back-up or copy… The problem is once a file is embedded script can't swap the link… It has to remove and replace… Placed links are much easier to deal with… This worked with images same size and just placed…

                           

                           

                          #target illustrator
                          
                          function replaceImage() {
                          
                                    var i, doc, pdfFolder, pic, rep, rip, fileList, uIL;
                          
                                    pdfFolder = Folder.selectDialog( 'Please choose your Folder of AI PDFs…' );
                          
                                    pic = File.openDialog( 'Please choose your replacement Image…' );
                          
                                    if ( pdfFolder != null && pic != null ) {
                          
                                              fileList = pdfFolder.getFiles( /\.pdf$/i );
                          
                                              if ( fileList.length > 0 ) {
                          
                                                        uIL = app.userInteractionLevel;
                          
                                                        app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
                          
                                                        for ( i = 0; i < fileList.length; i++ ) {
                          
                                                                  doc = app.open( fileList[i] );
                          
                                                                  rip = doc.rasterItems[0].position;
                          
                                                                  rep = doc.placedItems.add();
                          
                                                                  rep.file = pic;
                          
                                                                  rep.move( doc.rasterItems[0], ElementPlacement.PLACEBEFORE )
                          
                                                                  rep.position = rip;
                          
                                                                  doc.rasterItems[0].remove();
                          
                                                                  rep.embed();
                          
                                                                  doc.save();
                          
                                                                  doc.close();
                          
                                                        };
                          
                                                        app.userInteractionLevel = uIL;
                          
                                              } else {
                          
                                                        alert( 'This Folder contained NO Illustrator PDF files?' );
                          
                                              };
                          
                                    };
                          
                          };
                          
                          replaceImage();
                          
                          
                          • 10. Re: How to request - Updating an embedded image in a PDF using Actions but not all actions are recorded
                            Bob Smith LS2 Level 1

                            Its very impressive but there are 2 problems with it.


                            It is generating the contents of the PDF as an .ai file and leaving the original

                            PDF untouched.
                            So a folder with "example.pdf" will result in a folder with "example.pdf" and

                            "example.ai" instead of just an updated "example.pdf".

                             

                            Secondly, while it's X and Y position looks correct, the new image has not

                            inherited the horizontal and vertical scaling of the original image (these values

                            are the only information about the original image that is displayed when i double

                            click on it in the Links palette).

                            All of the original images have the same horizontal and vertical scaling of 31.414%.
                            If i select the image and go Object> Transform> Transform Each and imput the

                            31.414% on the Horizontal and Vertical in the "Scale" section and also select the

                            top left "reference point" on the grid, then the image is in the correct position.


                            • 11. Re: How to request - Updating an embedded image in a PDF using Actions but not all actions are recorded
                              Muppet Mark Level 5

                              We can transform the object scaling from top/left no problem… I wasn't sure about the PDF saving part… I was hoping it would just overwrite the file where it is… I will need either all the options you would use when saving to PDF or better still do you save using a given PDF Preset?

                               

                              Does adding the line…

                               

                              rep.resize( 31.414, 31.414, true, true, true, true, 100, Transformation.TOPLEFT );
                              

                               

                              Between the lines…

                               

                              rep.position = rip;
                              
                              doc.rasterItems[0].remove();
                              

                               

                              If so and you can give me the name of a saved PDF preset you could be off and running…

                              • 12. Re: How to request - Updating an embedded image in a PDF using Actions but not all actions are recorded
                                Bob Smith LS2 Level 1

                                I tried the extra line and it works. The updated image is in the correct X and Y position and has the correct Horizontal and Vertical scaling.

                                 

                                It is still saving as an .ai file though. These are the "options" i have selected when i choose

                                 

                                File>Save as..

                                Adobe PDF Preset: [Illustrator Default]
                                Standard: None
                                Compatability: Acrobat 6(PDF 1.5)

                                 

                                and these boxes are ticked:
                                1)Preserve Illustrator Editing Capabilities
                                2)Embed Page Thumbnals
                                3)Create Acrobat Layers from Top-Level Layers


                                On the "Compression" window it has a tick mark

                                next to "Compress Text and Line Art"

                                • 13. Re: How to request - Updating an embedded image in a PDF using Actions but not all actions are recorded
                                  Muppet Mark Level 5

                                  If you are using a preset [Illustrator Default] then that should be all I need ( I will go check ) It's just a saved list of opions… much easier than setting all the properties out ( a long list )… I will rework it…

                                  • 14. Re: How to request - Updating an embedded image in a PDF using Actions but not all actions are recorded
                                    Muppet Mark Level 5

                                    Give this a trial… It does a save as which is much safer than overwriting… At least you still have your originals should I get something wrong…? I did test but only with 3 files…

                                     

                                    #target illustrator
                                    
                                    function replaceImage() {
                                      
                                              var i, doc, fileList, inFolder, outFolder, opts, pic, rep, rip, saveFile, uIL;
                                    
                                              inFolder = Folder.selectDialog( 'Please choose your Folder of AI PDFs…' );
                                      
                                              outFolder = Folder.selectDialog( 'Please choose a Folder to save AI PDFs in…' );
                                      
                                              pic = File.openDialog( 'Please choose your replacement Image…' );
                                    
                                              if ( inFolder != null && outFolder  != null && pic != null ) {
                                    
                                                        fileList = inFolder.getFiles( /\.pdf$/i );
                                    
                                                        if ( fileList.length > 0 ) {
                                      
                                                                  uIL = app.userInteractionLevel;
                                      
                                                                  app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
                                      
                                                                  for ( i = 0; i < fileList.length; i++ ) {
                                      
                                                                            doc = app.open( fileList[i] );
                                      
                                                                            rip = doc.rasterItems[0].position;
                                      
                                                                            rep = doc.placedItems.add();
                                      
                                                                            rep.file = pic;
                                      
                                                                            rep.move( doc.rasterItems[0], ElementPlacement.PLACEBEFORE )
                                      
                                                                            rep.position = rip;
                                      
                                                                            rep.resize( 31.414, 31.414, true, true, true, true, 100, Transformation.TOPLEFT );
                                      
                                                                            doc.rasterItems[0].remove();
                                      
                                                                            rep.embed();
                                      
                                                                            opts = new PDFSaveOptions();
                                      
                                                                            opts.pDFPreset = '[Illustrator Default]';
                                      
                                                                            saveFile = File( outFolder + '/' + doc.name );
                                      
                                                                            doc.saveAs( saveFile, opts );
                                      
                                                                            doc.close( SaveOptions.DONOTSAVECHANGES );
                                      
                                                                  };
                                      
                                                                  app.userInteractionLevel = uIL;
                                      
                                                        } else {
                                      
                                                                  alert( 'This Folder contained NO Illustrator PDF files?' );
                                      
                                                        };
                                    
                                              };
                                    
                                    };
                                      
                                    replaceImage();
                                    
                                    
                                    • 15. Re: How to request - Updating an embedded image in a PDF using Actions but not all actions are recorded
                                      Bob Smith LS2 Level 1

                                      Hi Muppet Mark. I've tried it on a few dozen files and it works perfectly.

                                      Thankyou very much for your imput and your time.

                                       

                                      Another subject.

                                      When i was watching the script running i noticed that quite a few of the files have a block of text outside of the artboard area that i forgot to delete.

                                      Is there a script i can run that will delete any items that are outside the artboard area? Should i start another thread for this?

                                      • 16. Re: How to request - Updating an embedded image in a PDF using Actions but not all actions are recorded
                                        Muppet Mark Level 5

                                        I have not tried… But you could well get away with an action for this… If you record an action to select > all on active artboard, select > inverse & delete… Run the saved action in batch mode from the actions flyout menu… Should this fail shout back in a new thread… I think it should work though…