Skip to main content
Claire_Chr
Participating Frequently
Jan 9, 2024 9:16 AM UTC
Answered

Javascript pour exporter en pdf les variantes de mise en page

Bonjour à tous,

 

Je souhaiterai exporter l'ensemble de mes variantes de mise en page d'un meme fichier dans des pdfs distinct. Est ce que quelqu'un saurait comment faire s'il vous plait ? Je ne trouve aucune formulation qui fonctionne.

 

Cordialement,

Claire.

 

rob day
rob dayCorrect answer
Community Expert
Jan 9, 2024 11:38 AM UTC

Hi @Claire_Chr , With JS you can get the document’s alternate layer names via sections, so something like this might work—the dialog asks you to select a PDF preset then exports each layout as an alternate layout page range to your document’s parent folder:

 

makeDialog();
var pp;
function makeDialog(){
    var theDialog = app.dialogs.add({name:"Choose a Preset", canCancel:true});
    with(theDialog.dialogColumns.add()){
        pp = dropdowns.add({stringList:app.pdfExportPresets.everyItem().name, selectedIndex:3, minWidth:80});
    }
    if(theDialog.show() == true){
        pp = app.pdfExportPresets.item(pp.selectedIndex);
        exportLayouts();
        theDialog.destroy();
	}
}


function exportLayouts(){
	var doc = app.activeDocument
	//gets an array of alternate layout names
	var pr = doc.sections.everyItem().alternateLayout;
	for (var i = 0; i < pr.length; i++){
		app.pdfExportPreferences.properties = {pageRange:pr[i], viewPDF:false }
		doc.exportFile(ExportFormat.pdfType, File(doc.filePath + "/" + pr[i] + ".pdf"), false, pp);
	};
}

2 replies

rob day
Community Expert
rob dayCommunity ExpertCorrect answer
Community Expert
Jan 9, 2024 11:38 AM UTC

Hi @Claire_Chr , With JS you can get the document’s alternate layer names via sections, so something like this might work—the dialog asks you to select a PDF preset then exports each layout as an alternate layout page range to your document’s parent folder:

 

makeDialog();
var pp;
function makeDialog(){
    var theDialog = app.dialogs.add({name:"Choose a Preset", canCancel:true});
    with(theDialog.dialogColumns.add()){
        pp = dropdowns.add({stringList:app.pdfExportPresets.everyItem().name, selectedIndex:3, minWidth:80});
    }
    if(theDialog.show() == true){
        pp = app.pdfExportPresets.item(pp.selectedIndex);
        exportLayouts();
        theDialog.destroy();
	}
}


function exportLayouts(){
	var doc = app.activeDocument
	//gets an array of alternate layout names
	var pr = doc.sections.everyItem().alternateLayout;
	for (var i = 0; i < pr.length; i++){
		app.pdfExportPreferences.properties = {pageRange:pr[i], viewPDF:false }
		doc.exportFile(ExportFormat.pdfType, File(doc.filePath + "/" + pr[i] + ".pdf"), false, pp);
	};
}
Translate
Anne Marie Jourdain
Participant
Jul 7, 2025 12:04 PM UTC

Peut on adapter ce script pour un livre ? Merci d'avance pour votre retour

Translate