Hello together,
I do my first experiment in using Adobe Javascript.
I got a javascript to split pdf pages into the half.
My Problem is that the script always makes a new document with var newDoc = app.newDoc();
The Name of the new document looks like this: AcrDEEC.tmp, but I want to keep the original Name of the Pdf opened in Acrobat e.g. My Document.pdf or make a new PDFname like this e.g. My Documentsplit.pdf
Why do I need this, because I have to split hundreds of PDFS and I can´t rename each PDF File maually.
Here is my Script(Not really made by myself getting from khk)
ProcessDocument = app.trustedFunction(function()
{
// create a new document
app.beginPriv();
var newDoc = app.newDoc();// Is it here possible to change the name to the original?
app.endPriv();
// get the filename of our current file
var i = 0;
while (i < this.numPages)
{
newDoc.insertPages( {
nPage: newDoc.numPages-1,
cPath: this.path,
nStart: i
});
newDoc.insertPages( {
nPage: newDoc.numPages-1,
cPath: this.path,
nStart: i
});
// we did this twice so that we can then split each copy of the page into a left
// and right half.
i++;
}
if (newDoc.numPages > 1)
{
newDoc.deletePages(0); // this gets rid of the page that was created with the newDoc call.
}
// at this point we have a documnent with every page from the source document
// copied twice
for (i=0; i
var cropLeft = new Array();
cropLeft[0] = cropRect[0];
cropLeft[1] = cropRect[1];
cropLeft[2] = cropRect[0] + halfWidth;
cropLeft[3] = cropRect[3];
var cropRight = new Array();
cropRight[0] = cropRect[2] - halfWidth;
cropRight[1] = cropRect[1];
cropRight[2] = cropRect[2];
cropRight[3] = cropRect[3];
if (i%2 == 0)
{
newDoc.setPageBoxes( {
cBox: "Crop",
nStart: i,
rBox: cropLeft
});
}
else
{
newDoc.setPageBoxes( {
cBox: "Crop",
nStart: i,
rBox: cropRight
});
}
}
}
)
// add the menu item
app.addMenuItem({
cName: "splitPagesJS", // this is the internal name used for this menu item
cUser: "Split Pages", // this is the label that is used to display the menu item
cParent: "Document", // this is the parent menu. The file menu would use "File"
cExec: "ProcessDocument()", // this is the JavaScript code to execute when this menu item is selected
cEnable: "event.rc = (event.target != null);", // when should this menu item be active?
nPos: 0
});
The script itsself is running perfectly and very nice:-)
In my final script I made some modification with the add.MenuItem and creating a app.addMenuItem this runs also perfectly
I read all the Adobe documentions but I can´t find any help to keep the original PDFname.
Would you plaese help me?
Thank you very much
kind regards
Gebhard
for(var i=this.numPages-1;i>=0;i--)
this.insertPages(i,this.path,i);
This code modifies the original file. To save the file to the new or original name see this article:
How to Save a PDF with JavaScript
To learn more about adding a toolbar button instead of a menu item, see this article
Apply Security with JavaScriprt
The article is about adding security to a PDF but it also shows how to add a button to the Acrobat Toolbar.
More specific information including scripts and tools for both creating and using toolbar buttons can be found at this membership site:Automating Acrobat
Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script