16 Replies Latest reply on Nov 11, 2009 8:46 AM by tommy_boy56

    PDF security

    MikeBrog

      Is it possible to script the security options for PDF export?  JavaScript, InDesign CS2.  Thanks.

        • 1. Re: PDF security
          [Jongware] Most Valuable Participant

          I'd say "yes it can".

          The CS3 help lists changeSecurityPassword, disallowChanging, disallowCopying, disallowDocumentAssembly, disallowExtractionForAccessibility, disallowFormFillIn, disallowHiResPrinting, disallowNotes, disallowPlaintextMetadata, disallowPrinting, and openDocumentPassword, as well as useSecurity -- all under PDFExportPreferences. I think this is the same under CS2.

           

          The CS2 Javascript guide shows how to set PDF export preferences; admittedly, it does state "security options are not set". Left as an exercise for the reader, I guess.

          • 2. Re: PDF security
            MikeBrog Level 1

             

            Thanks for the reply.  I was able to find what I needed based on the info you supplied.  This is what I put together.  It's basically a proofing system for advertisements.

             

            It applies a watermark file to the current document and then exports the document as a PDF with security settings applied.  I thought I would post the code here because I was unable to find a watermarking process that was automated and because I thought I might get feedback to improve what I have.

             

            Thanks again.

             

             

            CurrentDoc = app.activeDocument;

            CurrentPage = app.activeWindow.activePage.name;

            myFile = "VOLX:_DNK1:PROOFWATERMARK2.pdf";

             

            var insertedImages = CurrentDoc.pages.item(CurrentPage).place(myFile);

            var myGraphic = CurrentDoc.allGraphics[0];

             

            myGraphic.parent.geometricBounds = ["0p","0p",CurrentDoc.documentPreferences.pageHeight,CurrentDoc.documentPreferences.pageW idth]

            myGraphic.fit(FitOptions.proportionally)

            myGraphic.fit(FitOptions.CENTER_CONTENT)

            myGraphic.opacity = 30

             

            with(app.pdfExportPreferences){

            cropMarks = false;

            registrationMarks = false;

            acrobatCompatibility = AcrobatCompatibility.acrobat5;

            colorBitmapCompression = BitmapCompression.autoCompression;

            colorBitmapQuality = CompressionQuality.low;

            colorBitmapSampling = Sampling.bicubicDownsample;

            colorBitmapSamplingDPI = 100;

            compressionType = PDFCompressionType.compressObjects;

            compressTextAndLineArt = true;

            cropImagesToFrames = true;

            grayscaleBitmapCompression = BitmapCompression.autoCompression;

            grayscaleBitmapquality = CompressionQuality.low;

            grayscaleBitmapSampling = Sampling.bicubicDownsample;

            grayscaleBitmapSamplingDPI = 100;

            monochromeBitmapCompression = MonoBitmapCompression.ccit4;

            monochromeBitmapSampling = Sampling.bicubicDownsample;

            monchromeBitmapSamplingDPI = 300;

            optimizePDF = true;

            subsetFontsBelow = 100;

            useSecurity = true;

            viewPDF = true;

            disallowPrinting = false;

            disallowCopying = true;

            disallowChanging = true;

            changeSecurityPassword = "XXXXXX"

            }

             

            var myPageName, myFilePath, myFile;

            var myDocument = app.activeDocument;

            var myDocumentName = myDocument.name;

            var myRegExp = new RegExp(":","gi");

            var myRegExp2 = new RegExp(".indd","gi");

             

            myPageName = myDocument.name

            myPageName = myPageName.replace(myRegExp, "_");

            myBaseName = myPageName.replace(myRegExp2, "");

            myFilePath = "VOL1:Test PDF Ads:_LOW RES PROOF - WATERMARK:" + myBaseName + ".pdf";

            myFile = new File(myFilePath);

             

            CurrentDoc.exportFile(ExportFormat.pdfType, myFile, false)

             

             

            • 3. Re: PDF security
              tommy_boy56

              Hello Mike,

               

              I am very, very new to scripting. I was reading your post and I have the same problem you have. I need a pdf setting that would export a file with the security settings already applied. Is there any way I could modify your script to make it work for me, if not, can you let me know where you found the "PDFExportPreferences"

               

              Thanks Again, any help you can give would be appreciated.

               

              Tom

              • 4. Re: PDF security
                MikeBrog Level 1

                I found the options for PDFExportPreferences here:

                http://wwwimages.adobe.com/www.adobe.com/products/indesign/scripting/pdfs/InDesignCS3_Scri ptingGuide_JS.pdf

                 

                I think all you need is this part to export the document as a secure PDF:

                 

                with(app.pdfExportPreferences){

                cropMarks = false;

                registrationMarks = false;

                acrobatCompatibility = AcrobatCompatibility.acrobat5;

                colorBitmapCompression = BitmapCompression.autoCompression;

                colorBitmapQuality = CompressionQuality.low;

                colorBitmapSampling = Sampling.bicubicDownsample;

                colorBitmapSamplingDPI = 100;

                compressionType = PDFCompressionType.compressObjects;

                compressTextAndLineArt = true;

                cropImagesToFrames = true;

                grayscaleBitmapCompression = BitmapCompression.autoCompression;

                grayscaleBitmapquality = CompressionQuality.low;

                grayscaleBitmapSampling = Sampling.bicubicDownsample;

                grayscaleBitmapSamplingDPI = 100;

                monochromeBitmapCompression = MonoBitmapCompression.ccit4;

                monochromeBitmapSampling = Sampling.bicubicDownsample;

                monchromeBitmapSamplingDPI = 300;

                optimizePDF = true;

                subsetFontsBelow = 100;

                useSecurity = true;

                viewPDF = true;

                disallowPrinting = false;

                disallowCopying = true;

                disallowChanging = true;

                changeSecurityPassword = "XXXXXX"

                }

                 

                var myPageName, myFilePath, myFile;

                var myDocument = app.activeDocument;

                var myDocumentName = myDocument.name;

                var myRegExp = new RegExp(":","gi");

                var myRegExp2 = new RegExp(".indd","gi");

                 

                myPageName = myDocument.name

                myPageName = myPageName.replace(myRegExp, "_");

                myBaseName = myPageName.replace(myRegExp2, "");

                myFilePath = "VOL1:Test PDF Ads:_LOW RES PROOF - WATERMARK:" + myBaseName + ".pdf";

                myFile = new File(myFilePath);

                 

                CurrentDoc.exportFile(ExportFormat.pdfType, myFile, false)

                • 5. Re: PDF security
                  MikeBrog Level 1

                  The link I sent in the previous post was incorrect.  I will try to get the correct one tomorrow.  The correct PDF is over 1200 pages, I think.

                  • 6. Re: PDF security
                    MikeBrog Level 1

                    Here is the URL to the InDesign_CS2_Scripting_Reference.pdf:

                    http://www.adobe.com/products/indesign/pdfs/InDesign_Scripting_Reference.pdf

                     

                    For CS3, you can check the Adobe ExtendScript Toolkit 2 > Help > Adobe InDesign CS3 Object Model.

                    • 7. Re: PDF security
                      tommy_boy56 Level 1

                      Thanks for your help Mike. This is what I have so far. The only problem I am having is, where the file is being saved, I can not locate the file after I save it. Is there any way to write in a line of code that will save the pdf to the desktop or another specific location. I tried to manipulate the "myFilePath" line but all that did was add the text to the file name.

                       

                      Tom

                       

                      CurrentDoc = app.activeDocument;

                       

                      with(app.pdfExportPreferences){

                      cropMarks = false;

                      registrationMarks = false;

                      acrobatCompatibility = AcrobatCompatibility.acrobat5;

                      colorBitmapCompression = BitmapCompression.autoCompression;

                      colorBitmapQuality = CompressionQuality.low;

                      colorBitmapSampling = Sampling.bicubicDownsample;

                      colorBitmapSamplingDPI = 100;

                      compressionType = PDFCompressionType.compressObjects;

                      compressTextAndLineArt = true;

                      cropImagesToFrames = true;

                      grayscaleBitmapCompression = BitmapCompression.autoCompression;

                      grayscaleBitmapquality = CompressionQuality.low;

                      grayscaleBitmapSampling = Sampling.bicubicDownsample;

                      grayscaleBitmapSamplingDPI = 100;

                      monochromeBitmapCompression = MonoBitmapCompression.ccit4;

                      monochromeBitmapSampling = Sampling.bicubicDownsample;

                      monchromeBitmapSamplingDPI = 300;

                      optimizePDF = true;

                      subsetFontsBelow = 100;

                      useSecurity = true;

                      viewPDF = true;

                      disallowPrinting = false;

                      disallowCopying = true;

                      disallowChanging = true;

                      changeSecurityPassword = "XXXXXX"

                      }

                       

                      var myPageName, myFilePath, myFile;

                      var myDocument = app.activeDocument;

                      var myDocumentName = myDocument.name;

                      var myRegExp = new RegExp(":","gi");

                      var myRegExp2 = new RegExp(".indd","gi");

                       

                      myPageName = myDocument.name

                      myPageName = myPageName.replace(myRegExp, "_");

                      myBaseName = myPageName.replace(myRegExp2, "");

                      myFilePath = "wesite" + myBaseName + ".pdf";

                      myFile = new File(myFilePath);

                       

                      CurrentDoc.exportFile(ExportFormat.pdfType, myFile, false)

                      • 8. Re: PDF security
                        MikeBrog Level 1

                        Try making the myFilePath a full path.

                         

                        It would be similar to this for a Mac where VOL1 is a server share:

                        myFilePath = "VOL1:Test PDF Ads:_LOW RES PROOF - WATERMARK:" + myBaseName + ".pdf";

                         

                        Windows would be more like this (I have not tested this format):

                        myFilePath = "\\server1\\Test PDF Ads\\_LOW RES PROOF - WATERMARK\\" + myBaseName + ".pdf";

                         

                        Or like this for a mapped network drive or your C: drive:

                        myFilePath = "C:\\Test PDF Ads\\_LOW RES PROOF - WATERMARK\\" + myBaseName + ".pdf";

                        • 9. Re: PDF security
                          tommy_boy56 Level 1

                          To let you know, I am on a MAC. and I need the path to be fairly generic because there maybe as many as 5-7 people using this script. I tried the following:

                           

                          myPageName = myDocument.name

                          myPageName = myPageName.replace(myRegExp, "_");

                          myBaseName = myPageName.replace(myRegExp2, "");

                          myFilePath = "G5:desktop:wesite" + myBaseName + ".pdf"; (I want to place the file in a folder named "website" on my desktop)

                          myFile = new File(myFilePath);

                           

                           

                          But the file is getting placed in a file I can not access:

                           

                          applications

                               -adobe Indd CS2

                                    -adobe Indd CS2 app (once I click on this icon InDesign is launched)

                                         -contents

                                              -MacsOS

                          • 10. Re: PDF security
                            Kasyan Servetsky Level 5

                            I want to place the file in a folder named "website" on my desktop

                            var myFile = new File("~/Desktop/website/" +  myBaseName + ".pdf");

                            • 11. Re: PDF security
                              MikeBrog Level 1

                              "G5:desktop:wesite" doesn't sound like a valid path.

                               

                              The desktop folder is buried in the system and each user has a separate desktop.  Try opening your hard drive and creating a folder on its root and then point to this folder.

                               

                              You can then create an alias to this folder on all of the desktops.

                              • 12. Re: PDF security
                                MikeBrog Level 1

                                Looks like this will work with any user?

                                • 13. Re: PDF security
                                  Kasyan Servetsky Level 5

                                  Looks like this will work with any user?

                                  Yes, it will.

                                  • 14. Re: PDF security
                                    MikeBrog Level 1

                                    Nice!

                                    • 15. Re: PDF security
                                      tommy_boy56 Level 1

                                      Kasyan, thanks for your reply. However, since I am new to scripting I have a question, where do I place this new script or am I replacing

                                       

                                       

                                      "myFilePath = "G5:desktop:wesite" + myBaseName + ".pdf"; "

                                       

                                      with

                                       

                                      "var myFile = new File("~/Desktop/website/" +  myBaseName + ".pdf");"

                                       

                                      Thanks Again Tom

                                      • 16. Re: PDF security
                                        Kasyan Servetsky Level 5

                                        You can replace these two lines

                                        myFilePath = "G5:desktop:wesite" + myBaseName + ".pdf"; (I want to place the file in a folder named "website" on my desktop)

                                        myFile = new File(myFilePath);

                                        with mine.

                                         

                                        I also recommend you to check if wesite folder exists on the desktop. Something like this:

                                        var myFolder = new Folder("~/Desktop/website/");
                                        if (!myFolder.exist) {
                                            if (confirm("\"Website\" doesn't exist on your desktop. Do you want to create it?", false, "Folder is missing")) {
                                                myFolder.create();
                                            }
                                            else {
                                                exit(); // if user clicks NO, exit silently
                                            }
                                        }