Skip to main content
Participant
February 16, 2011
Answered

Data Merge export to single pdf and auto naming

  • February 16, 2011
  • 1 reply
  • 1345 views

Hi All,

I have a question that I have been searching for the answer on here for a few hours...

I am needing to make up around 200 certificates

Each certificate will have 3 text boxes, Im using Data merge to fill these fields.

My question has 2 parts:

Part 1 of my question is -  What script can I use to export these 200 certificates to seperate pdfs

Part 2 of my question is - What script can I utilise to make use of one of the fields which will be (name) and use that to name the file when it is exported?

Much appreciated...

Darren.

This topic has been closed for replies.
Correct answer Loic.Aigon

Hi,

You may want to try two scripts I wrote :

Export single PDFs file :

http://www.scriptopedia.org/index.php?post/custompdfexport.jsx.html

use some csv row to rename a bunch of pdf files accordingly:

var csv=File(Folder.desktop+"/fichier.csv");

var myPDFFolder = Folder(Folder.desktop+"/pdfs");

var names = getNamesFromCSV(csv);

if(csv.exists && myPDFFolder.exists){
   
var files = myPDFFolder.getFiles();
   
if(files.length==names.length){
       
for(var i=0; i<files.length; i++){
            files
[i].rename(files[i].parent+"/"+names[i]+".pdf");
       
}
   
}
}
       
function getNamesFromCSV(csv){
   
if(csv.exists){
        csv
.open('r');
       
var content = csv.read();
       
var namesArr = [];
        content
=content.split("\n");
       
for(var j=0; j<content.length; j++){
            namesArr
.push(content[j].match(/^(.[^\n]+)/i)[1]);
       
}
           
        csv
.close();
       
return namesArr.slice(1,namesArr.length);
   
}
   
return false;
}

This code was intented to use the first row item as the basis for renaming the PDF files. Adapt it to your own needs.

Hope it helps,

Loic

http://www.loicaigon.com

http://www.scriptopedia.org

1 reply

Loic.Aigon
Loic.AigonCorrect answer
Legend
February 18, 2011

Hi,

You may want to try two scripts I wrote :

Export single PDFs file :

http://www.scriptopedia.org/index.php?post/custompdfexport.jsx.html

use some csv row to rename a bunch of pdf files accordingly:

var csv=File(Folder.desktop+"/fichier.csv");

var myPDFFolder = Folder(Folder.desktop+"/pdfs");

var names = getNamesFromCSV(csv);

if(csv.exists && myPDFFolder.exists){
   
var files = myPDFFolder.getFiles();
   
if(files.length==names.length){
       
for(var i=0; i<files.length; i++){
            files
[i].rename(files[i].parent+"/"+names[i]+".pdf");
       
}
   
}
}
       
function getNamesFromCSV(csv){
   
if(csv.exists){
        csv
.open('r');
       
var content = csv.read();
       
var namesArr = [];
        content
=content.split("\n");
       
for(var j=0; j<content.length; j++){
            namesArr
.push(content[j].match(/^(.[^\n]+)/i)[1]);
       
}
           
        csv
.close();
       
return namesArr.slice(1,namesArr.length);
   
}
   
return false;
}

This code was intented to use the first row item as the basis for renaming the PDF files. Adapt it to your own needs.

Hope it helps,

Loic

http://www.loicaigon.com

http://www.scriptopedia.org

Smart_77Author
Participant
February 18, 2011

Thanks alot