5 Replies Latest reply on Sep 5, 2010 7:27 AM by mlavie

    Change graphic with XML

    Kevin van der Laak

      How do we change a graphic in a Indesign Document? We have build a template and we see that a graphic has a href attribute. Sow whe tought changing the attribute will change the image also but that doesn't happen.


      What do we have to do to change the graphic?

        • 1. Re: Change graphic with XML
          sudar1983_14 Level 2



          If you are changing the arguments at the runtime, it will not change the graphic, if you want to change the graphic at runtime then you have to write a script for changing the graphic.





          • 2. Re: Change graphic with XML
            Kevin van der Laak Level 1

            Yes ok, thanks. But how do i do that? I have a script that replaces all the text etc... but how


            // This script uses scriptArgs to fill out a business card template
            myDoc = app.open(File("/c/Template-nieuwsbrief.indd"));

            myStructure = myDoc.xmlElements.item("Root");

            with (myStructure) {
              xmlElements.item("NieuwsbriefTitel").contents = "Titel van nieuwsbrief ";
              xmlElements.item("NieuwsbriefSubtitel").contents = "Subtitel van nieuwsbrief";
              xmlElements.item("NieuwsbriefDatum").contents = "30 april 2009";
              xmlElements.item("NieuwsbriefHeader").xmlAttributes.item("href").value = "file:///c/People.jpg";
              xmlElements.item("InhoudTitel").contents = "Inhoudtitel";
              xmlElements.item("InhoudTekst").concents = "InhoudTekst";
              xmlElements.item("AanbiedingTitel").concents = "AanbiedingTitel";
              xmlElements.item("AanbiedingTekst").concents = "AanbiedingTekst";
              xmlElements.item("AanbiedingTekstlinks").concents = "AanbiedingTekstlinks";
              xmlElements.item("AanbiedingTekstrechts").concents = "AanbiedingTekstrechts";
              xmlElements.item("FooterTekst").concents = "FooterTekst";
              xmlElements.item("ArtikelTitel").concents = "ArtikelTitel";
              xmlElements.item("ArtikelTekst").concents = "ArtikelTekst"; 

            //export as pdf
            myDoc.exportFile(ExportFormat.pdfType, new File("/c/nieuwsbrief.pdf"));

            catch (err)




            • 3. Re: Change graphic with XML
              sudar1983_14 Level 2



              Please follow the below steps (using scripting)


              1. Find xmlElement, which is having the 'href' attribute using xml rules.

              2. Already it was loaded in the frame, so remove that graphic.

              3. You know what image should be loaded to the text frame, so you can load the image within textframe.




              • 4. Re: Change graphic with XML
                Kevin van der Laak Level 1

                thanks sudar, it does sound very easy but can you give me a sample code? I am a complete newbe with programming on indesign

                • 5. Re: Change graphic with XML
                  mlavie Level 1

                  Beste Kevin,


                  Did you ever solve this, and if so - how?