// variable to store whether document has been opened already or not
var bAlreadyOpened;

function docOpened()
{

	if(bAlreadyOpened != "true")
	{
		// document has just been opened
		var d = new Date();
		var sDate = util.printd("mm/dd/yyyy", d);

                // set date now
                app.alert("About to insert date into field now");
		this.getField("todaysDate").value = sDate;

		// now set bAlreadyOpened to true so it doesn’t
		// run again
bAlreadyOpened = "true";
	}
	else
	{
		// document has already been opened
	}
}

// call the docOpened() function
docOpened();

ppjslc_commonex_3.pdf
0.08MB

출처 : Example Acrobat JavaScripts – Planet PDF

/********************************
RSCivilTools by Andrew Binning
Version 01, 2-15-2012
********************************/
//Some code by:
// InDesign Fixups by Dave Merchant  - Creative Commons Share-alike license
// version 02, November 2010
// http://www.uvsar.com/go/indesignfixups

//create new submenu for the Acrobat 8/9 or X menus
//Determine version, assign menu location
var menuParent = (app.viewerVersion<10)? "DocumentProcessing":"Edit";
//Add the menu
app.addSubMenu({ cName:"RSCivilTools", cUser:"RSCivil Tools", cParent:menuParent, nPos:((app.viewerVersion<10)? 0:7) });
//Create a nested layer (tailored code for my specific Document.
app.addMenuItem({ cName:"RSCcreateNest", cUser:"Create Nest", cParent:"RSCivilTools", 
          cExec:"createNest();",
          cEnable:"event.rc = (event.target != null);", nPos:0 });
//Promote sub layers - Unravel the nests
app.addMenuItem({ cName:"RSCpromote", cUser:"Undo Nest", cParent:"RSCivilTools",
          cExec:"promoteOCG_handler(event.target);",
          cEnable:"event.rc = (event.target != null);", nPos:1 });
//Unlist Guides and Grids layer (from Adobe IN-Design)
app.addMenuItem({ cName:"RSCremGAG", cUser:"Unlist 'Guides and Grids'", cParent:"RSCivilTools",
          cExec:"removeGAG(event.target);",
          cEnable:"event.rc = (event.target != null);", nPos:2 });
//Set up layers ( this is tailored code for my specific Document)
app.addMenuItem({ cName:"RSCsetStates", cUser:"Set Layers", cParent:"RSCivilTools",
          cExec:"setStates();",
          cEnable:"event.rc = (event.target != null);", nPos:3 });
//Toggle this list of layers on and off (tailored code for my specific Document.
app.addMenuItem({ cName:"RSCtoggleCityLimits", cUser:"Toggle City Limits", cParent:"RSCivilTools",
          cExec:"toggleCityLimits();",
          cEnable:"event.rc = (event.target != null);", nPos:4 });
//Link to the company website         
app.addMenuItem({ cName:"RSCsite", cUser:"Website", cParent:"RSCivilTools", 
          cExec:"app.launchURL('http://rscivil.com');", nPos:5 });

//Add a button for this function - Add from Quick Tools 3rd party addons
app.addToolButton({
        cName: "RSCcreateNestButton",
        cExec: "createNest();",
        cTooltext: "Create Nest",
        cEnable: true,
        nPos: 0,
        cLabel: "Create Nest"
        })
//Add a button for this function - Add from Quick Tools 3rd party addons
app.addToolButton({
        cName: "promoteLayers",
        cExec: "promoteOCG_handler(event.target);",
        cTooltext: "Undo Nest",
        cEnable: true,
        nPos: 1,
        cLabel: "Undo Nest"

        })

