Hello Everyone, i need some help here. I'm a JS noob and have no idea what i am doing. I managed to put a script together that is made of several scripts.
Everything works fine until the very end.
I need to export my ai. file to 3 pdf files named:
filename.pdf
filename_K.pdf (converted to outlines)
filename_P.pdf (converted to curves, without layers)
The thing is that i can't find a way to export my third pdf without layers. Sometimes it does everything right, but sometimes it doesent.
Can someone help me with this?
Here my currents script:
#target illustrator
function Filename(){
var doc = app.activeDocument;
var parentPath = Folder(File(doc.fullName).parent);
var opts = new PDFSaveOptions();
opts.pDFPreset = "Polpharma (cartons)";
doc.saveAs(File(parentPath + "/"), opts);
};
Filename();
#target illustrator
function outlineDocText( ) {
if ( app.documents.length == 0 ) return;
var docRef = app.activeDocument;
recurseLayers( docRef.layers );
};
outlineDocText();
function recurseLayers( objArray ) {
for ( var i = 0; i < objArray.length; i++ ) {
// Record previous value with conditional change
var l = objArray[i].locked;
if ( l ) objArray[i].locked = false;
// Record previous value with conditional change
var v = objArray[i].visible;
if ( !v ) objArray[i].visible = true;
outlineText( objArray[i].textFrames );
// Recurse the contained layer collection
if ( objArray[i].layers.length > 0 ) {
recurseLayers( objArray[i].layers )
}
// Recurse the contained group collection
if ( objArray[i].groupItems.length > 0 ) {
recurseGroups( objArray[i].groupItems )
}
// Return to previous values
objArray[i].locked = l;
objArray[i].visible = v;
}
};
function recurseGroups( objArray ) {
for ( var i = 0; i < objArray.length; i++ ) {
// Record previous value with conditional change
var l = objArray[i].locked;
if ( l ) objArray[i].locked = false;
// Record previous value with conditional change
var h = objArray[i].hidden;
if ( h ) objArray[i].hidden = false;
outlineText( objArray[i].textFrames );
// Recurse the contained group collection
if ( objArray[i].groupItems.length > 0 ) {
recurseGroups( objArray[i].groupItems )
}
// Return to previous values
objArray[i].locked = l;
objArray[i].hidden = h;
}
};
function outlineText( objArray ) {
// Reverse this loop as it brakes the indexing
for ( var i = objArray.length-1; i >= 0; i-- ) {
// Record previous value with conditional change
var l = objArray[i].locked;
if ( l ) objArray[i].locked = false;
// Record previous value with conditional change
var h = objArray[i].hidden;
if ( h ) objArray[i].hidden = false;
var g = objArray[i].createOutline( );
// Return new group to previous Text Frame values
g.locked = l;
g.hidden = h;
}
};
#target illustrator
function Filename_K(){
var doc = app.activeDocument;
var parentPath = Folder(File(doc.fullName).parent);
var opts = new PDFSaveOptions();
opts.pDFPreset = "Polpharma (cartons)";
PDFSaveOptions.acrobatLayers = false;
doc.saveAs(File(parentPath + "/" + doc.name.replace(/\.\w+$/, "_K.pdf")), opts);
};
Filename_K();
#target illustrator
function Filename_P(){
var doc = app.activeDocument;
var parentPath = Folder(File(doc.fullName).parent);
var opts = new PDFSaveOptions();
opts.pDFPreset = "Polpharma (cartons)";
doc.saveAs(File(parentPath + "/" + doc.name.replace("_K.pdf", "_P.pdf")), opts);
};
Filename_P();
Thank you for your time!