InDesign script: change Page in placed PDF (selection)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(function selPlacePDFPage( dt,doc,sel,t,ok,ff) | |
//---------------------------------- | |
// Simple interface for changing page in placed PDF. | |
// (Just select the PDF container and run.) | |
{ | |
dt = +new Date; | |
try | |
{ | |
doc = app.properties.activeDocument; | |
if( !doc ) throw "No active document."; | |
sel = doc.properties.selection; | |
if( !(sel && sel.length) ) throw "No selection."; | |
if( !(sel=sel[0]).isValid ) throw "Invalid selection."; | |
for( t=sel ; 'PDF' != t.constructor.name ; t=t[0] ) | |
{ | |
ok = t.hasOwnProperty('contentType') | |
&& ContentType.graphicType == t.properties.contentType | |
&& 1 == (t=t.properties.allGraphics||[]).length; | |
if( !ok ) throw "The selection has no direct PDF content."; | |
} | |
ff = (t=t.properties.itemLink||0).isValid && (t.properties.filePath||0); | |
if( !(ff && File(ff).exists) ) throw "PDF File is missing. You probably should relink."; | |
// Runtime error if canceled by the user (hence the `dt` timer.) | |
// --- | |
sel.place(ff, true); | |
alert( "PDF page sucessfully placed!" ); | |
} | |
catch( e ) | |
{ | |
dt = +new Date - dt; // full delay, in ms. | |
if( 500 > dt ) alert( e ); // Only display instant error. | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment