How to run JS code in reader instead of ACrobat DC

Community Beginner ,
Jul 24, 2022 Jul 24, 2022

Copy link to clipboard

Copied

I am trying to run below code

 

*********************

var GetFile = app.trustedFunction(function()
{
app.beginPriv();
try{global.newDoc.path;}
catch(e)
{
var flag = 1
var cRslt = Collab.browseForFolder();
if (cRslt != undefined)
{
console.println(cRslt);

var cRtn = app.response("Enter backup name");
if (cRtn != null)
{
global.newDoc = app.newDoc();
global.newDoc.saveAs(cRslt + "/+cRtn + ".pdf");
}}}
if (global.newDoc.path != ""){
global.newDoc.insertPages({
nPage:global.newDoc.numPages-1,
cPath: this.path,
nStart: this.pageNum,
nEnd: this.pageNum
});}

global.newDoc.save
if (flag == 1)
{
global.newDoc.deletePages({nStart:0,nEnd:0});
flag = 0
}
app.beep(0);
app.endPriv();
});

var strData7ImportNamedAttach= "******"
var olconimportNamedAttach = null;
olconimportNamedAttach = {count: 0, width: 20,height: 20,
read: function(nBytes){return strData7ImportNamedAttach.slice(this.count, this.count +=nBytes);}};
var DoCmdImportNamedAttach="GetFile();"
var oButObjImportNamedAttach=
{cName: "ImportNamedAttach",
cExec: DoCmdimportNamedAttach,
cEnable: "event.rc = (app.doc != null)",
cMarked: "event.rc = false",
cLabel: "Backup Page",
cTooltext: "Send current page to backup",
nPos: -1}:
if(olconimportNamedAttach != null)
oButObjImportNamedAttach=olconimportNamedAttach;

try{app.removeToolButton("ImportNamedAttach");}catch(e){}
try
{
app.addToolButton(oButObjimportNamedAttach);
if((event.type == "Doc") && (app.viewerVersion >= 7))
global["ImportNamedAttach_In Doc"]="3:28:2009:9:48:55";
else
global ["ImportNamedAttach"] = "3:28:2009:9:48:55";
}catch(e)
{
if((global.bReportNameCollision != null) && (global.bReportNameCollision == true))
{
var strError = 'Cannot Install AcroButton "oButObjImportNamedAttach"\n';
strError += ':' + e.file Name + '\n';
strError += 'Error: ' + e.name + '\n';
strError +=e.message + '\n';
strError += 'Possible Name conflict';
app.alert(strError,0,0,'AcroButton Error');
}
}
var Trusted_MyDocSave = app.trustedFunction(function()
{
app.beginPriv();
var cpath = app.browseForDoc();
global.newDoc = app.openDoc(cpath);
app.endPriv();
});
var test="Trusted_MyDocSave();"
var strData7JSDebugger ="*************"
var olconJSDebugger = null;
olconJSDebugger = {count: 0, width: 20, height: 20,
read: function(nBytes return strData7JSDebugger.slice(this.count, this.count += nBytes);}};
var DoCmdJSDebugger = "console.show();";
var oButObjJSDebugger =
{cName: "JSDebugger",
cExec: test,
cEnable: "event.rc = (app.doc != null)",
cMarked: "event.rc = false",
cTooltext: "Select a backup from folder",
nPos: -1,
cLabel: "Add to file"};
if(olconJSDebugger != null)
oButObjJSDebugger.olcon = olconJSDebugger;
try{app.remove ToolButton("JSDebugger");}catch(e){}
try{app.addToolButton(oButObjJSDebugger);}catch(e){}
var icNewDocSm="****"
var olconNewDocument {count: 0, width: 20, height: 20,
read: function(nBytes){return icNewDocSm.slice (this.count, this count += nBytes);}};

var DoCmdNewDocument=app.trustedFunction(function()
{
app.beginPriv();
try{global.newDoc.path;}
catch(e)
{
var flag = 1
var cRslt2 = Collab.browseForFolder();
if (cRslt2 != undefined)
{
console.println(cRslt2);
var cRtn = app.response("Enter backup name");
//app.alert(cRtn)
if (cRtn != null)
{
global.newDoc = app.newDoc();
global.newDoc.save As(cRslt2 + "/"+cRtn + ".pdf");
}
}
if (global.newDocpath != ""){
var cUrl = app.response("Enter a URL");
global.newDoc.getURL(cUrl)
;}
global.newDoc.save
if (flag == 1)
{

timeout= app.setinterval("DoIt()", 1000);
flag = 0
}
app.endPriv();
});
var oButNewDocument =
{
cName: "NewDocument",
cExec: "DoCmdNewDocument()",
cEnable: "event.rc = true",
cMarked: "event.rc = false",
cTooltext: "Add web page to a backup file",
cLabel: "Add from Web",
olcon: olconNewDocument
}
try(app.removeToolButton("NewDocument");}catch(e){}
try/app.addToolButton(oButNewDocument);}catch(e){}
function DoIt() {
var pages = global.newDoc.numPages
if (pages > 1)
{
global.newDoc.deletePages({nStart: 0,nEnd:0});
app.clearinterval(timeout);
}}
var SendHighlight = app.trustedFunction(function()
// Privileged context is necessary to prevent JavaScript warning messages on dialog
app.beginPriv();

try{global.newDoc.path; } catch(e){
var flag = 1
var cRslt3 = Collab.browseForFolder();
if (cRslt3 != undefined)
{
console.println(cRslt3);
var cRtn = app.response ("Enter backup name");
//app.alert(cRtn)
if (cRtn != null)
{
global.newDoc = app.newDoc();
global.newDoc.saveAs(cRslt3 + "/" + cRtn + ".pdf");
if (global.newDoc.path != ""){
for(var nPg=0;nPg<event.target.numPages; nPg++)
{
var oAnnots = event.target.getAnnots(nPg);
if(oAnnots){
global.newDoc.insertPages(global.newDoc.numPages-1,event.target.path,nPg):
}
global.newDoc.save
if (flag == 1)
{
global.newDoc.deletePages((nStart:0,nEnd:0});
flag = 0
}
app.beep(0);
app.endPriv();
});
var ImgHighlightPages =
*****
var olconHighlightPages = null;
olconHighlightPages= {count: 0, width: 20, height: 20,
read: function(nBytes) {return ImgHighlightPages.slice (this.count, this.count += nBytes);}};
var oButObjHighlightPages=
{cName: "HighlightPages",
cExec: "SendHighlight()",
cEnable: "event.rc = (app.doc != null)",
cMarked: "event.rc = false",
cTooltext: "Send highlighted pages to backup",
olcon: olconHighlightPages,
cLabel: "Highlight Pages"};
//</JSCode Snippet>

try{app.removeToolButton("HighlightPages"); catch(e){}
//Wscodeśn name="TryAddBut">
try{
app.addToolButton(oButObjHighlightPages);
}catch(e){}
*******
var strClip ="***********"
var olconClip = null;
olconClip = {count: 0, width: 20,height: 20,
read: function(nBytes){return strClip.slice(this.count, this.count += nBytes);}};
var flag = 0
var do=
var myClip= app.trustedFunction(function(){
app.beginPriv();
var d = app.activeDocs
d = d.length
return d;
app.endPriv();
});
var DoClip = app.trustedFunction(function()
{
app.beginPriv();
var d1 = myClip();
if (d1 > d0){
old = myClip():
if (global newDoc path = ""){
z = app.active Docs;
global.newDoc.insertPages({
nPage:global.newDoc.numPages-1,
cPath: z[d1-1] path,
nStart 0
nEnd: 0});}
global newDoc.save
app.clearInterval(timeout
zid1-1].close Doc(true);
if (flag - 1 )
//var pages = global.newDoc.numPages
global.newDoc.delete Pages((nStart 0.nEnd:0})
flag = 0
}
app.endPriv();
var oClip =
{
cName:"Clip",
CExec: "ClipDocument()",
cEnable: "event.rc = (app.doc != null)",
cMarked: "event.rc = false",
cTooltext: "Send clip to backup",
olcon: oClip,
cLabel: "Snip"};
//</JSCode Snippet>

try{app.removeToolButton("Clip"); catch(e){}

try{
app.addToolButton(oClip);
}catch(e){}

TOPICS
How to

Views

30

Likes

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
Adobe Community Professional ,
Jul 24, 2022 Jul 24, 2022

Copy link to clipboard

Copied

And... ? What is the result? A bit more information would be helpful...

At a first glance I can see that you're calling the deletePages method, though. That would only work in Reader on pages that have been spawned from a Template. You can't delete regular pages in a PDF using it.

Likes

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
Adobe Community Professional ,
Jul 24, 2022 Jul 24, 2022

Copy link to clipboard

Copied

You also have multiple syntax errors in the code, so it's not going to work in Acrobat, either.

For example, this line:

if (global newDoc path = ""){

It should probably be:

if (global.newDoc.path == ""){

And even then it doesn't make sense, as the path of a Document object can't be empty, even if it was just created.

Likes

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
Adobe Community Professional ,
Jul 24, 2022 Jul 24, 2022

Copy link to clipboard

Copied

LATEST

Acrobat Reader can't insert pages.

Likes

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