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

How: DataMerge->Export as individual PDFs-> automatically name each PDF using PDF dynamic fields

Community Beginner ,
Nov 29, 2020 Nov 29, 2020

Copy link to clipboard

Copied

Hello ASC - 

 

I find myself under pressure to create a few thousand COVID test results per day, with great urgency, using the excel output file of a molecular biology lab that does the work and needs to have it conveyed in a special PDF form to the government.

 

I've solved all but the last steps of the process using DataMerge and the option to save as individual PDFs I can now generate the test bulletins. But for these tests to be distributed fast to hundreds of destinations and thousands of recipients, I need to be able to implement a naming protocol and this is where I got stuck.

 

Each PDF should be named using a combination of specific fields from its content, such as test_result, pacient_name, test_date, test_place, etc

 

I am relatively new to Indesign and have reached my competency limit with this one. I can probably crack it given enough time, but time is exactly what we lack.

 

Can you help me please? 

TOPICS
How to , Import and export , Scripting

Views

2.5K

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 ,
Nov 29, 2020 Nov 29, 2020

Copy link to clipboard

Copied

Hello Catalin,

 

I will be able to help, but I have a couple of questions..........

Are each test bulletins a single page to export as a pdf? what pdf export preset do you use to export the pdfs currently.

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
Valorous Hero ,
Nov 29, 2020 Nov 29, 2020

Copy link to clipboard

Copied

Hi Catalin,

