Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

how to write a script for export to pedf interactive?

Explorer ,
Oct 17, 2022 Oct 17, 2022

hi, it exist lot of nice script for export to pdf but, i need to integrate it into my script

 

2 possiblity, i write it  into my actual big script after update all link by recusrion, we can export the "etiquette fini.indd" file

 

 

or i write a script with scan mask function for open only the "etiquette fini.indd" file name (name existing in 70 version file with 70 path different), and i export only this file to pdf interactive?

 

 

thanks for your help

 

i m so close to finish my job

TOPICS
Scripting
1.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 20, 2022 Oct 20, 2022

hello, after two hours of fruitless try.....

here is where I am, I tried to steal a piece of photoshop png export code to make the file path and the file name but hey it does not work

newfile gives consistent result in watch (~/Desktop/test%20script/ingr%C3%A9dients%20-%20Copie%20(2).pdf), but it tells me it's undefined... I can ' I don't take it anymore.... I would like to know how to do all this....


here is where I am with my tests

 

 

var updated_list = [];

var defaultFolder = "/M/infographie/Dossier Phykidis/base de donnée produit/pkd"
function findAll(f, flist) {
    var f = Folder(f).getFiles("*.*");
    for (var i = 0; i < f.length; i++) {
        if (f[i] instanceof Folder && f[i].name[0] != ".")
            findAll(f[i], flist);
        else {
            if (f[i].displayName == ("étiquette finie.indd"||"cataloguephykidis.indd"||"cataloguephykidis - fiche tech.indd"))
                flist.push(f[i])
        }
    }
}

var myFolder = Folder(defaultFolder).selectDlg("Select the folder containing InDesign Files");
if (!myFolder) exit();

var f = []
findAll(myFolder, f)
var doc;
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;
//Opens each ID file and runs the 
for (var i = 0; i < f.length; i++) {
    doc = app.open(File(f[i]));
        OpenAndUpdate(doc);
}

alert('fini !')


/**
 * Updates a document’s links 
 * @ param the document to update 
 * @ return value 0 
 * 
 */
function OpenAndUpdate(doc) {
    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;
    //$.writeln("ouverture d'un sous lien : " +  doc);
    internal_link = doc.links;
    var nb_link = 0;
    try {
        nb_link = internal_link.length;
    } catch (error) {}
    //$.writeln(internal_link);
    //$.writeln("nombre de liens dans ce fichier : " + internal_link.length + "nombre de link : " + nb_link ) //+ internal_link[k]);
    if (nb_link > 0) {
        // doc.links.everyItem().update(); 
        // doc.save(); //idem
        for (var k = 0; k < nb_link; k++) {
            // internal_link = doc.links; 
            if (k > 0) {
                
            }
            // On vérifie que le lien est OK :
            if (internal_link[k].status == LinkStatus.LINK_MISSING){
			    //var filePath = File.openDialog(internal_link[k].filePath);
				alert(internal_link[k].filePath)
				//internal_link[k].relink(filePath.fsName);
				//internal_link[k].reinitLink(filePath.fsName);
		    }
			else {
				internal_link[k].update();
				}
            // Si le lien est ok. On l'ouvre pour vérifier ses propres lien. La recursivité a lieu ici:
            //$.writeln("Lien numéro " + k + " : type de fichier " + internal_link[k].linkType + " alors que seul les indd sont mis à jour");
            if (internal_link[k].linkType == 'InDesign Format Name') { // Je ne veux ouvrir que les fichier indd
                //$.writeln("ouverture d'un sous lien. entrée dans une boucle récursive");
                //alert(updated_list);
                if (!isinlist(updated_list,internal_link[k].filePath)) { 
                    newdoc = app.open(internal_link[k].filePath);
                    OpenAndUpdate(newdoc)
                    doc = app.activeDocument
					internal_link = doc.links; // quand tu reviens de la boucle, recharge les liens
                    updated_list.push(internal_link[k].filePath); 
                }
            }
        }
    }
    if (doc.links.length > 0) {
        app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;
        doc.links.everyItem().update();
		//if (doc.displayName == ("étiquette finie.indd"){
			exporttopdf();
		//}
        doc.close(SaveOptions.YES);
    } else {
        doc.close();
    }
    return 0; // fin de la fonction. Elle ne renvoie rien normalement
};

function isinlist(list, element) {
	var flag = false;
	for (var l = 0; l < list.length; l++) {
		if (list[l] == element){
			flag = true;
		}
	}
	return flag;
}

