Copy link to clipboard
Copied
Carlos, you created a script i believe called AI_openMultiPagePDF.
And that is awesome, However i was wondering if you could change it just a bit and instead of opening the files, could you use the PLACE command instead?
The problem i have had is that some PDF's have embedde fonts that i dont have but if i place it, then flatten transparency>Convert Outlines i can use the PDF excatly as it was and not have it convert the fonts.
Is that an easy script change?
Here is your script
#target illustrator
#targetengine session
// script.name = AI_openMultiPagePDF_CS4_CS5_v1.02.jsx;
// script.description = opens a multipage PDF;
// script.required = requires CS4 or later
// script.parent = CarlosCanto // 01/07/12; v1.2-01/15/12
// script.elegant = false;
// Notes: I didn't try opening a ridiculous amount of pages, I "only" open 35 pages....in about a minute and a half.
// Use with caution, save everything before running, script is memory intensive...
// Lion fix by John Hawkinson 01/15/12
//----------------------- START UI CODE, create user interface
var win = new Window ("dialog", "MTools - Open Multipage PDF");
var fileGroup = win.add("group"); // this is the group on the left, it holds the File button and the Font label note
var btnFile = fileGroup.add("button", undefined, "File..."); // button to select the PDF to open
var lblFonts = fileGroup.add("statictext",undefined,"Unavailable\nFonts\nwill be\nsubstituted.", {multiline:true}); //
var grpRight = win.add("group"); // group on the right, to hold everything else
var txtFile = grpRight.add("edittext",undefined); // to hold selected PDF file path
var grpPanel = grpRight.add("group");
var pagesPanel = grpPanel.add("panel", undefined, "Page Range");
var lblFrom = pagesPanel.add("statictext",undefined,"From:");
var txtFrom = pagesPanel.add("edittext",undefined, 1);
var lblTo = pagesPanel.add("statictext",undefined,"To:");
var txtTo = pagesPanel.add("edittext",undefined, 1);
var btnGroup = grpPanel.add("group");
var btnOk = btnGroup.add("button", undefined, "Open");
var btnCancel = btnGroup.add("button", undefined, "Cancel");
var lblStatus = grpRight.add("statictext",undefined,"Open Multipage PDF requires CS4 or later...");
win.orientation = pagesPanel.orientation = "row"; // two items fileGroup and grpRight
win.alignChildren = "right";
fileGroup.orientation = "column";
fileGroup.alignment = "top";
txtFile.alignment = ["fill","top"];
lblStatus.alignment = "left";
grpRight.orientation = "column";
btnGroup.orientation = "column";
btnOk.enabled = false; // disable this button until a valid file is supplied
txtFrom.characters = txtTo.characters = 3;
btnFile.active = true; // receive the first "Enter"
win.helpTip = "\u00A9 2012 Carlos Canto";
grpRight.helpTip = "Not tested with a ridiculous amount of pages";
//------------------------ get the PDF file
btnFile.onClick = function(){
txtFile.text = ""; // clear previous File path if any
btnOk.enabled = false; // disable the Ok button
var fileRef = File.openDialog ("Select PDF...", "*.pdf"); // get the file
fileRef = new File(fileRef.fsName.replace("file://","")); // Lion fix by John Hawkinson
if(fileRef!= null && fileRef.exists) // check if it is valid file, it should be, unless after clicking a file, the name gets edited
{
txtFile.text = fileRef.fsName; // show the file Path here
btnOk.enabled = true; // enable the Ok button
txtTo.active = true; // move focus to change the last page to open
}
}
//------------------------
btnOk.onClick = function(){
doSomething(); // call main function.
win.close(); // close when done
}
//------------------------ on leaving this text, check again if file exist, in case file path is typed instead of clicking the File...button
txtFile.onDeactivate = function(){
//alert("on deactivate")
var file = File(txtFile.text); // create a file based on the text edit control
if (file.exists){ // and chekc for existance, if it does
btnOk.enabled = true; // enable the Ok button
}
else { // if it does not exist
btnOk.enabled = false; // disable the Ok button
}
}
//------------------------
win.center ();
win.show();
//-------------------------END UI CODE
function doSomething() // Open each page in the range, group all art, move to a new document, then
{ // with all pages on top of each other, create artboards and move each page
// to its final own layer, own artboard.
// get first page and last page to open
$.hiresTimer; // start timer
var from = txtFrom.text;
var to = txtTo.text;
// create destination document, pdf open options, etc
app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
var fileRef = File(txtFile.text); // get file from text edit
//alert(fileRef.name)
var idoc = app.documents.add(); // add a document;
var pdfOptions = app.preferences.PDFFileOptions;
pdfOptions.pDFCropToBox = PDFBoxType.PDFBOUNDINGBOX;
var spacing = 10; // space between artboards
var arrPagesInfo = []; // to hold each PDF page name, doc size and art position
for (j=from; j<=to; j++) // open all pages in range, group art, and move the dest document
{
pdfOptions.pageToOpen = j;
// Open a file using these preferences
var pdfDoc = open(fileRef, DocumentColorSpace.RGB);
lblStatus.text = "\u00A9 2012 Carlos Canto - Opening page " + j;
win.update();
var pdfLayer = pdfDoc.activeLayer;
// add a group and group all items
var items = pdfLayer.pageItems; // get all items in layer, there's only one layer, right?
var tempGrp = pdfDoc.groupItems.add(); // to group everything in page
tempGrp.name = "Page " + j; // name the group, "Page 1", "Page 2", etc
for (i=items.length-1; i>0; i--) // group all items
{
items.move(tempGrp,ElementPlacement.PLACEATBEGINNING);
}
// get document bounds
var pdfw = pdfDoc.width;
var pdfh = pdfDoc.height;
var activeAB = pdfDoc.artboards[0];
pdfLeft = activeAB.artboardRect[0];
pdfTop = activeAB.artboardRect[1];
if (j==from)
{
firstabRect = activeAB.artboardRect;
abRect = firstabRect;
//$.writeln(abRect);
}
else
{
// TODO // x = 8498 seems to be the canvas max X position, check and make another row if a page gets to here
if ((abRect[2]+spacing+pdfw)>=8494) // if rightmost artboard position surpases the canvas size,
{
var ableft = firstabRect[0]; // position next artboard below the first one
var abtop = firstabRect[3]-spacing;
var abright = ableft + pdfw;
var abbottom = abtop - pdfh;
firstabRect = [ableft, abtop, abright, abbottom];
}
else // if we don't get to the canvas edge, position next artboard, to the right of the last one
{
var ableft = pageSpecs[3][2]+spacing; // pageSpecs[3] = abRect // abRect[2] = right position
var abtop = pageSpecs[3][1]; // abRect[1] = top position
var abright = ableft + pdfw;
var abbottom = abtop - pdfh;
}
abRect = [ableft, abtop, abright, abbottom];
}
// get this group position relative to top/left
var deltaX = tempGrp.left-pdfLeft;
var deltaY = pdfTop-tempGrp.top;
// make an array to hold each page Name, width, height, deltaX, deltaY
pageSpecs = [tempGrp.name, deltaX, deltaY,abRect]; // pageSpecs holds last page info, it gets overwritten as we add pages
arrPagesInfo.unshift(pageSpecs); // unshift to make first page, the last in the array
// duplicate grouped page 1 onto dest document
newItem = tempGrp.duplicate( idoc,ElementPlacement.PLACEATBEGINNING);
// close current PDF page
pdfDoc.close (SaveOptions.DONOTSAVECHANGES);
} // end for all pages to open
// Stage 2, create layers and artboards for each PDF page (group) and reposition
// loop thru the groups, add artboards for each and reposition
var ilayer = idoc.layers[idoc.layers.length-1]; // the one layer so far
for(k=arrPagesInfo.length-1; k>=0; k--) // last item in the array holds the first PDF page info
{
// add new layer and new AB
var newAB = idoc.artboards.add(arrPagesInfo
var newLayer = idoc.layers.add();
newLayer.name = arrPagesInfo
// reposition group relative to top/left
var igroup = ilayer.groupItems
igroup.left = newAB.artboardRect[0]+arrPagesInfo
igroup.top = newAB.artboardRect[1]-arrPagesInfo
igroup.move(newLayer,ElementPlacement.PLACEATEND);
// add new artboard to the left of existing one
lblStatus.text = "Repositioning page " + k;
win.update();
}
idoc.artboards[0].remove();
ilayer.remove();
app.userInteractionLevel = UserInteractionLevel.DISPLAYALERTS;
var time = $.hiresTimer/1000000; // end timer
lblStatus.text = "Copyright 2012 \u00A9 Carlos Canto";
alert(arrPagesInfo.length +" pages opened in " + time.toFixed(2) + " seconds" ); // 35 pages opened in 98-99 seconds
//$.writeln(time);
}// end doSomething Function
Copy link to clipboard
Copied
You can't choose a page to open with the place command its first one ONLY… So the PDF needs to be split to pages first…
Copy link to clipboard
Copied
Thats incorrect Mark,
If you choose a PDF to place it gives you a dialog box to select whichever page you want to place...
Copy link to clipboard
Copied
I will re-phrase… You can't choose a page to open with the place command using script its first one ONLY… So the PDF needs to be split to pages first…
Copy link to clipboard
Copied
Ok, i see what you are saying...
Copy link to clipboard
Copied
Mark is right, I did try to place when I was developing the script...and found out it was not possible, so we're stuck with opening the pdf for now.
Copy link to clipboard
Copied
My fault wasn't clear the first time. What you are looking at is the extra work Carlos did because the app doesn't ( a work around )… Placing is the much faster route… The guide is a little misleading with PDF open/place options as a few of use have found out… Not all that is in the app GUI makes it to script… The closest to that would be Indesign and by some distance too…
Copy link to clipboard
Copied
Oh i really like this script the way it is and 8 times out of 10 it will work perfectly and awesomely for what i need.
Of course i want to open the 182 page MUTCD catalog of signs in illustrator but most of them have text that is not converted to outlines.
I can open the 1 i want by placing them but anyways longer story....
Copy link to clipboard
Copied
sorry about that...that's the way it is, Illustrator is abandoned compared to other CS apps, I think there's no budget for it (I like to think Adobe doesn't make enough money to put some more resources to fix what's broken and provide "real" updates)...and Illustrator scripting is....well...very very limited.
Copy link to clipboard
Copied
It's possible to place MultiPagePDF into illustrator by VBS, and i think also by AS. With CS6 is aslo possible by JS.
The core steps are:
1. record an action, the only thing need to record is insert menuitem - "Edit>Paste", name the actionset as "Do Action", name the action as "Paste PDF".
2. before run the script, copy you PDF file into clipboard,
3. if you want to modify the import seetings, juse import PDF file manualy with all you seetings, then you can delete the imported item.
4. run this script.
#target illustrator
#targetengine 'main'
var VB = VB || {
vbs: ['Set appRef = CreateObject("Illustrator.Application")', 'appRef.DoScript "Paste PDF", "Do Action"', 'Set appRef = Nothing'].join('\n'),
tmpFile: function FN( /*?str*/ s) {
FN.file && FN.file.remove();
FN.file = null;
if (!s) return null;
return FN.file = (function (fx) {
fx = new File('' + fx);
if (!fx.open("w")) return null;
fx.write(s);
fx.close();
return fx;
})(Folder.temp + '/_' + (+new Date) + '.vbs');
}
},
f = VB.tmpFile(VB.vbs),
u, //undefined shortcut
w = new Window('palette', u, u);
w.margins = [0, 0, 0, 0];
w.add("button", u, "Import PDF").addEventListener('click', function () {
var Prefs = app.preferences;
this.visible = 0;
if (ScriptUI.environment.keyboardState.ctrlKey) {
Prefs.setIntegerPreference('plugin/PDFImport/PageNumber', 1);
w.close(0);
VB.tmpFile();
return
}
p = Prefs.getIntegerPreference('plugin/PDFImport/PageNumber');
Prefs.setIntegerPreference('plugin/PDFImport/PageNumber', p + 1);
f.execute();
this.visible = 1;
});
w.onShow = f.execute(); //脚本启动自动置入第一页
w.show();
Here is the original link.
And also check my version of open MultiPagePDF
Copy link to clipboard
Copied
Moluapple, I see you write your VB string to file and then execute that in order to run your action… Im 95% certain this can't be done with AppleScript… The syntax needs to be complied either by the editor or shellscript… Its a shame AI does NOT have ID's doScript() which will run VB or AppleScript… Personally I would prefer to split the PDF as background process to temp folder and place those… Where did you find reference to that plugin prefs? I have not seen that before…
Copy link to clipboard
Copied
Mark what is the easist way to split a pdf into individual pdf pages?
Also mark on the Original Link its in chinesebut when you translate it the guy writing the article talks about the plugin prefs command..
Copy link to clipboard
Copied
Hi, Mark,
Im 95% certain this can't be done with AppleScript… The syntax needs to be complied either by the editor or shellscript…
Your mean even use File.execute() to run a pre-complied AppleScript file is also impossible? Otherwise is possible isn't it?
Where did you find reference to that plugin prefs? I have not seen that before…
I found this in the AIPrefs file, and I should say I was inspired by the "switchRulerOriginToCS4nCS5.jsx" script written by Carlos.
Yes, the AIPrefs file is exactly the REFERENCE for app.preferences.
Personally I would prefer to split the PDF as background process to temp folder and place those…
I think the total filesize of the splited PDFs is large then a single PDF, and keep one file only is a much clean workflow.