• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Unique file names

Explorer ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

Hi 
 
I have to produce 500+ certificates that are all personalised, and then save them as individual PDFs with unique filenames that are not connected or sequential. 
 
Adding the data to the Indesign pages is covered, as is the PDF 'ing – it's the filename thing that I'm struggling with (it doesn't appear in the artwork either).
 
All I can think of is to 'cut n paste' the file name from the master.xls one by one.
 
I'm hoping there is some kind of script? Any ideas welcomed on making this process more streamlined or efficient?
 
thx
TOPICS
How to , Import and export , Scripting

Views

1.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Advisor , Apr 13, 2021 Apr 13, 2021

Hello Dano,

 

If you have data in your master.xls that you can also have as part of your merge process see the steps below....

 

1. Start off by creating a Paragraph style named "PDF_name"

2. Create a text box in the slug area with a portion of the box within the page bounds and assign the Paragraph style "PDF_name"

3. Assign the field from the data source for the pdf naming

4. Create and save the Merged document, run the script to export the pdfs


The below script will export pdfs named by the contents

...

Votes

Translate

Translate
Community Expert , Mar 20, 2024 Mar 20, 2024
quote

Fixing the typo does not solve the issue though... 
I would greatly appreciate you help.


By @gijsd18053393

 

As per the screenshot - you have wrong quotes:

RobertTkaczyk_0-1710948544139.png

 

copy the one from the rectangle instead of the around [...]:

RobertTkaczyk_1-1710948595510.png

 

Votes

Translate

Translate
Advisor ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

Hello Dano,

 

If you have data in your master.xls that you can also have as part of your merge process see the steps below....

 

1. Start off by creating a Paragraph style named "PDF_name"

2. Create a text box in the slug area with a portion of the box within the page bounds and assign the Paragraph style "PDF_name"

3. Assign the field from the data source for the pdf naming

4. Create and save the Merged document, run the script to export the pdfs


The below script will export pdfs named by the contents of the text box useing the Paragraph style named "PDF_name from each page

 

 

var doc = app.documents[0];
   var myResult = {};
   var allStoriesArray = app.documents[0].stories.everyItem().getElements();
   
    for(var n=0; n<allStoriesArray.length; n++){
    var currentStory =  allStoriesArray[n];
    var textContainersLength = currentStory.textContainers.length;
    var lastFrameOfStory = currentStory.textContainers[textContainersLength-1];
    var objToCheck = lastFrameOfStory;
    
    if(lastFrameOfStory.constructor.name == "TextPath")
    objToCheck = lastFrameOfStory.parent
    
    if(currentStory.overflows && objToCheck.itemLayer.visible && objToCheck.parentPage != null)
    myResult[objToCheck.parentPage.name] = objToCheck.parentPage.name;
    }
    
    var pageList = new Array;
    for(var a in myResult)
    pageList.push(a);
        
    pageList.sort(function(a,b) {return a-b});
    
    if(pageList.length > 0){
    alert("Error!\nDocument contains overset text on page(s): \r" + pageList);
    exit();
    }
    
   var mLinks = doc.links; 
   for(var i = 0; i < mLinks.length; i++){ 
   if ((mLinks[i].status == LinkStatus.LINK_MISSING || mLinks[i].status == LinkStatus.LINK_OUT_OF_DATE) && checkIfOnPage(mLinks[i].parent.parent) && mLinks[i].parent.parent.itemLayer.visible == true ){ 
   alert("Error!\nThis document contains links to files that are missing or modified, use the links panel to fix the problem(s) and try again!");  
   exit();
     
          }
     }

function checkIfOnPage(mItem){
    
    var _OldZeroPoint = app.activeDocument.zeroPoint;     
    app.activeDocument.zeroPoint = [0,0];     
    var _Width =app.activeDocument.documentPreferences.pageWidth;     
    var _Height=app.activeDocument.documentPreferences.pageHeight;     
    var _Bounds = mItem.geometricBounds;
    if ((_Bounds[3] < 0)  || (_Bounds[1] > _Width) || (_Bounds[0] > _Height) || (_Bounds[2] < 0)){
        return false     
    }else{   
        return true 
    }
    app.activeDocument.zeroPoint =_OldZeroPoint;     
}

    function myGetPageNames(){
        var myPageNames = new Array;
        for(myCounter = 0; myCounter < app.activeDocument.pages.length; myCounter ++){
            myPageNames.push(app.activeDocument.pages.item(myCounter).name);
      }
        return myPageNames;
    }

       //Function Returns pdf_name for Selected Pages
      function getTextFromPageUsingParagraphStyle(myPage){
     
     if (doc.paragraphStyles.itemByName("PDF_name") == null) {
      alert ('Error!\nThe Paragraph Style "PDF_name" does not exist or is Labeled Incorrectly.');
      exit();
}
          app.findTextPreferences = app.changeTextPreferences = null;   
          app.findTextPreferences.appliedParagraphStyle = "PDF_name";  
  
          var myTextframes = myPage.textFrames;  
          var pdf_name = null;
          
          for (y=0; y < myTextframes.length; y++){
            try {
              var mySearchResult = myTextframes[y].findText();
                if (mySearchResult.length > 0){  
                 pdf_name = mySearchResult[0].contents; 
                   break;  
                  }
             }catch (e){
        }
            } 
  
           return pdf_name;      
  } 