My Extract Pages script (https://www.id-extras.com/products/extract-pages/) does just what you ask for. Not free, though.

Thanks,

Ariel

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 ,
Nov 29, 2020 Nov 29, 2020

Copy link to clipboard

Copied

Hello Catalin,

 

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
New Here ,
Oct 07, 2021 Oct 07, 2021

Copy link to clipboard

Copied

Wonderful!!

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 ,
Oct 25, 2021 Oct 25, 2021

Copy link to clipboard

Copied

Hi Mike, 

How do you save the script to the Indesign Scripts folder?  Thanks! 

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 ,
Oct 25, 2021 Oct 25, 2021

Copy link to clipboard

Copied

Hello @susaneala,

 

Saving the script file: Copy the code above into the text edit app setting the format to "Make Plain Text" then save the file with the .jsx extension.

Installing the Script file: in InDesign go to (Window > Utilities > Scripts), then right-click on the User folder, inside the folder that opens there is a folder called Scripts Panel. Put the script inside that folder.

 

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 Beginner ,
Oct 25, 2021 Oct 25, 2021

Copy link to clipboard

Copied

Thanks!

 

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 ,
Apr 11, 2022 Apr 11, 2022

Copy link to clipboard

Copied

I signed up just so I could thank you for this script!

Does exactly what I needed it to and your instructions made it easy to implement. 

Thanks so much for taking the time to share with the community!\

{{insert jumping high five emoji here }}

 

-=b=-

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 ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

Hi Mike, 

 

This works perfectly, but one question, I have hyperlinks on the indesign document linked to websites for help sections. Is there any way to run this script but to make the hyperlinks clickable as well?

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 ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

Hello @Taylor25383048qtfc,

you will need to create a Adobe PDF Preset that meets your export requirements and includes Hyperlinks, then change the line of code below to match the name of your preset.

Screen Shot 2022-07-25 at 11.14.27 AM.png

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

//Change to
var export_preset = app.pdfExportPresets.item("insert the name of your preset 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 ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

This worked perfectly, thank you 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
Adobe Employee ,
Jul 25, 2022 Jul 25, 2022

Copy link to clipboard

Copied

Hi @Taylor25383048qtfc ,

 

Glad to hear that. Feel free to reach out if you have any other questions or issues. 

 

Regards

Rishabh

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 ,
Nov 29, 2020 Nov 29, 2020

Copy link to clipboard

Copied

There is various ways to do this... and various script also.
You can also use Acrobat to split them using top level bookmarks generated by InDesign.
Take a look at this article:
https://creativepro.com/data-merging-individual-records-separate-pdfs/

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
Guide ,
Oct 26, 2021 Oct 26, 2021

Copy link to clipboard

Copied

I wrote a script that does exactly this.

Screen Shot 2021-10-23 at 00.13.33.png

 it's available for FREE at https://colecandoo.com/scripts/ OR via the adobe add-ons https://exchange.adobe.com/creativecloud.details.100404.data-merge-to-single-records.html

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 ,
Oct 26, 2021 Oct 26, 2021

Copy link to clipboard

Copied

Thanks!

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 ,
Jan 19, 2022 Jan 19, 2022

Copy link to clipboard

Copied

First of all, thank you a ton!

Secondly: I can open the script, but it shows all my 32 data fields as one field i could add.

Instead of "modelName; "or "bodyName;" or any else i see a field called "modelName;bodyName;price;..."

Any idea why?

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
Guide ,
Jan 19, 2022 Jan 19, 2022

Copy link to clipboard

Copied

I've seen this once before. The script is designed to work with delimiters that are either tabs or commas, but it looks like your data is separated by semicolons - that's indicated by the line being

modelName;bodyName;price;

To be clear, while InDesign's data merge can handle semicolons, my script hasn't been updated to reflect this change.

Open your text in a texteditor such as BBedit, notepad or similar, and check the delimiters. If they are semicolons, that'll be the issue, whether your file is a csv or txt. If they are semicolons, change them to tabs using find/change; and make sure the file has a .txt extension on the end. In Data Merge, then go to Select Data Source and make sure the "show import options" dialog box is checked on and then select this data.

 

HTH

 

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 03, 2022 Mar 03, 2022

Copy link to clipboard

Copied

@Colin Flashman 

Thank You!!! 

Is there a way to add a base to the filename without it being in the csv file. I would like to set the basename in the dialog box and ADD <<name>> to the end of the file name. Like CC-NationalServices-<<name>>.pdf 

 

I have 10 files I need to export all with different file names w/ the sales persons name added to the end. I guess I could have 10 csv files or 1 with 10 extra columns for the various filenames. 

 

Or I could just be happy with what you have done and use a file renamed to prepend the pdf files. 

 

Let me know if you have a solution for this. 

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
Engaged ,
Mar 08, 2022 Mar 08, 2022

Copy link to clipboard

Copied

Hi @TracyOsh 

if you're working on macOS you could use the native Finder function to rename multiple files at once – asuming you want to add a static text to the filename: Just select the files you want to rename, right click, rename. There you can set it to add text and...

Not sure if Windows Explorer can do something like that.

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 ,
Apr 11, 2022 Apr 11, 2022

Copy link to clipboard

Copied

Hi @Jens Trost 
I ended up buying Colin's paid version of the plugin and it is fantastic. I can get the filename to be exactly what I want. The only thing I hate is that the info is not saved. You have to reenter, where to save, file type, and filename set up each and every time. If you made a mistake... do it all over again. But still, it is a massive time saver so this is just a little nit. 

 

I do use file renamers a lot but thrilled I don't have to use it at all when I use Colin's script.  

--Tracy Osh

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 24, 2022 Mar 24, 2022

Copy link to clipboard

Copied

When I click the script I get this pop up, what am i doing wrong? There are no missing fonts in this document, i checked everything,

Screen Shot 2022-03-23 at 11.45.00 AM.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 ,
Apr 11, 2022 Apr 11, 2022

Copy link to clipboard

Copied

@Melissa23305900c3yz 

I had this issue too but I did not with the paid version of the script (it's like $15 or something). I am haven't had any issues with that version of the script. My only issue is InDesign sometimes crashes completely when I select datamerge. It will crash for days... then it is fine. No idea what ID isn't happy with. Maybe it was a phase of the moon.

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 ,
Mar 11, 2022 Mar 11, 2022

Copy link to clipboard

Copied

When exporting .INDDs, is it possible to not export layers that are inactive?

 

(While i am using different Data for different languages, each language has its own layer. Only one at a time is active. It would save filesize, rendering time and CPU later on without the inactive layers)

 

Thank you! 

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 23, 2022 Mar 23, 2022

Copy link to clipboard

Copied

When I click the script I get this pop up, what am i doing wrong? There are no missing fonts in this document, i checked everything,

Screen Shot 2022-03-23 at 11.45.00 AM.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