//Creates a nested layer from a predetermined list
function createNest(){
    var layers = this.getOCGs();
    var newOrder = new Array();
    var cityLimits = new Array();
    var comps = new Array();

    /*******************************************************
    This is where I need help.
    By not setting the first element to a String it does not name the group. Instead it seems to attach it as a child to the previous element in the array.
    This is fine, except that when you turn off said parent it does not turn off the sub layers/OCGs.
    If I could figure out how to create an object and set it up as an element before my inserted array it might help.
    *******************************************************/
    //Commented for testing - Set first element of the array to a descriptive string (this will be the name of the nested group) 
    //cityLimits[0] = "City Limits";
    //Set first element of the array to a descriptive string (this will be the name of the nested group)
    comps[0] = "Comps";

    //Separate all layers/OCGs containing "CityLimits|" or "COMP" from the original list of layers/OCGs
    for (var i=0,j=0,k=0,l=1; i<layers.length; i++){
        if(layers[i].name.substr(0,11)==="CityLimits|"){
            cityLimits[j] = layers[i];  //separate CityLimits OCG
            j++;
        }
        else if(layers[i].name.substr(0,4)==="COMP"){
            comps[l] = layers[i];   //separate COMP OCG
            l++;
        }
        else{
            newOrder[k] = layers[i];    //cram everything else into a new array
            k++;
        }
    }
    //Insert the cityLimits array into the newOrder array at position 5, do not remove any elements (the element before this arbitrarily becomes the parent, but does not work correctly)
    newOrder.splice(5,0,cityLimits);
    //Append the comps array to the end of the newOrder array
    newOrder[newOrder.length] = comps;
    //set the newOrder array as the OCGOrder.
    this.setOCGOrder(newOrder);
}
//Code by Dave Merchant
//Handler for promoting OCGs out of nested layers
function promoteOCG_handler(oDoc) {

  var ocgOrder = oDoc.getOCGOrder();
  var hasNest = false;

  if (ocgOrder==null) {
    app.alert( "No layers in current file", 0, 0, "Cannot proceed");
  } else {
    for (var i=0; i<ocgOrder.length; i++) {
       if ((typeof(ocgOrder[i]) == "object") && (ocgOrder[i].length > 0)) hasNest = true;
    }
    if (hasNest)  {
      promoteOCGs(oDoc,ocgOrder);
    } else app.alert( "No nested layers in current file", 0, 0, "Cannot proceed");
  }
}
//Code by Dave Merchant
//Promote/unravel layers/OCG out of nests
function promoteOCGs(oDoc,ocgOrder) {

  // Removes the top-level OCG nest structure from a PDF, promoting all sub-OCGs to the top level.
  // Used to remove the nesting created when a PDF is exported from InDesign with "Create Acrobat Layers" checked.


  var oChk = { cMsg:"Unlist the 'Guides and Grids' layer?", bInitialValue:true, bAfterValue:false};

  //var cMesg = "This action will ungroup all nested layers. IT CANNOT BE UNDONE.\n\nDo you want to continue?";
  //var nRtn = app.alert({ cMsg:cMesg, nIcon:2, nType:2, cTitle:"Promote nested layers", oCheckbox:oChk});
  //if (nRtn == 4) {

    var newOrder = new Array();

    for (var i=0; i<ocgOrder.length; i++) {

     var oType = typeof(ocgOrder[i]);
     var oLeng = ocgOrder[i].length
     if ((oType == "object") && (oLeng > 0)) {      // it's a nest, do the promotions

        for (var j=0; j<oLeng; j++) {
           if ((typeof(ocgOrder[i][j]) == "object") && 
              (!oChk.bAfterValue || (ocgOrder[i][j].name != "Guides and Grids"))) newOrder.push(ocgOrder[i][j]);
        }

     } else if (!oChk.bAfterValue || (ocgOrder[i].name != "Guides and Grids")) newOrder.push(ocgOrder[i]);
    }
    oDoc.setOCGOrder( newOrder );
  //}
}


//Code by Dave Merchant
// Removes the listing for (sub)OCG named "Guides and Grids".
// Does NOT delete the layer, simply hides it from the sidebar display.
function removeGAG(oDoc) {
  var cMesg = "This action will unlist the 'Guides and Grids' layer from the sidebar but will NOT delete the ";
  cMesg += "layer itself. IT CANNOT BE UNDONE.\n\nDo you want to continue?";
  var nRtn = app.alert(cMesg, 2, 2, "Unlist 'Guides and Grids'");
  if (nRtn == 4) {

    var ocgOrder = oDoc.getOCGOrder();
    var newOrder = new Array();

    for (var i=0; i<ocgOrder.length; i++) {

     var oType = typeof(ocgOrder[i]);
     var oLeng = ocgOrder[i].length
     if ((oType == "object") && (oLeng > 0)) {      // it's a nest

        var subObj = new Array();
        for (var j=0; j<oLeng; j++) {
           if ((typeof(ocgOrder[i][j]) == "string") || (ocgOrder[i][j].name != "Guides and Grids")) subObj.push(ocgOrder[i][j]);
        }
        newOrder.push(subObj);

     } else if (ocgOrder[i].name != "Guides and Grids") newOrder.push(ocgOrder[i]);
    }
    oDoc.setOCGOrder( newOrder );
  }
}

