Export to PDF with MetaData
I have a script that exports each individual page to a pdf with each page having it's own metadata.
It works fine except for on small thing.
The keyword array looks like this in the final PDF.
; "Keyword1, Keyword2, Keyword3
"
How do I get rid of the semicolon and quotes?
Thanks!
main ();
function main() {
var curDoc = app.activeDocument;
var docPath = app.activeDocument.filePath;
// Array of paragraph Style names
var paraStyleNames = ["meta-title", "meta-alt", "meta-subject"]; // insert here your para names !
var missingParaStyles = [];
// check, if the styles are valid
for ( var p = 0; p < paraStyleNames.length; p++ ) {
var curName = paraStyleNames
;
// if the style is missing, push it to the array
if ( !curDoc.paragraphStyles.itemByName(curName).isValid ) {
missingParaStyles.push( curName );
}
}
var folderPath = new Folder(docPath + "/" + curDoc.name.replace(/\.indd$/,"") + "-pdf");
if (!folderPath.exists)
folderPath.create();
// loop through all pages
for ( var i = 0; i < curDoc.pages.length; i++ ) {
// the current page
var curPage = curDoc.pages;
// Page number
var pName = (curPage.name < 10) ? ("0" + curPage.name) : curPage.name;
// controls the loop
var controller = true;
// all paragraphs on the current page
var allPageParas = curPage.textFrames.everyItem().paragraphs.everyItem().getElements();
// loop through all paragraphs and check, if one has the para style applied
for ( var p = 0; p < allPageParas.length; p++ ) {
if ( !controller ) break;
// the current para
var curPara = allPageParas
;
// loop through the styles
for ( var n = 0; n < paraStyleNames.length; n++ ) {
if ( curPara.appliedParagraphStyle.name == "meta-title" ) {
var docTitle = curPara.contents;
} // end if
if ( curPara.appliedParagraphStyle.name == "meta-alt" ) {
var docAlt = curPara.contents;
} // end if
if ( curPara.appliedParagraphStyle.name == "meta-subject" ) {
var docKeywords = curPara.contents;
var docDirectory = Array(docKeywords);
} // end if
} // end for paraStyleNames
} // end for allPageParas
for (var i = 0; i < docDirectory.length; i++) {
docDirectory = docDirectory.replace(/; /g, "");
}
var filePath = folderPath + "/" + curDoc.name.replace(/\.indd$/,"") + "-" + pName + ".pdf";
var myFile = File( filePath );
var pdfPreset = "Labels";
with (curDoc.metadataPreferences){
documentTitle = docTitle;
author = curDoc.name.replace(/\.indd$/,"") ;
description = docAlt;
contentCreator = curDoc.name.replace(/\.indd$/,"") + "-" + pName ;
keywords = docDirectory;
}
with (app.pdfExportPreferences) {
pageRange = curPage.name;
viewPDF = false }
curDoc.exportFile( ExportFormat.PDF_TYPE, myFile, false, pdfPreset );
}
} // end for > main