-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNo-fuss FLATTENER.js
97 lines (73 loc) · 5.45 KB
/
No-fuss FLATTENER.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//This flattens the entire pdf
var CopyandFlatten = app.trustedFunction(function()
{ // Privileged context is necessary to prevent JavaScript warning messages on dialog
if(!CheckPermitted())return;
app.beginPriv();
//Save this as a copy appended with 'TABLET'
var doc_path=this.path.replace(/\/[^\/]+pdf$/,"/");
var name=this.documentFileName.replace(/\.pdf$/i,"") ;
//Save a copy
try{
console.println("Saving copy" + doc_path+name+ " TABLET.pdf");
this.saveAs({cPath: doc_path+name + " TABLET.pdf", bCopy: true});
}catch(e){
app.alert("Error during save of clean copy");
}
//Open the copy and flatten it
try{
console.println("Opening copy " + doc_path+name + " TABLET.pdf");
var d=app.openDoc({cPath:doc_path+name+" TABLET.pdf",bHidden:true});
d.flattenPages();
d.info.flattened=true;
d.info.PaginationExists=false;
d.info.HeaderExists=false;
d.info.TOCExists=false;
}catch(e){
app.alert("Error while trying to re-open copy");
}
//Save
try{
console.println("Saving flattened copy " + doc_path+name+ " TABLET.pdf");
d.saveAs({cPath: doc_path+name + " TABLET.pdf"});
}catch(e){
app.alert("Error during save of clean copy");
}
d.closeDoc(true); //close
app.endPriv();
});
//</CodeAbove>
//<JSCodeSnippet name="ImageData6">
var strData6FlattenPages =
"00000000000000000000000000000000130000002c0000002c0000002c0000002c0000002c0000002c0000002c0000002c0000002c0000002c000000130000000000000000000000000000000000000000000000000000000000000054000000dd000000a9000000a8000000a8000000a8000000a8000000a8000000a8000000a8000000a8000000a8000000df00000052000000000000000000000000000000000000000000000000000000a80000002f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000033000000a4000000000000000000000000000000000000000000000000000000ac00000028000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c000000a8000000000000000000000000000000000000000000000000000000ac00000028000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c000000a8000000000000000000000000000000000000000000000000000000ac00000028000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c000000a8000000000000000000000000000000000000000000000000000000ac00000028000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c000000a8000000000000000000000000000000000000000000000000000000ac00000028000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c000000a8000000000000000000000000000000000000000000000000000000ac00000028000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c000000a8000000000000000000000000000000000000000000000000000000ac00000028000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c000000a8000000000000000000000000000000000000000000000000000000ac00000028000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c000000a8000000000000000000000000000000000000000000000000000000ac00000028000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c000000a8000000000000000000000000000000000000000000000000000000ac00000028000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c000000a8000000000000000000000000000000000000000000000000000000ac00000028000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c000000a8000000000000000000000000000000000000000000000000000000ac00000028000000000000000000000000000000000000000000000000000000000000000000000000000000000000002c000000a8000000000000000000000000000000000000000000000000000000ac00000029000000000000000000000000000000000000000000000000000000000000000000000000000000000000002d000000a8000000000000000000000000000000000000000000000000000000ac0000009b000000590000005800000058000000580000005800000058000000580000005800000058000000590000009f000000a8000000000000000000000000000000000000000000000000000000a9000000ff000000ff000000ff000000ff000000ff0000009a000000a6000000ff000000ff000000ff000000ff000000ff000000a400000000000000000000000000000000000000000000000000000052000000f9000000ff000000ff000000ff000000ff000000bb000000c5000000ff000000ff000000ff000000ff000000f80000004d0000000000000000000000000000000000000000000000000000000000000010000000270000002800000028000000280000002800000028000000280000002800000028000000270000000f00000000000000000000000000000000000000";
//</JSCodeSnippet>
// Icon Generic Stream Object
//<JSCodeSnippet name="ButtonIconDef">
var oIconFlattenPages = null;
//if(app.viewerVersion < 7){
oIconFlattenPages = {count: 0, width: 20, height: 20,
read: function(nBytes){return strData6FlattenPages.slice(this.count, this.count += nBytes);}};
//}else{
//}
//</JSCodeSnippet>
//<JSCodeSnippet name="EventCode">
//</JSCodeSnippet>
//<JSCodeSnippet name="ButtonObjDef">
var oButObjFlattenPages =
{cName: "FlattenPages",
cExec: "CopyandFlatten()",
cEnable: "event.rc = (app.doc != null)",
cMarked: "event.rc = false",
cTooltext: "Creates copy for use on a tablet",
oIcon: oIconFlattenPages,
cLabel: "Copy for tablet"};
//</JSCodeSnippet>
try{app.removeToolButton("FlattenPages");}catch(e){}
//<JSCodeSnippet name="TryAddBut">
try
{
//</JSCodeSnippet>
//<JSCodeSnippet name="AddButtonfn">
app.addToolButton(oButObjFlattenPages);
//</JSCodeSnippet>
}catch(e){}
//</JSCodeSnippet>