//Just a list of layers I want to toggle on or off (document specific)
function togList(name){
    if(name.substr(0,11)==="CityLimits|")
        return true;
    return false;
}
//Just a list of layers I want to set an initial state to off (document specific)
function offList(name){
    var lOff =  new Array();
    lOff[0] = "ADT";
    lOff[1] = "CityLimits|1900";
    lOff[2] = "CityLimits|1910";
    lOff[3] = "CityLimits|1920";
    lOff[4] = "CityLimits|1930";
    lOff[5] = "CityLimits|1940";
    lOff[6] = "CityLimits|1950";
    lOff[7] = "CityLimits|1960";
    lOff[8] = "CityLimits|1970";
    lOff[9] = "CityLimits|1975";
    lOff[10] = "CityLimits|1980";
    lOff[11] = "CityLimits|1985";
    lOff[12] = "CityLimits|1990";
    lOff[13] = "CityLimits|1995";
    lOff[14] = "CityLimits|2000";
    lOff[15] = "CityLimits|2005";
    lOff[16] = "CityLimits|2006";
    lOff[17] = "CityLimits|2007";
    lOff[18] = "CityLimits|2008";
    lOff[19] = "CityLimits|2009";
    lOff[20] = "CityLimits|2010";
    lOff[21] = "CityLimits|2011";
    lOff[29] = "Distance Circles 1";
    lOff[30] = "Distance Circles 2";
    lOff[31] = "landuse|Agriculture";
    lOff[32] = "landuse|Industrial";
    lOff[33] = "Landmark Labels Locations";
    lOff[34] = "landmarks|Locations";

    for (var i=0; i<lOff.length; i++){
        if(lOff[i] === name)
            return true;
    }
    return false;
}

//Checks all layers against a list and toggles them off or on (document specific)
function toggleCityLimits(){
   var layers = this.getOCGs();
    for (var i=0; i<layers.length; i++){
        var tog = true;
        if(togList(layers[i].name)){
            if(layers[i].state)
                tog = false;
            layers[i].state = tog; //toggle layer
        }
    }
}

//Checks all layers against a list and sets the initial state and current state to off (state=visibility) (document specific)
function setStates(){
   var layers = this.getOCGs();
    for (var i=0; i<layers.length; i++){
        var tog = true;
        if(offList(layers[i].name))
            tog = false;
        layers[i].state = tog;      //turn off layer
        layers[i].initState = tog;  //set initial visibilty to off
    }
}

출처 : http://www.uvsar.com/go/indesignfixups

syncAnnotScan();

var strFDF = exportAsFDFStr({bAllFields: 'true', bFlags: 'true', bAnnotations: 'true'});
//exportAsXFDFStr(true, true, null, true, 1);";

var strXFDF = exportAsXFDFStr(true, true, true, true, 1);
//exportAsXFDFStr(true, true, null, true, 1);

exportAsFDF({ bAnnotations: 'true', cPath: '/d/export.fdf'});


importAnFDF("/d/import.fdf");
importAnXFDF("/d/import.xfdf");
// Add navigation buttons to the page
// This script puts 3 buttons on top of every page (except the first one that has one button)
// First button "<" : takes to the previous page
// Second button: "1" : takes to the first page of the document
// Third button: ">" : takes to the next page in the document (does not exists on the last page)

var inch = 72;

try 
{

    nLastPage = this.numPages - 1;

    for (var p = 0; p < this.numPages; p++)
    {
        var x = 0.5;
 
        if (p > 0)
        {
            AddButton(p,x,0.5,0.25,0.25,"PrevPage","<","Previous Page","this.pageNum--;"); // left arrow, previous page
            x += 0.3;
        }
    
        if (p != 0)
        {
            AddButton(p,x,0.5,0.25,0.25,"StartPage","1","Go To First Page","this.pageNum=0;"); // "1", takes to the first page
            x += 0.3;
        }
    
        if (p < nLastPage)
        {
            AddButton(p,x,0.5,0.25,0.25,"NextPage",">","Next Page","this.pageNum++;"); // right arrow, next page
            x += 0.3;
        }

        AddButton(p,x,0.5,0.25,0.25,"Back","<<","Go Back","app.execMenuItem(\"GoBack\");"); // right arrow, next page
        x += 0.3;
        
    }

}


