Hi,
I have this script which is below which I need to split a 300 page document which I need to split into 50 documents and name them with a csv file provided. I have the excel spreadsheet with column headed "filename" with 50 file names.
When I select the data file to import after being asked to enter text at start of filename etc I see the message 'No filenames found - using "file-XX.pdf". Press Escape after continuing to cancel.'
and then the error -
RaiseError: The file may be read-only, or another user may have it open. Please save the document with a different name or in a different folder.
Doc.extractPages:83:Console undefined:Exec
===> The file may be read-only, or another user may have it open. Please save the document with a different name or in a different folder.
file-0
I have checked the number of rows in the csv with the one which i created the merge in Indesign and it is the same. I have also tried using google docs spreadsheet but acrobat doesnt recognise the URL.
Thank you.
script I am using -
var CSV = function (data, delimiter) {
var _data = CSVToArray(data, delimiter);
var _head = _data.shift();
return {
length: function () {return _data.length;},
adjustedLength: function () {return _data.length - 1;},
getRow: function (row) {return _data[row];},
getRowAndColumn: function (row, col) {
if (typeof col !== "string") {
return _data[row][col];
} else {
col = col.toLowerCase();
for (var i in _head) {
if (_head[i].toLowerCase() === col) {
return _data[row][i];
}
}
}
}
};
};
function CSVToArray( strData, strDelimiter ){
strDelimiter = (strDelimiter || ",");
var objPattern = new RegExp(
(
// Delimiters.
"(\\" + strDelimiter + "|\\r?\\n|\\r|^)" +
// Quoted fields.
"(?:\"([^\"]*(?:\"\"[^\"]*)*)\"|" +
// Standard fields.
"([^\"\\" + strDelimiter + "\\r\\n]*))"
),
"gi"
);
var arrData = [[]];
var arrMatches = null;
while (arrMatches = objPattern.exec( strData )){
var strMatchedDelimiter = arrMatches[ 1 ];
if (
strMatchedDelimiter.length &&
(strMatchedDelimiter != strDelimiter)
){
arrData.push( [] );
}
if (arrMatches[ 2 ]){
var strMatchedValue = arrMatches[ 2 ].replace(
new RegExp( "\"\"", "g" ),
"\""
);
} else {
var strMatchedValue = arrMatches[ 3 ];
}
arrData[ arrData.length - 1 ].push( strMatchedValue );
}
return( arrData );
}
function isInt(n) {
return typeof n === "number" && n % 1 == 0;
}
var prepend = app.response("Enter any text to go at the START of each filename:");
var append = app.response("Enter any text to go at the END of each filename:");
var pathStr = app.response("If the PDFs should be saved in a sub folder, enter the relative path here:", "", "pdf/");
this.importDataObject("CSV Data");
var dataObject = this.getDataObjectContents("CSV Data");
var csvData = new CSV(util.stringFromStream(dataObject, 'utf-8'), ',');
var pagesPerRecord = this.numPages / csvData.length();
if (isInt(pagesPerRecord)) {
for (var i = 0; i < this.numPages; i ++) {
var pageStart = i*pagesPerRecord;
var pageEnd = (i+1)*pagesPerRecord - 1;
var recordIndex = (i + pagesPerRecord) / pagesPerRecord;
var filename = csvData.getRowAndColumn(i, "filename");
if (!filename) {
app.alert('No filenames found - using "file-XX.pdf". Press Escape after continuing to cancel.');
filename = "file-" + i;
}
var settings = {nStart: pageStart, nEnd: pageEnd, cPath: pathStr+prepend+filename+append+'.pdf'};
this.extractPages(settings);
}
} else {
var message = "The number of pages per row is not an integer (" + pagesPerRecord;
message += ", " + this.numPages + " pages, " + csvData.length() + " rows).";
}
(which I found from another forum, but noone has answered me and I am desperate)
Thank you in advance.