9 Replies Latest reply on Sep 3, 2010 5:19 AM by [Jongware]

    Export PNG Error:

    Barqx Level 1

      I want to export my *.indd as PNG. I tried the following code:

       

      function ExportPNG("/c/test)
      {
          try
          {
              app.activeDocument.exportFile(ExportFormat.PNG_FORMAT, File(filePath + '.png'));
          }
          catch(e)
          {
              alert(e);
          }
      }
      

       

      However, I get the following error:

       

      Error: The specified object does not support the desired export format.

       

      How can I fix this?

        • 1. Re: Export PNG Error:
          [Jongware] Most Valuable Participant

          By rewriting a large part of InDesign

           

          The error occurs because you cannot export an entire document to PNG (for several reasons, but the most obvious one is that PNG is not a multi-page format).

           

          (Come to think of it: I'm not perfectly sure it works on a page either.)

          • 2. Re: Export PNG Error:
            Barqx Level 1

            I found a "solution" here: http://forums.adobe.com/message/2786712

             

            However, for me the code specified:

             

            app.activeDocument.selection[0].exportFile(ExportFormat.PNG_FORMAT, File(new File("c:\\test.png")));
            
            

             

            Does not work.

             

            ???

            • 3. Re: Export PNG Error:
              [Jongware] Most Valuable Participant

              Yeah, that's mine.

               

              It still works perfectly -- on Windows 7, CS4, specifically. If you are on Mac OS X, it would be the File name notation your system falls over. Try something like this (and make sure you have something selected...)

               

              app.activeDocument.selection[0].exportFile(ExportFormat.PNG_FORMAT, File(new File("~/Desktop/test.png")));

              • 4. Re: Export PNG Error:
                [Jongware] Most Valuable Participant

                On further thought: it might not work as you think it should because this very short example only exports the very first item in any selection. If you want to export an entire page, you'll have to

                 

                1. Draw a rectangle the size of that page, all over it. It doesn't need to be filled or stroked, unless you want a white background rather than the default transparent one.

                2. Select all, and group.

                3. Then do the export-to-png on that group.

                 

                I checked, and indeed, it seems you cannot export a single page directly (nor a spread, for that matter).

                1 person found this helpful
                • 5. Re: Export PNG Error:
                  Marijan Tompa [tomaxxi] Level 4

                  Hey!

                   

                  Maybe this will help you, just change export format.

                   

                  if(app.selection.length > 1){
                      var myObj = app.activeWindow.activePage.groups.add(app.selection);
                      myObj.exportFile(ExportFormat.JPG, myFile, false);
                      app.activeDocument.undo();
                  }else{
                      app.selection[0].exportFile(ExportFormat.JPG, myFile, false);
                  }
                  

                   

                  Hope it helps.

                   

                  --

                  tomaxxi

                  http://indisnip.wordpress.com/

                  1 person found this helpful
                  • 6. Re: Export PNG Error:
                    Barqx Level 1

                    Thanks.

                     

                    I've already got that.

                     

                    However, I need to export to both JPG and PNG.

                    • 7. Re: Export PNG Error:
                      Barqx Level 1

                      Jongware,

                       

                      I tried the following code:

                       

                          try
                          {
                              var myObj = new Array();
                              myObj = app.activeDocument.spreads.item(1).pageItems;
                              var myGroup = app.activeDocument.spreads.item(1).groups.add(myObj);
                              myObj.exportFile(ExportFormat.PNG_FORMAT, File(filePath + '.png'));
                              myObj.ungroup();
                          }
                          catch(e)
                          {
                              alert(e);
                          }
                      

                       

                      However, I get the error:

                      ReferenceError: myObj.exportFile is not a function.

                      • 8. Re: Export PNG Error:
                        [Jongware] Most Valuable Participant

                        Correct. myObj is an instance of pageItems (plural), and you cannot export those. You probably meant this

                         

                        myGroup.exportFile(ExportFormat.PNG_FORMAT, File(filePath + '.png'));
                        myGroup.ungroup();
                        

                         

                        but you must keep in mind Javascript is not good at doing what you actually want to do, it only can do what you tell it to ...

                        • 9. Re: Export PNG Error:
                          Barqx Level 1

                          Silly mistake. Thanks for helping out - again!