9 Replies Latest reply on Aug 23, 2016 2:33 PM by toddshirbert

    save pdf in the same location as the orginal .indd file it was exported from

    Awitmer Level 1

      Hello!

       

      I am just starting to get my feet wet in Javascript scripting, and I am greatly enjoying it!

       

      I am wanting to create a script that exports a pdf using a pdf export preset I have defined and then I want to have the pdf saved in the same folder as the indesign file that it was exported from. I already know how to export the pdf using a preset that I already have. The only thing I don't know how to do is to specify that the pdf be saved in the same folder as the Indesign file that it was exported from. Can someone please help me out? I would greatly appreciate it!

       

      I would also like to find a way to name automatically have the pdf be named the same name as the Indesign file it was exported from.

       

      If I need to clarify something further, feel free to let me know.

       

      Thanks a lot!

        • 1. Re: save pdf in the same location as the orginal .indd file it was exported from
          vinothr Level 3

          For pdf file path:

          var pdfPath = doc.filePath;
          

           

          For pdf file name:

           

          Option 1:

          var docName = doc.name;
          var pdfName = docName.substring(0, docName.lastIndexOf(".")) + "pdf";
          

           

          Option 2:

          var docName = doc.name;
          var pdfName = docName.replace(".indd", ".pdf");
          

           

          Finally,

          var pdfFilePath = pdfPath + "/" + pdfName;
          

           

           

          NOTE: In case your document is not ever saved (untitled document) then the file path is meaningless.

          So you should do above only if doc.saved returns true

           

          If it returns false, then you should have a default file path and file name.

          1 person found this helpful
          • 2. Re: save pdf in the same location as the orginal .indd file it was exported from
            karthiks94217840 Level 2

            Try this sample code

             

            app.scriptPreferences.version = 11.0 

            var myDocument = app.activeDocument; 

            var myFileName; 

            if (myDocument.modified == false) { 

                myFileName = myDocument.fullName + ""; 

                if (myFileName.indexOf(".indd") != -1) { 

                    var myRegularExpression = /.indd/gi; 

                    myFileNamePDF_Web = myFileName.replace(myRegularExpression, ".pdf"); 

                } 

                with(app.pdfExportPreferences) { 

                    PDFJPEGQualityOptions.HIGH; 

                    PdfMagnificationOptions.FIT_PAGE; 

                    PageLayoutOptions.SINGLE_PAGE; 

                    colorBitmapCompression = BitmapCompression.zip; 

                    colorBitmapQuality = CompressionQuality.eightBit; 

                    colorBitmapSampling = Sampling.BICUBIC_DOWNSAMPLE; 

                    colorBitmapSamplingDPI = 300; 

                } 

                myDocument.exportFile(ExportFormat.pdfType, new File(myFileNamePDF_Web)); 

            } else { 

                alert("Save your file before continuing"); 

             

             

            Thanks

            • 3. Re: save pdf in the same location as the orginal .indd file it was exported from
              Awitmer Level 1

              Thank you all very much for your help! This is very helpful!! I really appreciate it!

              • 4. Re: save pdf in the same location as the orginal .indd file it was exported from
                Awitmer Level 1

                I am trying to use the PDFExportPreset option but it always generates and error at line 11. Here is the error code I am getting: "Invalid value for parameter 'using' of method 'exportFile'. Expected PDFExportPreset, but recieved nothing. Could you please help me see what I am doing wrong?

                 

                See the code I am using below.

                 

                app.scriptPreferences.version = 11.0

                var myDocument = app.activeDocument;

                var myFileName;

                var myPDFExportPreset = app.pdfExportPresets.item("Press Quality");

                if (myDocument.modified == false) {

                    myFileName = myDocument.fullName + "";

                    if (myFileName.indexOf(".indd") != -1) {

                        var myRegularExpression = /.indd/gi;

                        myFileName = myFileName.replace(myRegularExpression, ".pdf");

                    }

                    myDocument.exportFile(ExportFormat.pdfType, new File(myFileName), true, myPDFExportPreset);

                } else {

                    alert("Save your file before continuing");

                }

                 

                 

                Thanks in advance for your help!

                • 5. Re: save pdf in the same location as the orginal .indd file it was exported from
                  s.vnesh Level 1

                  Change the present name with in square brackets (eg. []) as below and try.

                  var myPDFExportPreset = app.pdfExportPresets.item("[Press Quality]");

                   

                  • 6. Re: save pdf in the same location as the orginal .indd file it was exported from
                    Laubender Adobe Community Professional & MVP

                    Since "[Press Quality]" is a localized name—in my German version of InDesign it is called "[Druckausgabequalität]"—we could also use the fifth item of app.pdfExportPresets.

                     

                    var myPDFExportPreset = app.pdfExportPresets[4];
                    

                     

                    Note: it's not unlikely, that the order or even the names of PDF export presets would change with upcoming versions of InDesign.

                     

                    Before we could check, if the fifth PDF export preset is really the required one.

                    Maybe something went wrong with the installation. I had this recently at a customer's site with some installations of InDesign CS6 on Windows where the basic PDF/X-4 export setting "[PDF/X-4:2008]" was missing in InDesign due to a glitch in the installation of Acrobat Pro on the same machines.

                     

                    Or we have to add a new PDF export preset temporarily (removed after usage) with all required properties from scratch.

                     

                    I ran the following snippet to get the names of the first 6 installed standard PDF export presets, that should be installed with every InDesign CS5 and above, just to show, that names could differ on various localized installations:

                     

                    var pdfExportPresetsArray = app.pdfExportPresets.everyItem().getElements();
                    for(var n=0;n<6;n++)
                    {
                         $.writeln(n+"\t"+pdfExportPresetsArray[n].name);
                    }
                    
                    /*
                    
                    Results from my German InDesign CS6 v8.1.0:
                    
                    0    [Qualitativ hochwertiger Druck]
                    1    [PDF/X-1a:2001]
                    2    [PDF/X-3:2002]
                    3    [PDF/X-4:2008]
                    4    [Druckausgabequalität]
                    5    [Kleinste Dateigröße]
                         
                    */
                    

                     

                    What is also important to know here, that the order in the array I created did not reflect the order in the UI of my InDesign CS6 installation.

                     

                    OrderOfStandardPDFExportPresets.png

                     

                     

                    Regards,
                    Uwe

                    • 7. Re: save pdf in the same location as the orginal .indd file it was exported from
                      Awitmer Level 1

                      Thanks a lot! Putting the pdf export name in brackets did the trick.

                      • 8. Re: save pdf in the same location as the orginal .indd file it was exported from
                        Laubender Adobe Community Professional & MVP

                        Also be aware, that the used regular expression could not do any harm to your file names.

                         

                        /.indd/gi

                         

                        may find too much.

                        The dot is denoting any character, not only the dot.

                        And the substring "indd" could be found anywhere in the file name.

                         

                        So escape the dot to find a dot only and add a $ to the end of the string. That would ensure, that the substring is only found at the end of the file name.

                         

                        Test the following to see the difference:

                         

                        var string = "MyINDD-Document.indd";
                        var regExp1 = /.indd/gi ;
                        var regExp2 = /\.indd$/i ;
                        
                        alert(string.replace(regExp1,".pdf"));
                        alert(string.replace(regExp2,".pdf"));
                        

                         

                        Regards,
                        Uwe

                        • 9. Re: save pdf in the same location as the orginal .indd file it was exported from
                          toddshirbert

                          No errors, but this doesn't appear to select the specified preset. It just selects whatever the last used preset was.