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

An event listener before Exporting to PDF

Community Expert ,
May 13, 2022 May 13, 2022

Copy link to clipboard

Copied

Hi gang,

I found an old event listener script from 10 years ago that pops up when you Print and shows the question: "Did you update the Table of Contents?" and other Quality Control reminders. 

 

How can I edit this event listener to ALSO trigger if someone Exports to PDF?

Mike Witherell
TOPICS
How to

Views

345

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
community guidelines
Community Expert ,
May 16, 2022 May 16, 2022

Copy link to clipboard

Copied

Here is what I found and edited so far:

 

#targetengine "session"
// An event listener performs a preflight check before printing. 
// If preflight fails, it cancels the print job.
main();
function main(){
    var myEventListener = app.eventListeners.add("beforePrint",
        myBeforePrintHandler);
}
function myBeforePrintHandler(myEvent){
//The parent of the event is the document.
    var myDocument = myEvent.parent;
    if(myPreflight(myDocument) == false){
        myEvent.stopPropagation();
        myEvent.preventDefault();
        alert
            (
            "Document did not pass Preflight check."+"\r"+            
            "Did you Edit > Spelling > Check Spelling?"+"\r"+
            "Did you Layout > Update Table of Contents?"+"\r"+
            "Did you File > Save As a backup copy?"
            );
    }
    else{alert
            (
            "Document passed Preflight check. Ready to print."+"\r"+
            "Did you Edit > Spelling > Check Spelling?"+"\r"+
            "Did you Layout > Update Table of Contents?"+"\r"+
            "Did you File > Save As a backup copy?"
            );
        }
    function myPreflight(myDocument){
        var myPreflightCheck = true;
        var myFontCheck = myCheckFonts(myDocument);
        var myGraphicsCheck = myCheckGraphics(myDocument);
        alert("Fonts: " + myFontCheck + "\r" + "Links:" + myGraphicsCheck);
        if((myFontCheck == false)||(myGraphicsCheck == false)){
            myPreflightCheck = false;
        }
        return myPreflightCheck;
    }
    function myCheckFonts(myDocument){
        var myFontCheck = true;
        for(var myCounter = 0; myCounter < myDocument.fonts.length; 
            myCounter ++){
            if(myDocument.fonts.item(myCounter).status != FontStatus.installed){
                myFontCheck = false;
            }
        }
        return myFontCheck;
    }
    function myCheckGraphics(myDocument){
        var myGraphicsCheck = true;
        for(var myCounter = 0; myCounter < myDocument.allGraphics.length;
        myCounter++){
            var myGraphic = myDocument.allGraphics[myCounter];
            if(myGraphic.itemLink.status != LinkStatus.normal){
                myGraphicsCheck = false;
            }
        }
        return myGraphicsCheck;
    }
}

 

This is from the ExtendScript Guide from about 10 years ago.

What I would like to have it also do is trigger the screen messages when someone does an Export to PDF or PDF  interactive.

Can someone advise me on how to expand this beyond listening for the Print command?

Mike Witherell

Votes

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
community guidelines
Community Expert ,
Jun 21, 2022 Jun 21, 2022

Copy link to clipboard

Copied

I reframed the above question in case I was not describing the need clearly.

Also, does it need to be a separate startup script? Or can one event listener listen for 2 events: Print and Export to PDF?

Mike Witherell

Votes

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
community guidelines
Community Expert ,
Jun 21, 2022 Jun 21, 2022

Copy link to clipboard

Copied

Hi @Mike Witherell,

You can use the beforeExport event. The eventhandler is passed an object that contains a property "format" which you can use to identify the file format for which the export is trigerred

#targetengine "session"
app.eventListeners.add("beforeExport",
        function ex(e){
			alert(e.format)
})

So in your code you would have to call the eventListeners add method two times, one for the print method and other time for the export method

-Manan

 

Votes

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
community guidelines
Community Expert ,
Jun 21, 2022 Jun 21, 2022

Copy link to clipboard

Copied

Thanks Manan! I have been playing with this, and comparing it to the one that is for Print. It works, but it doesn't message the screen until AFTER the PDF dialog boxes and AFTER you OK a file name. I wonder what I am doing wrong. it says "beforeExport" but seems to happen after.

Mike Witherell

Votes

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
community guidelines
Community Expert ,
Jun 21, 2022 Jun 21, 2022

Copy link to clipboard

Copied

Hi @Mike Witherell,

I did test it and you are correct about when the event is fired, it seems misplaced. By before it seems to mean before the actual export is triggered but after all the options related to the export have been set.

-Manan

Votes

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
community guidelines
Community Expert ,
Jun 21, 2022 Jun 21, 2022

Copy link to clipboard

Copied

 