function exporttopdf() {
var myDocument = app.activeDocument;	//Or set it with or replace it with the document object you might have

for (var myCounter = 0; myCounter < myDocument.spreads.length; myCounter++) {
	myDocument.spreads.item(myCounter).pageTransitionType = PageTransitionTypeOptions.wipeTransition;
	myDocument.spreads.item(myCounter).pageTransitionDirection = PageTransitionDirectionOptions.down;
	myDocument.spreads.item(myCounter).pageTransitionDuration = PageTransitionDurationOptions.medium;
}
app.interactivePDFExportPreferences.flipPages = true;
app.interactivePDFExportPreferences.flipPagesSpeed = 5;
app.interactivePDFExportPreferences.openInFullScreen = false;
app.interactivePDFExportPreferences.interactivePDFInteractiveElementsOption = InteractivePDFInteractiveElementsOptions.includeAllMedia;
var docName = myDocument.name.replace(/\.[^\.]+$/, '');
var outputFolder = Folder(myDocument.filePath);
var newFile = File(decodeURI(outputFolder) + "/" + docName + ".pdf");
myDocument.exportFile(ExportFormat.interactivePDF,newfile, false);	//Change the file path and file name as needed
}

 

 

and that:

 

 

		//if (doc.displayName == ("étiquette finie.indd"){
			exporttopdf();
		//}

 

 

 

create error 25....

 

my full code

 

 

var updated_list = [];

var defaultFolder = "/M/infographie/Dossier Phykidis/base de donnée produit/pkd"
function findAll(f, flist) {
    var f = Folder(f).getFiles("*.*");
    for (var i = 0; i < f.length; i++) {
        if (f[i] instanceof Folder && f[i].name[0] != ".")
            findAll(f[i], flist);
        else {
            if (f[i].displayName == ("étiquette finie.indd"||"cataloguephykidis.indd"||"cataloguephykidis - fiche tech.indd"))
                flist.push(f[i])
        }
    }
}

var myFolder = Folder(defaultFolder).selectDlg("Select the folder containing InDesign Files");
if (!myFolder) exit();

var f = []
findAll(myFolder, f)
var doc;
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;
//Opens each ID file and runs the 
for (var i = 0; i < f.length; i++) {
    doc = app.open(File(f[i]));
        OpenAndUpdate(doc);
}

alert('fini !')


/**
 * Updates a document’s links 
 * @ param the document to update 
 * @ return value 0 
 * 
 */
function OpenAndUpdate(doc) {
    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;
    //$.writeln("ouverture d'un sous lien : " +  doc);
    internal_link = doc.links;
    var nb_link = 0;
    try {
        nb_link = internal_link.length;
    } catch (error) {}
    //$.writeln(internal_link);
    //$.writeln("nombre de liens dans ce fichier : " + internal_link.length + "nombre de link : " + nb_link ) //+ internal_link[k]);
    if (nb_link > 0) {
        // doc.links.everyItem().update(); 
        // doc.save(); //idem
        for (var k = 0; k < nb_link; k++) {
            // internal_link = doc.links; 
            if (k > 0) {
                
            }
            // On vérifie que le lien est OK :
            if (internal_link[k].status == LinkStatus.LINK_MISSING){
			    //var filePath = File.openDialog(internal_link[k].filePath);
				alert(internal_link[k].filePath)
				//internal_link[k].relink(filePath.fsName);
				//internal_link[k].reinitLink(filePath.fsName);
		    }
			else {
				internal_link[k].update();
				}
            // Si le lien est ok. On l'ouvre pour vérifier ses propres lien. La recursivité a lieu ici:
            //$.writeln("Lien numéro " + k + " : type de fichier " + internal_link[k].linkType + " alors que seul les indd sont mis à jour");
            if (internal_link[k].linkType == 'InDesign Format Name') { // Je ne veux ouvrir que les fichier indd
                //$.writeln("ouverture d'un sous lien. entrée dans une boucle récursive");
                //alert(updated_list);
                if (!isinlist(updated_list,internal_link[k].filePath)) { 
                    newdoc = app.open(internal_link[k].filePath);
                    OpenAndUpdate(newdoc)
                    doc = app.activeDocument
					internal_link = doc.links; // quand tu reviens de la boucle, recharge les liens
                    updated_list.push(internal_link[k].filePath); 
                }
            }
        }
    }
    if (doc.links.length > 0) {
        app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;
        doc.links.everyItem().update();
		//if (doc.displayName == ("étiquette finie.indd"){
			exporttopdf();
		//}
        doc.close(SaveOptions.YES);
    } else {
        doc.close();
    }
    return 0; // fin de la fonction. Elle ne renvoie rien normalement
};

function isinlist(list, element) {
	var flag = false;
	for (var l = 0; l < list.length; l++) {
		if (list[l] == element){
			flag = true;
		}
	}
	return flag;
}

