Copy link to clipboard
Copied
I already have a script that i give to my fellow designers that in part creates both a high res PDF and a low res PDF. both open a dialog where the design can spec how they prefer the PDF to be made. At the last meeting, the "powers that be" decided to make all the low resolution PDFs be uniform AND include security features to lock down the low res PDF from alteration. Security features cannot be saved in a preset so i cannot go down the route of creating a preset and having the script assign that preset to the PDF. I found a list of PDFExportPreference but am unsure how to use this information.
scott
2 Correct answers
Here's a sample code using useSecurity and changeSecurityPassword. You also need to set the restrictions for printing, copying and changing. Be sure to change any preferences back at the end.
var currPrefs = app.pdfExportPreferences;
with (currPrefs) {
useSecurity = true;
changeSecurityPassword = "myPassword";
acrobatCompatibility = AcrobatCompatibility.ACROBAT_7;
viewPDF = true;
pageRange = PageRange.ALL_PAGES;
disallowPrinting = false;
disallowCopying = true;
d
...
Hi,
just two small changes to make that work:
1. Use the preset itself that is stored in variable pdfExportPreset.
And not its name that is stored in variable pdfExportPresetName.
2. Use the preset as the fourth argument in method exportFile(). Currently its the fifth argument.
DOM documentation to your rescue:
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Document.html#d1e49241__d1e53606
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Copy link to clipboard
Copied
you are correct, it is not possible to have a PRESET include security.
so i am looking for a script that will export a "generic" low rsolution pdf which will include security.
I see that the option to changeSecurityPassword and useSecurity are both available in PDFExportPreferences but i do not know enough about scripting to use this information. I am good enough to alter an existing script but not sure how to get started because i cannot find any scripts that are using PDFExportPreferences to start from
These low res PDFs are place into our online catalog of available printed pieces.
the problem is idiots were taking these low res pdfs and altering them.
I know it is not great security but at least it makes it more difficult.
Copy link to clipboard
Copied
Scott,
you can add the PDFExportPreferences useSecurity property to your script like this...
app.pdfExportPreferences.useSecurity = true;
I added it to one of my existing scripts to see what it would do on export, see below on what the the Document Properties show without and with useSecurity.
without:
with:
Either way it appears that you'll have to go into the Document Properties of the exported pdf and manaully set\change the Security settings to your preferences.
Regards,
Mike
Copy link to clipboard
Copied
Scott,
Disregard......
"Either way it appears that you'll have to go into the Document Properties of the exported pdf and manaully set\change the Security settings to your preferences."
you can apply each of the Security settings like Brian is showing below.....
Regards
Mike
Copy link to clipboard
Copied
Here's a sample code using useSecurity and changeSecurityPassword. You also need to set the restrictions for printing, copying and changing. Be sure to change any preferences back at the end.
var currPrefs = app.pdfExportPreferences;
with (currPrefs) {
useSecurity = true;
changeSecurityPassword = "myPassword";
acrobatCompatibility = AcrobatCompatibility.ACROBAT_7;
viewPDF = true;
pageRange = PageRange.ALL_PAGES;
disallowPrinting = false;
disallowCopying = true;
disallowChanging = true;
}
var doc = app.activeDocument;
doc.exportFile(ExportFormat.PDF_TYPE, File("~/Desktop/testsec1.pdf"), false);
currPrefs.useSecurity = false;
Copy link to clipboard
Copied
thank you that was exactly the kickstart i needed....
YOU ARE THE BEST!!!!
scott
Copy link to clipboard
Copied
Hi Brian,
I would reset all other values as well after the export is done.
Note: There is a properties property of app.pdfExportPreferences you could use.
Also missing:
1. A check if the pdf file exists before trying to export.
2. A try/catch around exportFile() to get a known exception if the PDF file cannot be written.
Main causes:
PDF file with the same name is already open.
Folder to save the file has not the rights to write a file to.
File name is too long to write a file to the folder.
( There may be others as well. )
3. A defined PDF Preset as fourth argument in exportFile().
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
I already am aware and will take care of #1 and #2 but could you explain #3 a bit more?
scott
Copy link to clipboard
Copied
You can set a preset for the export as the fourth argument in exportFile:
var preset = app.pdfExportPresets.itemByName("mypreset");
doc.exportFile(ExportFormat.PDF_TYPE, File("~/Desktop/testsec1.pdf"), false, preset);
Copy link to clipboard
Copied
Hi Scott,
exportFile() takes a lot of arguments.
Details here:
http://jongware.mit.edu/idcs6js/pc_Document.html#exportFile
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Document.html#d1e49521__d1e53922
The fourth argument is using : PDFExportPreset
So I think you could use a pre-defined PDFExportPreset for your lowres PDFs.
No need to define all necessary property/value pairs of your PDF Export with app.pdfExportPreferences.
Just do the security settings there. All other should come from a saved PDFExportPreset , a installed *.joboptions file.
Some code to illustrate this:
( function()
{
// Here goes the password:
var passWord = "myPassword";
// Here one have to set the PDF Export Preset name:
var pdfExportPresetName = "yourPDF-Preset-Name";
// No document open? Do nothing:
if( app.documents.length == 0 ){ return };
var doc = app.activeDocument;
// If the active document was never saved, do nothing:
if( !doc.saved )
{ alert( "ERROR: Save your INDD-Document before running this script! | SCRIPT "); return };
// Check, if the preset is available:
var pdfExportPreset = app.pdfExportPresets.itemByName( pdfExportPresetName );
// Preset is not available, do nothing:
if( !pdfExportPreset.isValid ){ alert( "ERROR: No pdfExportPreset found. | SCRIPT"); return };
/*
AND MORE CODE TO EXPORT TO PDF
*/
}() )
Regards,
Uwe Laubender
( Adobe Community Expert )
EDITED LINK
Copy link to clipboard
Copied
will the security still be applied even though in the end you are now using a preset? I assumed that the preset would undo the security requests
Copy link to clipboard
Copied
Hi Scott,
that depends on what property/value pairs a PDF Preset can define.
Look into DOM documentation again, this time in the most current one perhaps:
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#PDFExportPreset.html
Can you see property useSecurity for object PDFExportPreset? I do not.
So, I think a PDFExportPreset can go along very well with changed app.pdfExportPreferences.
Just do a test, come back and let us know how it went 🙂
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Unfortunately i am not getting it to work....
i have some of the error checking you mentioned earlier in the script and am attaching just the relevant section...
this is what i tried, a combination of the two answers so far and it is working...
except I cannot control the preset that is used.
It always uses the most recent PDF preset on export even though i am asking it to use "smallest size_spreads"
Copy link to clipboard
Copied
Hi,
just two small changes to make that work:
1. Use the preset itself that is stored in variable pdfExportPreset.
And not its name that is stored in variable pdfExportPresetName.
2. Use the preset as the fourth argument in method exportFile(). Currently its the fifth argument.
DOM documentation to your rescue:
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Document.html#d1e49241__d1e53606
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
thank you for helping me out with this project....you make me look like a rockstar!!!!!
scott
Copy link to clipboard
Copied
for the preset "Smallest file size_spreads" the only change to the adobe supplied [smallest File Size] preset i made is to create the PDF as spreads
because "exportReaderSpreads"is a property for object PDFExportPreset i cannot add exportReaderSpreads=true;
up in my list of preferences because it will be overridden by the info in [Smallest File Size]
is this correct?
i would like to write this using the factory supplied [Smallest File Size] if possible to avoid having all my designers install or create a PDF preset in addition to the script
scott
Copy link to clipboard
Copied
Hi Scott,
you could add a throw-away pdfExportPreset, apply a true to property exportReaderSpreads and after the export is done remove it. Look into the method duplicate() for pdfExportPreset for that.
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#PDFExportPreset.html#d1e325649__d1e326872
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Hi Scott,
if you are testing my suggestion with the throw-away duplicate of a pdfExportPreset:
WARNING
Do not test the script code with the ESTK ( ExtendScript Toolkit ).
The ESTK will throw an error:
With my German version: Die angeforderte Aktion konnte nicht ausgeführt werden, da das Objekt nicht mehr existiert.
( $ID/ObjectDeletedError )
Where?
var dupPreset = pdfExportPreset.duplicate();
// THAT THROWS ERROR:
dupPreset.exportReaderSpreads = true ;
It is as if the duplicate of the preset does not exist anymore.
WORKAROUND
Run the same script code from InDesign's Scripts Panel and no error will be thrown.
The PDF can be exported using the changed duplicate. In the above case as exported spreads.
Just tested this with InDesign 2020 on Windows 10.
Also tested it a year ago with InDesign CC-2019.
This is a longstanding bug!
The following thread in the OLD InDesign Scripting Forum gave me the hint:
Duplicate pdfExportPreset
enbanat May 27, 2013 6:24 PM
NEW LINK:
https://community.adobe.com/t5/indesign/duplicate-pdfexportpreset/td-p/5155495
OLD LINK:
https://forums.adobe.com/message/5355641#5355641
Sorry! Unfortunately this thread was not moved to the current InDesign Forum last year.
What a shame!
EDITED: January 22, 2020
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
i'm afraid that you are now over my head. this is what i tried and it does not create spreads using the [Smallest FileSize] adobe supplied preset. I am sure i just bungled everything because i do not understand
Copy link to clipboard
Copied
Hi Scott,
I suggested to duplicate a pdfExportPreset.
I did not suggest to work with a presets properties property.
Do not do this:
var dupPreset = app.pdfExportPresets.item('[Smallest File Size]').properties;
But this:
var dupPreset = app.pdfExportPresets.itemByName('[Smallest File Size]').duplicate();
Only now the preset is duplicated.
Then change the duplicated preset's value for property exportReaderSpreads to true ( false is default ) :
dupPreset.exportReaderSpreads = true ;
And use the duplicated and changed preset to export the document to PDF.
Do not use a name! A preset is required as 4th argument:
var doc = app.activeDocument;
doc.exportFile
(
ExportFormat.PDF_TYPE,
File(pdfFullName),
false,
dupPreset
);
Finally throw the duplicated preset away:
dupPreset.remove();
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
I think that worked!!!!!
here is what i ended up with:
//----------------------------------______LOW____--------------------------------------
//--------------------------pdf security export---------------------------------------------
if(app.documents.length>0){
var d=app.activeDocument;
};
else{
alert(“Please open a document to execute export to pdf. Script will be aborted.”);
exit();
}
if(d.saved == false){
alert(“Save your document first before executing export to pdf. Script will be aborted.”);
exit();
};
//----------------------------------------------
var dupPreset = app.pdfExportPresets.itemByName(‘[Smallest File Size]’).duplicate();
dupPreset.exportReaderSpreads = true;
var currPrefs = app.pdfExportPreferences;
with (currPrefs) {
useSecurity = true;
changeSecurityPassword = “Password”;
acrobatCompatibility = AcrobatCompatibility.ACROBAT_7;
viewPDF = true;
pageRange = PageRange.ALL_PAGES;
disallowPrinting = false;
disallowCopying = true;
disallowChanging = true;
}
var pdfPath = Folder.selectDialog(“Folder to save the LOW res pdf:”);
var pdfName = d.name.substring(0, d.name.indexOf(“.”))+”_lr.pdf”;
var userDefFileName = prompt(“File name:”,pdfName,undefined);
if(userDefFileName == null){
exit();
};
var pdfFullName = pdfPath+”/”+userDefFileName;
if(File(pdfFullName).exists){
c=confirm(“The PDF-file \””+userDefFileName+”\” is already existing. Do you want to overwrite it?”,true,undefined);
if (c==0){exit()};
};
var doc = app.activeDocument;
doc.exportFile
(
ExportFormat.PDF_TYPE,
File(pdfFullName),
false,
dupPreset
);
currPrefs.useSecurity = false;
dupPreset.remove();

