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

6.3K

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
People's Champ ,
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
New Here ,
Aug 10, 2023 Aug 10, 2023

Copy link to clipboard

Copied

Hi Mike,

Your work is greatly appreciated! However, I encounter an JavaScript Error in line 152 when running the script

Source:  doc.exportFile(ExportFormat.PDF_TYPE, File(mySelectedFolder +"/"+ pdf_name + ".pdf"), false, export_preset);

 

Can you please advise?

 

 

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 ,
Aug 10, 2023 Aug 10, 2023

Copy link to clipboard

Copied

Hello @Grafiker S&M 

 

Can you post a screen shot of the error message and the script you're using if you made any modifications.

 

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 ,
Aug 29, 2023 Aug 29, 2023

Copy link to clipboard

Copied

Hi @Mike Bro , I got the same error. I didn't make any modifications to the script.

 

I do have hyperlinks to images on my file.

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 ,
Aug 29, 2023 Aug 29, 2023

Copy link to clipboard

Copied

@Daniella31935498e168 
Purchase Collins plugin script, it works great and is very flexible. I manage 30 files x 56 sales names and contacts. I also use it for business card layouts. I update my spreadsheet, export from google sheets, change extension to txt, open indesign, update link and datamerge with Collin's tool. I can custom name, hyperlinks work fine... it is a lifesaver and wasn't expensive. Hope this helps. 

 

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 ,
Aug 29, 2023 Aug 29, 2023

Copy link to clipboard

Copied

Thank you!

I did get Colin's script, the free version, but it doesn't work for what I want. 

I have a multiple to multiple relationship with my records (multiple fund numbers and multiple individual IDs) and I want to combine them by IDs, with the resulting product being all the funds assigned to a specific ID in a single pdf.

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 ,
Aug 29, 2023 Aug 29, 2023

Copy link to clipboard

Copied

The paid version is a lot more flexible. Reach out to him to see if it can
do what you want.

Thanks,
Tracy O'Shaughnessy

Branding & Beyond
Building websites & brands that get you noticed & hired
p: 512 670-7770
m: 512 825-4643
e: tracy@brandingbeyond.com
LinkedIn: http://tracylinkedin.com

The best compliment we could receive is a referral. Is there anyone you
think would benefit from our services, let us know… or better yet, let them
know!

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
Community Expert ,
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

If the answer wasn't in my post, perhaps it might be on my blog at colecandoo!

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
Community Expert ,
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

 

If the answer wasn't in my post, perhaps it might be on my blog at colecandoo!

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