catch (e)
{
app.alert(e);
}

// AddButton function creates a button with given parameters and action

function AddButton(nPageNum, x, y, width, height, strText, strCaption, strToolTip, strAction)
{
    var aRect = this.getPageBox( { nPage: nPageNum} );
    aRect[0] += x * inch;
    aRect[1] -= y * inch;
    aRect[2] = aRect[0] + width * inch;
    aRect[3] = aRect[1] - height * inch;

    var f = this.addField(strText,"button", nPageNum, aRect);
    f.setAction("MouseUp",strAction);
    f.userName = strToolTip;
    f.delay = true;
    f.borderStyle = border.s;
    f.highlight = "push";
    f.textSize = 0; // autosized
    f.textColor = color.blue;
    f.strokeColor = color.blue;
    f.fillColor = color.white;
    // you can specify a different font here, otherwise it uses a default one
    //f.textFont = font.ZapfD;
    f.buttonSetCaption(strCaption); 
    f.delay = false;
}

 

출처 : https://www.evermap.com/javascript.asp

AcrobatDC_js_developer_guide.pdf
2.78MB
AcrobatDC_js_api_reference.pdf
4.17MB
AcrobatDC_js_3d_api_reference.pdf
0.87MB
AcrobatDC_U3DElements.pdf
0.27MB
AcrobatDC_batch_sequences.pdf
0.23MB

출처 : ADOBE

var annots = this.getAnnots();
console.clear();
for (var i = 0; i < annots.length; i++) 
{
	//console.println(annots[i].toString());
	//if (annots[i].type == "PolyLine") 
	{  
		var a = annots[i].getProps();
		for(var o in a)
		{
			console.println( "annots." + o + "=" + a[o]);
		}
		console.println( "==========================")
		++counter;   
	}
}

app.alert("Total comments count: " + annots.length + " / : " + counter);
var annotText = this.addAnnot({
	page: 0,
	type: "FreeText",
	textFont: "Arial", // or, textFont: "Viva-Regular",
	textSize: 7,
	rect: [57.806640625,730.9102172851562,75.806640625,744.916015625],
	width: 0,
	alignment: 1,
	contents: "D",
	lineEnding : "None",
	refType : "R",
	seqNum : 1
});

var annotPoly = this.addAnnot({
	page: 0,
	type: "PolyLine",
	rect: [55.78631591796875,730.4441528320312,73.8094482421875,747.8836059570312], // height for three lines
	reftype : "R",
	rotation: -270,
	vertices: [[73.25311279296875,738.8373413085938],[56.49212646484375,747.6712036132812],[56.367919921875,730.8611450195312],[73.25311279296875,738.8373413085938]],
	with: 0.75,
	seqNum : 2
});
var annot = this.addAnnot({
	page: 0,
	type: "Text",
	point: [72,500],
	popupRect: [72, 500,6*72,500-2*72],
	popupOpen: true,
	noteIcon: "Help"
});

var spans = new Array();
spans[0] = new Object();
spans[0].text = "Attention:\r";
spans[0].textColor = color.blue;
spans[0].textSize = 18;

spans[1] = new Object();
spans[1].text = "Adobe Acrobat 6.0\r";
spans[1].textColor = color.red;
spans[1].textSize = 20;
spans[1].alignment = "center";

spans[2] = new Object();
spans[2].text = "will soon be here!";
spans[2].textColor = color.green;
spans[2].fontStyle = "italic";
spans[2].underline = true;
spans[2].alignment = "right";

// Now give the rich field a rich value
annot.richContents = spans;

출처 : https://www.gdpicture.com/forum/viewtopic.php?t=6250#p19870 

 

Adding multiline rich text - GdPicture Imaging Forums

Post by radshat » Wed Dec 13, 2017 12:31 am I need to be able to create multiline rich text annotation. The Acrobat JavaScript API reference allows the following. What is the equivalent in GdPicture? I don't mind doing this as a custom action on the serve

www.gdpicture.com

 

+ Recent posts