1 Reply Latest reply on Sep 20, 2011 2:17 AM by Haakenlid

    Exporting embedded images from InDesign

    sameervijaykar

      [Apologies for cross-posting. I mistakenly posted in the InDesign SDK earlier, where it didn't get a lot of views or helpful responses. I couldn't find a way to move the post.]

       

      I am looking for a way to programatically export embedded images from InDesign documents. These images are not linked files are a placed image would normally be. Instead, they seem to be completely embedded within the InDesign file; exporting as IDML causes the raw image data to be exported within XML itself. The itemLink property is null for the Image object.

       

      Searching in the scripting reference leads to the Image.exportForWeb and Image.exportFile methods. However, when I tried the exportForWeb function, it failed silently and returned null.

       

      The exportFile method worked but it takes as input the export format. Since the format of the original image is not available within the script, using exportFile will entail a potentially lossy conversion. (Checking for the imageTypeName for the Image object throws a "The property is not applicable in the current state" error.) Also, the exported file generated with exportFile seems to be limited to 20kb regardless of how large the original image is.

       

      One suggestion on the old post was to try Link.unembed. However, the Image.itemLink property is itself null so unembedding doesn't seem to be possible that way.

       

      Is there a better way to go about exporting these images? Any ideas why exportForWeb won't work. Thank you.

        • 1. Re: Exporting embedded images from InDesign
          Haakenlid Level 3

          Interesting problem. I toyed a bit around and found out that I was unable to export embedded images as jpg, but png worked.  PNG is lossless and I could export files of several megabyte.
          The original file format of the image did not seem to matter. Maybe InDesign treats all embedded images as png?

          var myImage = app.activeDocument.allGraphics[0];
          var myFile = new File("~/Desktop/test_image.png");
          myImage.exportFile("png", myFile);