Script Export PDF en serie.

Explorer ,
May 25, 2020

Copy link to clipboard

Copied

Bonjour,


J'aurai besoin d'un script pour exporter tous les documents ouvert en PDF celon un preset PDF défini.

Sur un autre post, on m'a donné ce script,

 

function saveAsPDF() {
    var allDocumentsLength = app.documents.length;
    for (var i = allDocumentsLength - 1; i >= 0; i--) {
        app.activeDocument = app.documents[i]; // Not necessary, only required whn you want to make document as active.
        var doc = app.documents[i];
        var pdfFile = new File(doc.path + "/" + doc.name.split('.')[0] + '.pdf');
        var pdfOptions = new PDFSaveOptions();
        pdfOptions.compatibility = PDFCompatibility.ACROBAT5;
        pdfOptions.generateThumbnails = true;
        pdfOptions.preserveEditability = false;
        pdfOptions.preset = "[Smallest File Size]";
        doc.saveAs(pdfFile, pdfOptions);
        doc.close(SaveOptions.DONOTSAVECHANGES);
    }
}

saveAsPDF();

 

mais que je change cette de cette ligne

 

"pdfOptions.preset = "[Smallest File Size]"; 

ou non avec  le preset que je souhaite, j'obtien un PDF de 182Mo contre un PDF de 4,6Mo 

 

Sur le même sujet, j'ai trouvé lui qui pourrais aller et ou je peux selectionner mon PRESET PDF, mais il ne fait qu'un doc a la fois.

// The active document  
var doc = app.activeDocument;  
// The path of the original document  
var originalDocPath = doc.path;  
// The name of the original document  
var originalDocName = doc.name;  
// An array of all the layers in the active document  
var allLayers = doc.layers;  
// Get just the file name. Ignore the file extension .pdf and .ai  
originalDocName = originalDocName.replace(/\.pdf|\.ai/gi, "")  
  
  
{
// Setup pdf save options  
var opts = new PDFSaveOptions();  
// Use the preset named "XXX"  
opts.pDFPreset = "your PDF preset name here";  
// Save the document in the original folder using the original name with _LR suffix  
doc.saveAs(File(originalDocPath + "/" + originalDocName + "_LR.pdf"), opts);  

app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

}

 

Sauriez vous ce que je dois faire ou modifier pour pouvoir changer le preset PDF ou modifier sur le 2nd script pour qu'ils tournent sur tous mes documents ? 

 

Merci d'avance.

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

I see that you have typo in your code, you have used preset property but it should be the following. Use this in your first code snippet and see how it works.

pdfOptions.pDFPreset = "[Smallest File Size]";

 

-Manan

TOPICS
Import and export, Scripting

Views

411

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Script Export PDF en serie.

Explorer ,
May 25, 2020

Copy link to clipboard

Copied

Bonjour,


J'aurai besoin d'un script pour exporter tous les documents ouvert en PDF celon un preset PDF défini.

Sur un autre post, on m'a donné ce script,

 

function saveAsPDF() {
    var allDocumentsLength = app.documents.length;
    for (var i = allDocumentsLength - 1; i >= 0; i--) {
        app.activeDocument = app.documents[i]; // Not necessary, only required whn you want to make document as active.
        var doc = app.documents[i];
        var pdfFile = new File(doc.path + "/" + doc.name.split('.')[0] + '.pdf');
        var pdfOptions = new PDFSaveOptions();
        pdfOptions.compatibility = PDFCompatibility.ACROBAT5;
        pdfOptions.generateThumbnails = true;
        pdfOptions.preserveEditability = false;
        pdfOptions.preset = "[Smallest File Size]";
        doc.saveAs(pdfFile, pdfOptions);
        doc.close(SaveOptions.DONOTSAVECHANGES);
    }
}

saveAsPDF();

 

mais que je change cette de cette ligne

 

"pdfOptions.preset = "[Smallest File Size]"; 

ou non avec  le preset que je souhaite, j'obtien un PDF de 182Mo contre un PDF de 4,6Mo 

 

Sur le même sujet, j'ai trouvé lui qui pourrais aller et ou je peux selectionner mon PRESET PDF, mais il ne fait qu'un doc a la fois.

// The active document  
var doc = app.activeDocument;  
// The path of the original document  
var originalDocPath = doc.path;  
// The name of the original document  
var originalDocName = doc.name;  
// An array of all the layers in the active document  
var allLayers = doc.layers;  
// Get just the file name. Ignore the file extension .pdf and .ai  
originalDocName = originalDocName.replace(/\.pdf|\.ai/gi, "")  
  
  
{
// Setup pdf save options  
var opts = new PDFSaveOptions();  
// Use the preset named "XXX"  
opts.pDFPreset = "your PDF preset name here";  
// Save the document in the original folder using the original name with _LR suffix  
doc.saveAs(File(originalDocPath + "/" + originalDocName + "_LR.pdf"), opts);  

app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

}

 

Sauriez vous ce que je dois faire ou modifier pour pouvoir changer le preset PDF ou modifier sur le 2nd script pour qu'ils tournent sur tous mes documents ? 

 

Merci d'avance.

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

I see that you have typo in your code, you have used preset property but it should be the following. Use this in your first code snippet and see how it works.

pdfOptions.pDFPreset = "[Smallest File Size]";

 

-Manan

TOPICS
Import and export, Scripting

Views

412

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
May 25, 2020 0
Adobe Community Professional ,
May 25, 2020

Copy link to clipboard

Copied

Hi,

 

Could you please explain what happens in your first code snippet, i think its fine it will export pdf using the pfd preset [Smallest File Size] for all the open documents. Does it not happen? How do you verify if its happening or not?

 

-Manan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 25, 2020 0
Explorer ,
May 25, 2020

Copy link to clipboard

Copied

Pour le premier code, je change 

"pdfOptions.preset = "[Smallest File Size]";  par "pdfOptions.preset = "2-LR"; qui est le nom de mon preset PDF et il me fait un PDF de 182MO contre 4,6 pour le même fichier fait a la main.
Pareil avec l'option d'export [Smallest File Size] 182Mo avec le script contre 776ko en le faisant a la main.

Mon PDF fait le même poids que si je l'exporte en PDF avec le preset par defaut.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 25, 2020 0
Adobe Community Professional ,
May 25, 2020

Copy link to clipboard

Copied

I see that you have typo in your code, you have used preset property but it should be the following. Use this in your first code snippet and see how it works.

pdfOptions.pDFPreset = "[Smallest File Size]";

 

-Manan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 25, 2020 0
Kyvarit LATEST
Explorer ,
May 25, 2020

Copy link to clipboard

Copied

C'est bon ! merci beaucoup !

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 25, 2020 0
Resources