0 Replies Latest reply on Jul 29, 2009 10:49 AM by Francis Devereux

    Replacing Placeholder Images and Text

    Francis Devereux

      Hello,

       

      I am designing a system which needs to be able to replace images and text in InDesign documents with new versions.  For example, we might have many documents containing a company logo and want to replace the company logo in all of the documents with a new one.

       

      I have InDesign Server CS4 and some of the Java CORBA samples up and running.  I have tried using data merge fields; I can get the com.adobe.ids.preferences.DataMerge objects for them but these objects don't seem to have any methods for updating the fields.  Perhaps data merging is not designed to do what I'm trying to achieve.

       

      Can anyone suggest a way of defining placeholder images and replacing them programatically?

       

      Thanks,

       

      Francis

       

      P.S. here is the code that I have so far:

       

      import java.io.File;

      import com.adobe.ids.*;
      import com.adobe.ids.basics.*;
      import com.adobe.ids.datamerge.DataMergeField;
      import com.adobe.ids.enums.kSaveOptionsNo;
      import com.adobe.ids.preferences.DataMerge;
      import com.adobe.ids.sdk.utils.ApplicationUtils;

      /**
      * Demo of InDesign data merging using InDesign Server
      *
      * @author Bright Interactive
      */
      public class DataMergeTest
      {
          public static void main(String[] args) throws Exception
          {
              String ior = args[0];
              String inFileName = args[1];
              String outFileName = args[2];

              File testInFile = new File(inFileName);
              if (!testInFile.exists())
              {
                  System.err.println(testInFile + " does not exist");
                  System.exit(1);
              }

              Document doc = null;
              ApplicationUtils utils = new ApplicationUtils(ior);
              try
              {
                  Application app = utils.getApplication();
                  app.consoleout("DataMergeTest starting");
                  VariableType vtFile = VariableTypeUtils.createFile(inFileName);
                  doc = DocumentHelper.narrow(app.open(vtFile).asObject());

                  DataMerge dataMerge = doc.getDataMergeProperties();
                  // next line throws an IdsException :-(
      //            DataMergeField pictureField = dataMerge.getNamedChildDataMergeField("Picture");
      //            System.out.println("pictureField = " + pictureField);

                  DataMergeField[] dataMergeFields = dataMerge.getAllChildDataMergeFields();
                  for (int i = 0; i < dataMergeFields.length; i++)
                  {
                      DataMergeField dataMergeField = dataMergeFields[i];
                      System.out.println(dataMergeField.getFieldName());
                      if (dataMergeField.getFieldName().equals("Picture"))
                      {
                          System.out.println("Found picture field");
                          // not sure what to do with dataMergeField now!
                      }
                  }


                  app.consoleout("DataMergeTest done");
              }
              finally
              {
                  if (doc != null)
                  {
                      try
                      {
                          doc.close(OptArg.makeSaveOptionsEnum(kSaveOptionsNo.value),
                                OptArg.noFile(),
                                OptArg.noString(),
                                OptArg.noBoolean());
                      }
                      catch (IdsException e)
                      {
                          e.printStackTrace();
                      }
                  }

                  try
                  {
                      utils.destroyORB();
                  }
                  catch (Exception e)
                  {
                      e.printStackTrace();
                  }
              }
          }
      }