10 Replies Latest reply on Dec 17, 2015 11:24 AM by runew73276507

    Help with a javascript - need the document name in filename when exporting

    runew73276507

      When I run this script:

       

      var myPresets = app.pdfExportPresets.everyItem().name;

      myPresets.unshift("- Select Preset -");

       

      var myWin = new Window('dialog', 'PDF Export Presets');

      myWin.orientation = 'row';

      with(myWin){

          myWin.sText = add('statictext', undefined, 'Select PDF Export preset:');

          myWin.myPDFExport = add('dropdownlist',undefined,undefined,{items:myPresets});

          myWin.myPDFExport.selection = 10;

          myWin.btnOK = add('button', undefined, 'OK');

          };

      myWin.center();

      var myWindow = myWin.show();

       

      if(myWindow == true && myWin.myPDFExport.selection.index != 0){

          var myPreset = app.pdfExportPresets.item(String(myWin.myPDFExport.selection));

          myFile = File(File.saveDialog("Save file with preset: " + myPreset.name,"PDF files: *.pdf"));

          if(myFile != null){

              app.activeDocument.exportFile(ExportFormat.PDF_TYPE, myFile, false, myPreset);

          }else{

              alert("No File selected");

          }

      }else{

          alert("No PDF Preset selected");

      }

       

      I need it to place the document filname automatically when the "Save as" dialog pops up:

      Udklip.PNG

      Can anyone help me?

        • 1. Re: Help with a javascript - need the document name in filename when exporting
          Peter Kahrel Adobe Community Professional & MVP

          Use this:

           

          myPath = app.activeDocument.filePath + '/' + app.activeDocument.name.replace (/\.indd$/, '.pdf');
          myFile = File(myPath).saveDlg("Save file with preset: " + myPreset.name,"PDF files: *.pdf");
          
          

           

          Peter

          • 2. Re: Help with a javascript - need the document name in filename when exporting
            runew73276507 Level 1

            Dear Peter,

             

            Thank you very much - it works perfectly!

             

            Can you maybe help me with two other things in the same javascript?

             

            1. If I want it to remember last chosen folder to export to - where and what to write for that?

            2. If I before the export a PDF javascript code inside the InDesign document want to A: Resize a frame to a specific size - for instance 240x340mm - and B: Fit the placed file inside the frame with the function: Fit content to frame - can you do a javascript code for that?

            • 3. Re: Help with a javascript - need the document name in filename when exporting
              Peter Kahrel Adobe Community Professional & MVP

              > 1. If I want it to remember last chosen folder to export to - where and what to write for that?

               

              Write the folder that's used for the export to a disk file. When you run the script, check if the file is present. If it is, read it and use the folder name stored on the file; if it isn't use either a default value (such as the InDesign document's folder) or nothing at all, which shows the disk's root (probably).

               

              > 2. If I before the export a PDF javascript code inside the InDesign document want to A: Resize a frame

              > to a specific size - for instance 240x340mm

               

              I don't really understand what you want here. Do you mean that you want to run a script before the export? Or do you want to store a script in the document?

               

              > B: Fit the placed file inside the frame with the function: Fit content to frame - can you do a javascript code for that?

               

              What is 'the placed file'?

               

              P.

              • 4. Re: Help with a javascript - need the document name in filename when exporting
                runew73276507 Level 1

                1. What I would like in the script is that a specific path on a server is chosen everytime i run the script - for instance \\filserver\data\output\

                Is it possible?

                 

                2. I use this code in the same script today:

                 

                if (app.selection.length != 0) {

                  for (n=0; n<app.selection.length; n++) {

                    app.selection[n].horizontalScale = app.selection[n].horizontalScale - 9.78;

                    app.selection[n].verticalScale = app.selection[n].verticalScale - 6.85;

                  }

                }

                 

                Instead I would like a specific size is made by the script - for instance 240x340 mm - and then fit the placed file - in this case a PDF file - to the framesize.

                 

                Is it possible?

                • 5. Re: Help with a javascript - need the document name in filename when exporting
                  Peter Kahrel Adobe Community Professional & MVP

                  1: You could use something like this (I suppose):

                   

                  myPath =  '//filserver/data/output/' + app.activeDocument.name.replace (/\.indd$/, '.pdf');


                  2: You could use geometricBounds, which is a 4-element array specifying top, left, bottom, right of a frame. (It's probably neater to use a transformation matrix but I can never remember the details.):


                  gb = app.selection[n].geometricBounds;

                  app.selection[n].geometricBounds = [gb[0], gb[1], gb[0]+340, [gb[1]+240];   // 340 tall, 240 wide

                  app.selection[n].fit (FitOptions.CONTENT_TO_FRAME);


                  P.

                  • 6. Re: Help with a javascript - need the document name in filename when exporting
                    runew73276507 Level 1

                    1. When paste that code into here:

                    if(myWindow == true && myWin.myPDFExport.selection.index != 0){

                        var myPreset = app.pdfExportPresets.item(String(myWin.myPDFExport.selection));

                      myPath =  '\\Polasaxoclustfs\SaxoGrafik\Side_Afsendelse_PDF' + app.activeDocument.name.replace (/\.indd$/, '.pdf');

                        myFile = File(myPath).saveDlg("Save file with preset: " + myPreset.name,"PDF files: *.pdf");

                        if(myFile != null){

                            app.activeDocument.exportFile(ExportFormat.PDF_TYPE, myFile, false, myPreset);

                     

                    I get this result, when I run the script:

                    Udklip.PNG

                     

                    2. how to put in the gb code in this code:

                    var myPresets = app.pdfExportPresets.everyItem().name;

                    myPresets.unshift("- Select Preset -");

                     

                    var myWin = new Window('dialog', 'PDF Export Presets');

                    myWin.orientation = 'row';

                    with(myWin){

                        myWin.sText = add('statictext', undefined, 'Select PDF Export preset:');

                        myWin.myPDFExport = add('dropdownlist',undefined,undefined,{items:myPresets});

                        myWin.myPDFExport.selection = 0;

                        myWin.btnOK = add('button', undefined, 'OK');

                        };

                    myWin.center();

                    var myWindow = myWin.show();

                     

                    if(myWindow == true && myWin.myPDFExport.selection.index != 0){

                        var myPreset = app.pdfExportPresets.item(String(myWin.myPDFExport.selection));

                      myPath =  '\\Polasaxoclustfs\SaxoGrafik\Side_Afsendelse_PDF' + app.activeDocument.name.replace (/\.indd$/, '.pdf');

                        myFile = File(myPath).saveDlg("Save file with preset: " + myPreset.name,"PDF files: *.pdf");

                        if(myFile != null){

                            app.activeDocument.exportFile(ExportFormat.PDF_TYPE, myFile, false, myPreset);

                        }else{

                            alert("No File selected");

                        }

                    }else{

                        alert("No PDF Preset selected");

                    }

                    • 7. Re: Help with a javascript - need the document name in filename when exporting
                      Peter Kahrel Adobe Community Professional & MVP

                      Escape your backslashes: '\\\\Polasaxoclustfs\\SaxoGrafik\\Side. . .'

                      • 8. Re: Help with a javascript - need the document name in filename when exporting
                        runew73276507 Level 1

                        1. then it just choose the same folder where the InDeisgn document is stored

                         

                        if(myWindow == true && myWin.myPDFExport.selection.index != 0){

                            var myPreset = app.pdfExportPresets.item(String(myWin.myPDFExport.selection));

                          myPath =  '\\\\Polasaxoclustfs\\SaxoGrafik\\Side_Afsendelse_PDF' + app.activeDocument.name.replace (/\.indd$/, '.pdf');

                            myFile = File(myPath).saveDlg("Save file with preset: " + myPreset.name,"PDF files: *.pdf");

                         

                        2. how to put in the gb code in this code:

                        var myPresets = app.pdfExportPresets.everyItem().name;

                        myPresets.unshift("- Select Preset -");

                         

                        var myWin = new Window('dialog', 'PDF Export Presets');

                        myWin.orientation = 'row';

                        with(myWin){

                            myWin.sText = add('statictext', undefined, 'Select PDF Export preset:');

                            myWin.myPDFExport = add('dropdownlist',undefined,undefined,{items:myPresets});

                            myWin.myPDFExport.selection = 0;

                            myWin.btnOK = add('button', undefined, 'OK');

                            };

                        myWin.center();

                        var myWindow = myWin.show();

                         

                        if(myWindow == true && myWin.myPDFExport.selection.index != 0){

                            var myPreset = app.pdfExportPresets.item(String(myWin.myPDFExport.selection));

                          myPath =  '\\Polasaxoclustfs\SaxoGrafik\Side_Afsendelse_PDF' + app.activeDocument.name.replace (/\.indd$/, '.pdf');

                            myFile = File(myPath).saveDlg("Save file with preset: " + myPreset.name,"PDF files: *.pdf");

                            if(myFile != null){

                                app.activeDocument.exportFile(ExportFormat.PDF_TYPE, myFile, false, myPreset);

                            }else{

                                alert("No File selected");

                            }

                        }else{

                            alert("No PDF Preset selected");

                        }

                        • 9. Re: Help with a javascript - need the document name in filename when exporting
                          Peter Kahrel Adobe Community Professional & MVP

                          1. You forgot the slashes between the path and the document name:

                           

                          myPath =  '\\\\Polasaxoclustfs\\SaxoGrafik\\Side_Afsendelse_PDF\\' + app.activeDocument.name.replace (/\.indd$/, '.pdf');

                           

                          2. I don't know. Lots of questions. Looks like a drastic addition, time to hire someone.

                           

                          P.

                          • 10. Re: Help with a javascript - need the document name in filename when exporting
                            runew73276507 Level 1

                            1. Yes of course - it works perfectly now!

                             

                            2. Fair enough - I am rookie but just very interested in Javascript to InDesign - thank you very much for your time Peter - I am really gratefull.

                             

                            Have a nice christmas!