//Dialog/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

var mySelectedFolder = Folder.selectDialog ("Select a Folder");
if(mySelectedFolder != null){

}else{
exit();
}

var myDialog = app.dialogs.add({name:"DataMerge 1-Page HR Pdf Exporter", canCancel:true});
with (myDialog){
with (dialogColumns.add()){

with (dialogRows.add())
staticTexts.add({staticLabel:"Page Range Options", minWidth:25});
with (borderPanels.add()){
var myradiogroup1 = radiobuttonGroups.add();
with (myradiogroup1){
var myyesradiobutton1 = radiobuttonControls.add({staticLabel:'Export All Pages', checkedState:true});
var mynoradiobutton1 = radiobuttonControls.add({staticLabel:'Export Select Pages'});    
staticTexts.add({staticLabel:"", minWidth:75});  
}
}
}
}
if (myDialog.show() == true){

var SelectedPages = myradiogroup1.selectedButton; 

}else{
}
myDialog.destroy();

//All Pages//////////////////////////////////////////////////////////////////////////////////////////////////

 if (SelectedPages == false){
     
for(var p = 0; p < app.documents[0].pages.length; p++) {  
         var frames = app.documents[0].pages[p].textFrames;  
         var pdf_name = null;  
      
         for(var i = 0; i < frames.length; i++) { 
          try { 
              if(frames[i].paragraphs[0].appliedParagraphStyle.name == 'PDF_name') {  
                   pdf_name = frames[i].paragraphs[0].contents;  
                   break;  
              }
            }catch (e){
          }  
        }
     
    if (pdf_name == null) { 
    alert ('Error!\nThe Paragraph Style "pdf_name" is not applied to one or more of the pages or is Labeled Incorrectly.');
    exit();
    }
      
      if(pdf_name != null) {  
 
    }    

         app.pdfExportPreferences.pageRange = app.documents[0].pages[p].name; 

         var export_preset = app.pdfExportPresets.item("[High Quality Print]");
         
         doc.exportFile(ExportFormat.PDF_TYPE, File(mySelectedFolder +"/"+ pdf_name + ".pdf"), false, export_preset);
  }
  alert("Done Exporting Pdf's!");
}

//Selected Pages/////////////////////////////////////////////////////////////////////////////////////////////

 if (SelectedPages == true){
     
     for(var p = 0; p < app.documents[0].pages.length; p++) {  
         var frames = app.documents[0].pages[p].textFrames;  
         var pdf_name = null;  
      
         for(var i = 0; i < frames.length; i++) { 
          try { 
              if(frames[i].paragraphs[0].appliedParagraphStyle.name == 'PDF_name') {  
                   pdf_name = frames[i].paragraphs[0].contents;  
                   break;  
              }
            }catch (e){
          }  
        }
     
     if (pdf_name == null) { 
    alert ('Error!\nThe Paragraph Style "PDF_name" is not applied to one or more of the pages or is Labeled Incorrectly.');
    exit();
      }
      if(!pdf_name) continue;
      }
  
   var myPageNames = myGetPageNames();

    var selectPgs = new Window ("dialog", "Select Page#'s To Export");
    var pgGroup = selectPgs.add("group");
    pgGroup.orientation = "column";
    pgGroup.alignChildren = "center";
    pgGroup.add("statictext", undefined, "Export Single Page pdf's");
    var pgsList = pgGroup.add("listbox", [-25, 0, 170, 246], myPageNames, {multiselect: true});
    var selectedpgsList = []; 
    for (var i = 0; i < pgsList.items.length; i++){selectedpgsList[-1] = pgsList.items[i];}
    pgsList.selection = selectedpgsList; 

    var btn = selectPgs.add("group");
    btn.orientation = "row";
    btn.alignment = ["right", "top"];
    var okBtn = btn.add ("button", undefined, "OK", {name:"OK"});
    var cancelBtn = btn.add ("button", undefined, "Cancel", {name:"Cancel"});

    var result = selectPgs.show();
    if(result == 1){
    }  
    else if (result== 2){  
    exit(0);  
    } 
    var pagelist = [];
    if(pgsList.selection == null){
     alert ("Error!\nNo page#'s were selected.")
     exit(); 
     }else{
         
      for (var i=0; i<pgsList.selection.length; i++) {
      pagelist.push(pgsList.selection[i].text);
        }
     }
 
          for (i = 0; i < doc.pages.length; i++) {
            if (String(pagelist).match("\\b"+doc.pages[i].name+"\\b")){ 

            var pdf_name = getTextFromPageUsingParagraphStyle(doc.pages[i]);
          
            app.pdfExportPreferences.pageRange = doc.pages[i].name;
           
            var export_preset = app.pdfExportPresets.item("[High Quality Print]");

           doc.exportFile(ExportFormat.PDF_TYPE, File(mySelectedFolder +"/"+ pdf_name + ".pdf"), false, export_preset);
         }
      }
      alert("Done Exporting Pdf's!");
    }

 

 