#targetengine "session"
// An event listener performs a preflight check before exporting. 
// If preflight fails, it cancels the export job.
main();
function main(){
    var myEventListener = app.eventListeners.add("beforeExport",
        myBeforeExportHandler);
}
function myBeforeExportHandler(myEvent){
//The parent of the event is the document.
    var myDocument = myEvent.parent;
    if(myPreflight(myDocument) == false){
        myEvent.stopPropagation();
        myEvent.preventDefault();
        alert
            (
            "Your document did not pass the Preflight check."+"\r"+           
            "Did you check all fonts, graphic links, and colorspaces?"+"\r"+
            "Did you Edit > Spelling > Check Spelling?"+"\r"+
            "Did you Layout > Update Table of Contents?"+"\r"+
            "Did you File > Save As a backup copy?"
            );
    }
    else{alert
            (
            "Your document passed the Preflight check. It might be ready to print, but ..."+"\r"+
            "Did you Edit > Spelling > Check Spelling?"+"\r"+
            "Did you Layout > Update Table of Contents?"+"\r"+
            "Did you File > Save As a backup copy?"
            );
        }
    function myPreflight(myDocument){
        var myPreflightCheck = true;
        var myFontCheck = myCheckFonts(myDocument);
        var myGraphicsCheck = myCheckGraphics(myDocument);
        alert("Fonts: " + myFontCheck + "\r" + "Links:" + myGraphicsCheck);
        if((myFontCheck == false)||(myGraphicsCheck == false)){
            myPreflightCheck = false;
        }
        return myPreflightCheck;
    }
    function myCheckFonts(myDocument){
        var myFontCheck = true;
        for(var myCounter = 0; myCounter < myDocument.fonts.length; 
            myCounter ++){
            if(myDocument.fonts.item(myCounter).status != FontStatus.installed){
                myFontCheck = false;
            }
        }
        return myFontCheck;
    }
    function myCheckGraphics(myDocument){
        var myGraphicsCheck = true;
        for(var myCounter = 0; myCounter < myDocument.allGraphics.length;
        myCounter++){
            var myGraphic = myDocument.allGraphics[myCounter];
            if(myGraphic.itemLink.status != LinkStatus.normal){
                myGraphicsCheck = false;
            }
        }
        return myGraphicsCheck;
    }
}

 

Mike Witherell

Votes

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
community guidelines
Community Expert ,
Jun 22, 2022 Jun 22, 2022

Copy link to clipboard

Copied

Hi Mike,

just a question:

Will that event also fire if you begin a Share For Review process?

And does that bother you, if it is the case?

 

Thanks,
Uwe Laubender
( Adobe Community Professional )

Votes

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
community guidelines
Community Expert ,
Jun 22, 2022 Jun 22, 2022

Copy link to clipboard

Copied

Hi Uwe,

Thanks for weighing in. I hadn't thought about Share for Review, but I wouldn't mind if it did trigger under that circumstance.

You can see from my example that I am essentially trying to trigger quality control reminders before Print, Export to PDF, and ... yes, Share for Review (I feature I am eager to see expand!)

Mike Witherell

Votes

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
community guidelines
Community Expert ,
Jun 22, 2022 Jun 22, 2022

Copy link to clipboard

Copied

Even if it trigger for Share For Review or any other operation, the format property I mentioned should help us isolate the cases that we are interested in

-Manan

Votes

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
community guidelines
Community Expert ,
Jun 22, 2022 Jun 22, 2022

Copy link to clipboard

Copied

Hi Manan,

Here is a version of my quality control reminders based on your code:

#targetengine "session"
app.eventListeners.add("beforeExport",
        function ex(e){
			alert(e.format)
			alert (
            "Did you check all fonts, graphic links, and colorspaces?"+"\r"+
            "Did you Edit > Spelling > Check Spelling?"+"\r"+
            "Did you Layout > Update Table of Contents?"+"\r"+
            "Did you File > Save As a backup copy?"
			)
})
app.eventListeners.add("beforePrint",
        function ex(e){
	alert
            	(
            "Did you check all fonts, graphic links, and colorspaces?"+"\r"+
            "Did you Edit > Spelling > Check Spelling?"+"\r"+
            "Did you Layout > Update Table of Contents?"+"\r"+
            "Did you File > Save As a backup copy?"
            )
})

This example of code does not try to run a Preflight. It is simpler, which is OK with me. Still, the warning alert for Export to PDF does not happen until AFTER the export. It would be nice for it to occur before. Any thoughts?

Mike Witherell

Votes

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
community guidelines
Community Expert ,
Jun 22, 2022 Jun 22, 2022

Copy link to clipboard

Copied

LATEST

Hi @Mike Witherell,

Try the followign script. Since your event handler was the same for both the events I have reused the code by enclosing it into a common function and have also tried to address the issue of the alert being shown at a later stage

#targetengine "session"

function ex(e){
	alert (
            "Did you check all fonts, graphic links, and colorspaces?"+"\r"+
            "Did you Edit > Spelling > Check Spelling?"+"\r"+
            "Did you Layout > Update Table of Contents?"+"\r"+
            "Did you File > Save As a backup copy?"
		)
	//Uncomment the following two lines if you want the default behaviour of the event to run
	//e.preventDefault();
	//e.stopPropagation()
}

app.menuActions.itemByName ( "$ID/Export..." ).addEventListener ( "beforeInvoke", ex)
app.eventListeners.add("beforePrint", ex)

-Manan

Votes

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
community guidelines
Community Expert ,
Jun 22, 2022 Jun 22, 2022

Copy link to clipboard

Copied

Bear in mind that this simple startup script could easily be edited to add any number of other QC reminders.

Mike Witherell

Votes

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
community guidelines