function exporttopdf() {
var myDocument = app.activeDocument;	//Or set it with or replace it with the document object you might have

for (var myCounter = 0; myCounter < myDocument.spreads.length; myCounter++) {
	myDocument.spreads.item(myCounter).pageTransitionType = PageTransitionTypeOptions.wipeTransition;
	myDocument.spreads.item(myCounter).pageTransitionDirection = PageTransitionDirectionOptions.down;
	myDocument.spreads.item(myCounter).pageTransitionDuration = PageTransitionDurationOptions.medium;
}
app.interactivePDFExportPreferences.flipPages = true;
app.interactivePDFExportPreferences.flipPagesSpeed = 5;
app.interactivePDFExportPreferences.openInFullScreen = false;
app.interactivePDFExportPreferences.interactivePDFInteractiveElementsOption = InteractivePDFInteractiveElementsOptions.includeAllMedia;
var docName = myDocument.name.replace(/\.[^\.]+$/, '');
var outputFolder = Folder(myDocument.filePath);
var newFile = File(decodeURI(outputFolder) + "/" + docName + ".pdf");
myDocument.exportFile(ExportFormat.interactivePDF,newfile, false);	//Change the file path and file name as needed
}

 

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Oct 20, 2022 Oct 20, 2022

The error code isn't the greatest piece of information. Can you please run your code inside a try/catch statementlike this: 

 

try{
   //all your code
}
catch(err){
   alert(err.line+" => "+err.message);
}

That will give you the line number where the error occurs and hopefully a clearer debugging message.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 20, 2022 Oct 20, 2022

line 120 newfile is undefined

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Oct 20, 2022 Oct 20, 2022

JavaScript is case sensitive so check your namings, newfile and newFile are two different references.

Try to be cautious with your writing, this is a very basic error you could have figured yourself.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 20, 2022 Oct 20, 2022

line 85 error 25 without alert

 

 

       if (doc.displayName == ("étiquette finie.indd"){
            exporttopdf();
        }

 

export work, but with all file not only etiquette fini.indd

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 20, 2022 Oct 20, 2022

@laurence roussel12011930 as I have always told you, you need to be methodical and patient to get results. You get too impatient to get the things working and don't really want a proper solution. First you were not ready or invest time to investigate why your PDF export won't work, you insisted on getting a working sample of code that exports interactive pdf. I gave you the snippet and also changed it as per your needs. Rather than testing that code and responding back if it works or not you integrated it into your bigger script and came back with things like 2 hours wasted, nothing works, works for x no. of files but not for 1 or 2. How do you expect someone sitting remotely to help you when you don't believe in isolating the problem and helping debug the issue. Is it easier to debug an isolated smaller problem or a problem in a bigger context, you move in the opposite direction.

The proper way would have been to test the export method alone and see if it works or not. If it does not work then get it fixed right there. Once it is working with all your use cases/files then start integrating with a bigger codebase and again test it. If now it fails then find under which condition, is it the filename is the file contents, is it the filepath that is causing issues, these are questions only you can figure out and not us. Telling us that a file named so and so does not work, how does that help us, there could be anything wrong with the file, We don't have access to the file and your machine to guess. So in a nutshell if you are not going to be methodical in your approach and give reliable inputs to us in addition to feedback on what we suggested you won't be able to get proper help from public forums.

-Manan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 20, 2022 Oct 20, 2022

i understand, i m patient,i work on it since 2-3 week...

 

i try to cut and past some code from different script

 

actually i don t understand why

if (doc.displayName == ("étiquette finie.indd"){}
do an error 25
doc.displayName exist and used before into the script....
 
and error 25 can help to debug
 
i put a stop point on line 85 for test the condition
 
edit: error find
 
if (doc.displayName == ("étiquette finie.indd"){}
if (doc.displayName == ("étiquette finie.indd")){}
if (doc.displayName == "étiquette finie.indd"){}
 
edit again:
if (doc.Name == "étiquette finie.indd"){}
 
wrong...
if (doc.name == "étiquette finie.indd"){}
 
good
 
 
 
 
 
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Oct 20, 2022 Oct 20, 2022
LATEST

@laurence roussel12011930 I couldn't agree @Manan Joshi more. You are so focused on the final achievement that you are actually drawning yourself in a glass of water. Let me give you an example of what happens in the aeronautic industry. If a pilot comes to a point he faces multiple alerts and is having a hard time understanding the situation, what he needs to do first is actually buy time (when of course this is possible) and get higher so he can "peacefully" overview the situation. So hands back, cold analysis, and back to a series of checklists to unthread the list of possible issues. 

Your plane isn't going in the right direction and you still want is to force it to go where you want no matter how. Just get height and start analyzing your issues from a microscopic point of view. This is all that we are telling you to do for a few days and you demonstrate almost no effort to do so.

It reminds me of a really good sentence from one of the greatest InDesign scripters around here: "Don't code until the very last moment". That means, try to investigate as much as possible on your scripting project, the best way to tackle it, the architecture you may need to escalate it in case of a future project, think in terms of small routines you can reuse, and possible build your own library of robust methods. Write pseudo code (that can help) for the logic. Draw logical diagrams (I do them and find those really valuable). You will see that this preliminary effort leads generally to much quicker code development because everything appears more clearly.
Remember that once you start coding, all the solutions appear to be more code and it's harder to slow down and think.

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