Regards,

Mike

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

That's awesome Mike! Thanks for sharing!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

Mike,

 

Thank you so much, getting there.

 

One more question how do I get the above code saved as a .jsx file to place in my Scripts Panel?

 

Cheers

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

Just copy the code and paste into a text editor as plain text. Save that file as [myfilename].jsx and put it in your InDesign scripts folder.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

Guys,

 

Just did a test run on 40 pages and it worked. 

Brilliant.

 

Thank you so, so much.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 22, 2023 Jan 22, 2023

Copy link to clipboard

Copied

Can you create a quick tutorial video? 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 24, 2023 Feb 24, 2023

Copy link to clipboard

Copied

How do I set the PDF as a PDF (print) with crop marks and bleed?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Feb 24, 2023 Feb 24, 2023

Copy link to clipboard

Copied

Hello @Luke24864044f9cy,

Change the line below by changing "[High Quality Print]" to "your preset name"

 //Change this line:
var export_preset = app.pdfExportPresets.item("[High Quality Print]");

//Change to:
var export_preset = app.pdfExportPresets.item("your preset name here");

 Regards,

Mike

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 26, 2024 Mar 26, 2024

Copy link to clipboard

Copied

LATEST

Hi Mike. Thank you for the script. Was hoping to see if we could revise the script for .png file format instead?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 20, 2024 Mar 20, 2024

Copy link to clipboard

Copied

Hey Thanks for this script and explenation.
I've run though all the steps but I get an error when running the script. I'm new to this and don't know what to do with this error. 
Error number: 8
Error string: Syntax error
Line: 1
Source: {\rtf1\ansi\ansicpg1252\cocoart2759
Offending Text: \

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 20, 2024 Mar 20, 2024

Copy link to clipboard

Copied

quote

Hey Thanks for this script and explenation.
I've run though all the steps but I get an error when running the script. I'm new to this and don't know what to do with this error. 
Error number: 8
Error string: Syntax error
Line: 1
Source: {\rtf1\ansi\ansicpg1252\cocoart2759
Offending Text: \


By @gijsd18053393

 

You need to copy and paste code of the script into a Notepad - and save as PlainText - it looks like you've saved it as RTF...

 

▒► ID-Tasker / ID-Tasker Server - work smart not hard ◄▒

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 20, 2024 Mar 20, 2024

Copy link to clipboard

Copied

Hey thanks for your feedback! Greatly appreciate the speed on that.
I've made it a plain text file and rename .jsx and placed it in the correct folder. 
Now I get an error where the export preset needs to be filled. 
I've used:

 var export_preset = app.pdfExportPresets.item(“[Smalles File Size]”);
         
         doc.exportFile(ExportFormat.PDF_TYPE, File(mySelectedFolder +"/"+ pdf_name + ".pdf"), false, export_preset);


and get this error now:
Screenshot 2024-03-20 at 15.57.20.png
 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 20, 2024 Mar 20, 2024

Copy link to clipboard

Copied

Spotted the typo there, sorry! 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 20, 2024 Mar 20, 2024

Copy link to clipboard

Copied

Fixing the typo does not solve the issue though... 
I would greatly appreciate you help.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 20, 2024 Mar 20, 2024

Copy link to clipboard

Copied

quote

Fixing the typo does not solve the issue though... 
I would greatly appreciate you help.


By @gijsd18053393

 

As per the screenshot - you have wrong quotes:

RobertTkaczyk_0-1710948544139.png

 

copy the one from the rectangle instead of the around [...]:

RobertTkaczyk_1-1710948595510.png

 

▒► ID-Tasker / ID-Tasker Server - work smart not hard ◄▒

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 20, 2024 Mar 20, 2024

Copy link to clipboard

Copied

Yes, you are right.
Succesfully exported 670 uniquely named pdf's.
Great appreciate your effort, please forgive my ignorence as I'm new to this.

Thanks allot!  

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 20, 2024 Mar 20, 2024

Copy link to clipboard

Copied

@gijsd18053393 

 

You are welcome. Happy to help.

 

▒► ID-Tasker / ID-Tasker Server - work smart not hard ◄▒

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines