Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Community Beginner ,
Feb 29, 2012 Feb 29, 2012

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.

TOPICS
Scripting
2.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Mentor , Mar 02, 2012 Mar 02, 2012

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…' );

 

         

...
Translate
Adobe
Mentor ,
Mar 01, 2012 Mar 01, 2012

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 01, 2012 Mar 01, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Mar 01, 2012 Mar 01, 2012

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…

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 01, 2012 Mar 01, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Mar 01, 2012 Mar 01, 2012

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 01, 2012 Mar 01, 2012

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Mar 01, 2012 Mar 01, 2012

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…

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 01, 2012 Mar 01, 2012

Sorry, i can't post any samples.

I don't know what options are.

Go for which ever is the easiest method for you.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Mar 01, 2012 Mar 01, 2012

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 );

                                        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();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 01, 2012 Mar 01, 2012

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.


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Mar 02, 2012 Mar 02, 2012

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…

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 02, 2012 Mar 02, 2012

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"

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Mar 02, 2012 Mar 02, 2012

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…

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Mar 02, 2012 Mar 02, 2012

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 );

 

                                        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();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 04, 2012 Mar 04, 2012

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Mar 04, 2012 Mar 04, 2012
LATEST

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…

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines