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

[Script] Exporting PDF and JPG with custom name from Data merge

Participant ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

Hi,

First of all - sorry for a long thread. Secondly, I'm not (at all) well versed in coding, so I tip my hat to those who have put together the scripts (linked/mentioned below) that were the starting point of this. I've been trying to combine/modify these scripts to perform the tasks I require but I can't seem to get it to work.

 

What I'm trying to do: I have a multi page document that consist of about 20 pages that range from a bunch of products; double sided business card, a couple of different posters/signs and material for online marketing. These different products contain a persons name and contact details (phone number and email) along with different types of photos of the person depending on the product.

 

Some pages need to be exported as JPG and some as PDF using different presets. 

 

My current solution: I'm batching/using a bunch of scripts in a folder. These are each dedicated to a number of pages. For example (PDF), if  page 1-2 would be a business card then I would have a minimalistic script/file called "page 1 business card.jsx":

 

with(app.pdfExportPreferences){
    pageRange = "1-2"
    }
var myPDFExportPreset = app.pdfExportPresets.item("Business card preset")
app.activeDocument.exportFile(ExportFormat.pdfType, File("/c/temp/XXX business card.pdf"),
false, myPDFExportPreset);

 

For example (JPG), if page 15 needs to be exported as a high quality JPG I would save this in the batch/export script folder as "page 15 HQ jpg.jsx": 

 

var doc = app.activeDocument;

app.jpegExportPreferences.properties = {
   antiAlias: true,
   embedColorProfile: true,
   exportResolution: 300,
   // exportingSpread: true,
   jpegColorSpace: JpegColorSpaceEnum.rgb,
   jpegExportRange: ExportRangeOrAllPages.exportRange,
   jpegQuality: JPEGOptionsQuality.maximum,
   jpegRenderingStyle: JPEGOptionsFormat.baselineEncoding,
   useDocumentBleeds: false,
   simulateOverprint: false,
   pageString: "15"
}

var tempFile = File("/c/temp/XXX product.jpg");
doc.exportFile(ExportFormat.jpg, tempFile);

 

Then I would run all the scripts using this lovely script by Kasyan.

http://kasyan.ho.ua/indesign/batch_process_scripts/batch_process_scripts.html 

 

After all the scripts have been run I would have a number of files, like this: 

  • XXX business card.pdf
  • XXX Instagram 1.jpg
  • XXX Instagram 2.jpg
  • XXX Sign.pdf
  • XXX Facebook.jpg
  • XXX Poster.pdf

Then I would have to rename the XXX part manually to First name + Last name, ie "John Doe business card.pdf"

 

What I would like to do: I would like to use a script that allows me to specify the name using a paragraph style. Then I could make a non printing layer and, in this layer, create a text box in which I'd use a specific paragraph style applied to the two data merge entries "<first_name> <last name>". Then during the export, a script would find that specific paragraph style and replace the XXX.

 

My starting point is this script from: https://indesignsecrets.com/topic/export-pages-to-jpg-with-custom-filenames 

 

if (app.documents.length != 0){
var myDoc = app.activeDocument;
MakeJPEGfile();
} else {
alert("Please open a document and try again.");
}

function myPS() {
try {
return myDoc.selection[0].appliedParagraphStyle;
} catch (e) {
alert("Place cursor to text with paragraph style for filenames");
exit();
}
}

function MakeJPEGfile() {

app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.high;
app.jpegExportPreferences.exportResolution = 150;
app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.exportRange;

app.findGrepPreferences = null;
app.findGrepPreferences.appliedParagraphStyle = myPS();

var f = myDoc.findGrep();

for (var myCounter = 0; myCounter < f.length; myCounter++) {
try {
var curPage = f[myCounter].parentTextFrames[0].parentPage;
if (curPage.appliedSection.name != "") {
curPage.appliedSection.name = "";
}
var objName = f[myCounter].contents;
app.jpegExportPreferences.pageString = curPage.name;
var myFilePath = myDoc.filePath + "/" + objName + ".jpg"; //export to a folder of the current document
var myFile = new File(myFilePath);
myDoc.exportFile(ExportFormat.jpg, myFile, false);
} catch(e) {
//pasteboard?
}

 

 

I made a bastardization of this script by excluding the last part of the JPG export and inserting/modifying the simple PDF script above. And this actually works with PDF: 

 

if (app.documents.length != 0){
var myDoc = app.activeDocument;
MakeJPEGfile();
} else {
alert("Please open a document and try again.");
}

function myPS() {   
try {
return myDoc.selection[0].appliedParagraphStyle;
} catch (e) {
alert("Place cursor to text with paragraph style for filenames");
exit();
}
}


function MakeJPEGfile() {
    
   app.jpegExportPreferences.properties = {
   antiAlias: true,
   embedColorProfile: true,
   exportResolution: 150,
   // exportingSpread: true, // Uncomment if spreads
   jpegColorSpace: JpegColorSpaceEnum.rgb,
   jpegExportRange: ExportRangeOrAllPages.exportRange,
   jpegQuality: JPEGOptionsQuality.high,
   jpegRenderingStyle: JPEGOptionsFormat.baselineEncoding,
   useDocumentBleeds: false,
   simulateOverprint: false,
   pageString: "1-2"
}


app.findGrepPreferences = null;
app.findGrepPreferences.appliedParagraphStyle = myPS();

var f = myDoc.findGrep();

for (var myCounter = 0; myCounter < f.length; myCounter++) {
try {
var curPage = f[myCounter].parentTextFrames[0].parentPage;
if (curPage.appliedSection.name != "") {
curPage.appliedSection.name = "";
}
var objName = f[myCounter].contents;
app.jpegExportPreferences.pageString = curPage.name;
var myFilePath = myDoc.filePath + "/" + objName + ".jpg";
var myFile = new File(myFilePath);
//myDoc.exportFile(ExportFormat.jpg, myFile, false);

with(app.pdfExportPreferences){
    pageRange = ("1-2")
    }
var myPDFExportPreset = app.pdfExportPresets.item("business card preset");
app.activeDocument.exportFile(ExportFormat.pdfType, File(myDoc.filePath + "/" + objName + " business card.pdf"),false, myPDFExportPreset);

} catch(e) {
//pasteboard?
}
}
}

 

 

Problem: This doesn't work with JPG as the script only exports the pages where the specified "file name" paragraph style is present, in my case the first page. So, hereby kindly requesting that someone could help out in solving the matter of exporting a specified page as JPG. 

 

I guess I could modify this part (below) in each case to get it to link to a paragraph style that is specific to the page/product ie. Page "Facebook 1" gets a paragraph style called "Facebook 1". 

 

app.findGrepPreferences.appliedParagraphStyle = myPS();

 

 

Ideas? Solutions? Plz halp! Thanks in advance! 🙂

TOPICS
Import and export , Scripting

Views

3.1K

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 1 Correct answer

Advisor , Mar 03, 2021 Mar 03, 2021

Give this a try....

 

var doc = app.documents[0];

var myFilePath = File("/c/temp/"); 


for(var p = 0; p < app.documents[0].pages.length; p++) {  
         var frames = app.documents[0].pages[p].textFrames;
         var jpg_name = null; 
         
      
         for(var i = 0; i < frames.length; i++) { 
          try { 
              if(frames[i].paragraphs[0].appliedParagraphStyle.name == 'Facebook') {  
                jpg_name = frames[i].paragraphs[0].contents;  
                   break;  
...

Votes

Translate

Translate
Participant ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

Quick follow up: After some more time on Google I found a post leading back to a older/dead part of this forum, but Waybackmachine solved it: 

https://web.archive.org/web/20141202192138/https://forums.adobe.com/thread/1339758 

 

I thought I could use this to create a script that pointed to a specific paragraph style and then only exported the page on which this style was used. I did a test run and used a style called "Facebook" (applied to <first name> <last name>) only on page 3 (of 3) and tried exporting. 

I ended up with: 

  • null1 Facebook.jpg
  • null2 Facebook.jpg
  • John Doe3 Facebook.jpg

 

Not quite what I had in mind...

if (app.documents.length != 0) {  
     var myDoc = app.activeDocument;  
    MakeJPEGfile();  
}  
else{    
     alert("Please open a document and try again.");    
}   
  
  
function MakeJPEGfile() {   
  

  
     for(var myCounter = 0; myCounter < myDoc.pages.length; myCounter++) {  
  
          if (myDoc.pages.item(myCounter).appliedSection.name != "") {  
               myDoc.pages.item(myCounter).appliedSection.name = "";  
          }  
              
            var myPageName = myDoc.pages.item(myCounter).name;  
          var myJpegPrefix = "";  
          var isStyleExist = true;  
  
          //Checking the existing of the paragraph style (filename)  
          try {  
              myDoc.paragraphStyles.item("Facebook");  
          }  
          catch (myError) {  
              isStyleExist = false;  
          }  
  
          if (isStyleExist)  
  
          myJpegPrefix = getParagraphContent(myDoc.paragraphStyles.item("Facebook"), myDoc.pages.item(myCounter)) + myPageName;  
          app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.high; // low medium high maximum  
          app.jpegExportPreferences.exportResolution = 72;  
          app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.exportRange;  
          app.jpegExportPreferences.pageString = myPageName;  
  
  
          var myFilePath = File("/c/temp/" + myJpegPrefix + " Facebook.jpg");  
          var myFile = new File(myFilePath);  
          myDoc.exportFile(ExportFormat.jpg, myFile, false);  
     }  
}  
  
  
// The new function, but needs to add checking the file name rules.    
  
function getParagraphContent (paragraphStyle, currentPage)  
{  
    var paragraphContent = null;  
    for (var c = 0; c < currentPage.textFrames.length; c++)  
    {  
        for (var i = 0; i < currentPage.textFrames.item(c).paragraphs.length; i++)  
        {  
            if (currentPage.textFrames.item(c).paragraphs.item(i).appliedParagraphStyle == paragraphStyle)  
            {  
                paragraphContent = currentPage.textFrames.item(c).paragraphs.item(i).contents;  
   // Remove spaces and returns at the end:  
                paragraphContent = paragraphContent.replace(/\s+$/, '');  
   // Replace remaining spaces with hyphen:  
               // paragraphContent = paragraphContent.replace(/\s+/g, '-');  
   // Make lowercase:  
              //  paragraphContent = paragraphContent.toLowerCase();  
                return paragraphContent;  
            }  
        }  
    }  
    return paragraphContent;  
}  

 

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

Copy link to clipboard

Copied

Hello Philip!

 

 

Here's my take on what I think you're looking to do.......

I just made a couple of modifications to an existing script I wrote.

 

var doc = app.documents[0];

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

}else{
exit();
}

for(var p = 0; p < app.documents[0].pages.length; p++) {  
         var frames = app.documents[0].pages[p].textFrames;
         var myPageName = app.documents[0].pages[p].name;  
         var jpg_name = null; 
         
      
         for(var i = 0; i < frames.length; i++) { 
          try { 
              if(frames[i].paragraphs[0].appliedParagraphStyle.name == 'Facebook') {  
                jpg_name = frames[i].paragraphs[0].contents;  
                   break;  
              }
            }catch (e){
          }  
        }
            
        if(jpg_name != null) {  
          
        app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.LOW; // low medium high maximum

        app.jpegExportPreferences.exportResolution = 72;

        app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.EXPORT_RANGE;
        app.jpegExportPreferences.pageString = app.documents[0].pages[p].name;

         
         doc.exportFile(ExportFormat.jpg, File(mySelectedFolder +"/"+ myPageName +'_' + jpg_name + ".jpg"), false);
        }
        if (jpg_name == null) { 
        }
      }
         alert("Done Exporting jpg'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
Participant ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

Hi Mike, 

 

Thanks for your reply! 

 

I tried your script but it doesn't export anything on my end. At first I thought the problem was that Facebook was in single quotation marks: 'Facebook' - so I changed it to "Facebook" but that didn't work either. The script runs without fault but doesn't seem to output. 

 

Is it possible to modify the script to skip the step where one chooses export folder? I just need to point the file to a fixed location for instance "/c/temp/".

 

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

Copy link to clipboard

Copied

Hi,

 

Give this a try...I have no way of testing the file path as I'm on a mac but everthig else is working on my end

 

var doc = app.documents[0];

var myFilePath = File("/c/temp/"); 


for(var p = 0; p < app.documents[0].pages.length; p++) {  
         var frames = app.documents[0].pages[p].textFrames;
         var myPageName = app.documents[0].pages[p].name;  
         var jpg_name = null; 
         
      
         for(var i = 0; i < frames.length; i++) { 
          try { 
              if(frames[i].paragraphs[0].appliedParagraphStyle.name == 'Facebook') {  
                jpg_name = frames[i].paragraphs[0].contents;  
                   break;  
              }
            }catch (e){
          }  
        }
            
        if(jpg_name != null) {  
          
        app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.LOW; // low medium high maximum

        app.jpegExportPreferences.exportResolution = 72;

        app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.EXPORT_RANGE;
        app.jpegExportPreferences.pageString = app.documents[0].pages[p].name;

         
         doc.exportFile(ExportFormat.jpg, File(myFilePath +"/"+ myPageName +'_' + jpg_name + ".jpg"), false);
        }
        if (jpg_name == null) { 
        }
      }
         alert("Done Exporting jpg'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
Participant ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

Same thing. Nothing happens on my Windows 10 system.

 

However, I tried the script (from your first post) on my obsolete/old/slow macbook - and it worked like a charm, so I'm guessing there's some difference between the code for PC vs. Mac. 

 

Not sure what it might be. 

 

Never mind. What was causing it was this:

doc.exportFile(ExportFormat.jpg, File(myFilePath +"/"+ myPageName +'_' + jpg_name + ".jpg"), false);

 

When I removed that part it worked perfectly! Thanks! How do I remove the number (attached to MyPageName) at the start of the file name? 

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
Participant ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

Wish I could edit the last post. 

Dunno what happened but it started working even with the part I thought was causing it not to work. 

 

Last question still stands though 🙂

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
Participant ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

Reply to myself: You schmuck! 

Just remove myPageName + '_' + from:

doc.exportFile(ExportFormat.jpg, File(myFilePath +"/"+ myPageName + '_' + jpg_name + ".jpg"), false);

 

Huzzah! Now I'm gonna see if I can wrangle this into exporting PDF's 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 ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

Give this a try....

 

var doc = app.documents[0];

var myFilePath = File("/c/temp/"); 


for(var p = 0; p < app.documents[0].pages.length; p++) {  
         var frames = app.documents[0].pages[p].textFrames;
         var jpg_name = null; 
         
      
         for(var i = 0; i < frames.length; i++) { 
          try { 
              if(frames[i].paragraphs[0].appliedParagraphStyle.name == 'Facebook') {  
                jpg_name = frames[i].paragraphs[0].contents;  
                   break;  
              }
            }catch (e){
          }  
        }
            
        if(jpg_name != null) {  
          
        app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.LOW; // low medium high maximum

        app.jpegExportPreferences.exportResolution = 72;

        app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.EXPORT_RANGE;
        app.jpegExportPreferences.pageString = app.documents[0].pages[p].name;

         
         doc.exportFile(ExportFormat.jpg, File(myFilePath +"/" + jpg_name + ".jpg"), false);
        }
        if (jpg_name == null) { 
        }
      }
         alert("Done Exporting jpg'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
Participant ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

Here's my bastardization of your script to export PDF - I tried it and it worked  🙂 

 

Many thanks for your help Mike! Would you mind if I turned this into a Youtube tutorial?

 

var doc = app.documents[0];

var myFilePath = File("/c/temp/testing"); 


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 == 'Facebook') {  
                pdf_name = frames[i].paragraphs[0].contents;  
                   break;  
              }
            }catch (e){
          }  
        }
            
        if(pdf_name != null) {  
          
with(app.pdfExportPreferences){
    pageRange = "2-3"
    }
    
var myPDFExportPreset = app.pdfExportPresets.item("Business card preset");
app.activeDocument.exportFile(ExportFormat.pdfType, File(myFilePath  + "/" + pdf_name + " Business card.pdf"),false, myPDFExportPreset);;
        }
        if (pdf_name == null) { 
        }
      }
         
   

 

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
Participant ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

Mike: Is there a way to create a folder using the jpg/pdf_name variable?

 

Kind of like this, but... um, actually working(?) 😄

var folder = new Folder('/c/temp/' + pdf_name);
    if (!folder.exists)
        folder.create();

I just end up with null

 

I'm trying to create a folder that everything goes in when batching. 

 

 

 

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

Copy link to clipboard

Copied

Hi Philip,

 

Can you post the entire code so I can see where you're trying to check\create the folder?

you'll need to create the folder after you set the variable pdf_name.

 

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
Participant ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

I banged my head against the wall a bit, moved the snippet around a bit, did some duplicating - and then it worked. I'm sure its not pretty tho - but I'm pretty happy that I managed to get it working at all 🙂 

 

So now, if the businesscard paragraph style contains my data merge list <name> <family name> I end up with the script creating a main folder called "John Smith" in which a sub folder called "Businesscard" is created - in which the file "John Smith Businesscard.pdf" is saved. 

var doc = app.documents[0];

var myFilePath = File("/c/temp/"); 


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 == 'Businesscard') {  
                pdf_name = frames[i].paragraphs[0].contents;  
                   break;  
              }
            }catch (e){
          }  
        }
            
        if(pdf_name != null) {  
       
          var mainfolder = new Folder('/c/temp/startkit/' + pdf_name);
    if (!mainfolder.exists)
        mainfolder.create();
        
          var subfolder = new Folder(mainfolder + "/businesscard");
    if (!subfolder.exists)
        subfolder.create();
       
with(app.pdfExportPreferences){
    pageRange = "1-3"
    }    
        
var myPDFExportPreset = app.pdfExportPresets.item("Businesscard");
app.activeDocument.exportFile(ExportFormat.pdfType, File(subfolder  + "/" + pdf_name + "Businesscard.pdf"),false, myPDFExportPreset);;
        }
        if (pdf_name == null) { 
        }
      }
         

   

 

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
Participant ,
Mar 03, 2021 Mar 03, 2021

Copy link to clipboard

Copied

Ok, so I ran into a problem. Batching these scripts using Kasyans script didn't work. It just stopped midway after running 2 out of 8 scripts. 

 

So I ended up using this method (which worked fine): 

 

var path = File("/c/Users/etc/etc");

function batch()
{
   var f1 = File ( path + "/page 1 [product].jsx" );
   var f2 = File ( path + "/page 2 [product].jsx" );
   var f3 = File ( path + "/page 3 [product].jsx" );
   var f4 = File ( path + "/page 4 [product].jsx" );
   var f5 = File ( path + "/page 5 [product].jsx" );
   var f6 = File ( path + "/page 6 [product].jsx" );
   var f7 = File ( path + "/page 7 [product].jsx" );
   var f8 = File ( path + "/page 8 [product]" );
 
   app.doScript ( f1 );
   app.doScript ( f2 );
   app.doScript ( f3 );
   app.doScript ( f4 );
   app.doScript ( f5 );
   app.doScript ( f6 );
   app.doScript ( f7 );
   app.doScript ( f8 );
}
 
batch();

 

 

And as a side note (since there were only 8 hits of which 1 was pertinent [but incorrect]) to whomever Googles for how to change the Blend space to RGB for exporting JPG (and then changing it back after export):

 

   var doc = app.documents[0];


for(var p = 0; p < app.documents[0].pages.length; p++) {  
         var frames = app.documents[0].pages[p].textFrames;
         var jpg_name = null; 
         
      
         for(var i = 0; i < frames.length; i++) { 
          try { 
              if(frames[i].paragraphs[0].appliedParagraphStyle.name == 'namn') {  
                jpg_name = frames[i].paragraphs[0].contents;  
                   break;  
              }
            }catch (e){
          }  
        }
app.activeDocument.transparencyPreferences.blendingSpace = BlendingSpace.RGB;
        if(jpg_name != null) {  
          
                    var mainfolder = new Folder('/c/temp/startkit/' + jpg_name);
    if (!mainfolder.exists)
        mainfolder.create();
        
          var subfolder = new Folder(mainfolder + "/Flödesbild");
    if (!subfolder.exists)
        subfolder.create();
        
        app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.HIGH; // low medium high maximum

        app.jpegExportPreferences.exportResolution = 300;

        app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.EXPORT_RANGE;
        app.jpegExportPreferences.pageString = "15";

         
         doc.exportFile(ExportFormat.jpg, File(subfolder +"/" + jpg_name + "Flödesbild.jpg"), false);
        }
        if (jpg_name == null) { 
        }
      }
  
app.activeDocument.transparencyPreferences.blendingSpace = BlendingSpace.CMYK;

 

 

Over and out, thanks a bunch 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
Participant ,
Mar 10, 2021 Mar 10, 2021

Copy link to clipboard

Copied

Dearest @Mike Bro  - I ran into some new trouble on my scripting travels. 

 

In short: I need to have a function that picks up another certain paragraph style and incorporates it into the file name. 

 

Like I mentioned before, I can now create a document using <first name> <last name> from Data merge in a paragraph called "name" for creating a folder called "First name Last name" and have different instances of the script to allow for different suffixes like "_business card", "_instagram" and so on. 

However. Now I need to get the email adress into the file name as well. 

 

I tried duplicating (actually triplicating [if that's even a word]) this part:

 

for(var a = 0; a < app.documents[0].pages.length; a++) {  
         var frames = app.documents[0].pages[a].textFrames;
         var email_paragraph = null;          
      
         for(var i = 0; i < frames.length; i++) { 
          try { 
              if(frames[i].paragraphs[0].appliedParagraphStyle.name == 'email') {  
                email_paragraph = frames[i].paragraphs[0].contents;  
                   break;  
              }
            }catch (e){
          }  }
        }

 

I thought I could end up with a script that specifies these paragraph styles:

  • email
  • name
  • product

 

So I wound up with this: 

 

   var doc = app.documents[0];


for(var p = 0; p < app.documents[0].pages.length; p++) {  
         var frames = app.documents[0].pages[p].textFrames;
         var email_name = null; 
         
      
         for(var i = 0; i < frames.length; i++) { 
          try { 
              if(frames[i].paragraphs[0].appliedParagraphStyle.name == 'email') {  
                email_name = frames[i].paragraphs[0].contents;  
                   break;  
              }
            }catch (e){
          }  
        }}
    
    for(var p = 0; p < app.documents[0].pages.length; p++) {  
         var frames = app.documents[0].pages[p].textFrames;
         var product_paragraph = null; 
         
      
         for(var i = 0; i < frames.length; i++) { 
          try { 
              if(frames[i].paragraphs[0].appliedParagraphStyle.name == 'product') {  
                product_paragraph = frames[i].paragraphs[0].contents;  
                   break;  
              }
            }catch (e){
          }  
        }}

for(var p = 0; p < app.documents[0].pages.length; p++) {  
         var frames = app.documents[0].pages[p].textFrames;
         var name_paragraph = null;          
      
         for(var i = 0; i < frames.length; i++) { 
          try { 
              if(frames[i].paragraphs[0].appliedParagraphStyle.name == 'name') {  
                name_paragraph = frames[i].paragraphs[0].contents;  
                   break;  
              }
            }catch (e){
          }  
        }
    
app.activeDocument.transparencyPreferences.blendingSpace = BlendingSpace.RGB;
        if(name_paragraph != null) {  
          
                    var mainfolder = new Folder('/c/temp/testing/' + name_paragraph);
    if (!mainfolder.exists)
        mainfolder.create();
        
          var subfolder = new Folder(mainfolder + "/" + product_paragraph);
    if (!subfolder.exists)
        subfolder.create();
        
        app.jpegExportPreferences.jpegQuality = JPEGOptionsQuality.HIGH; // low medium high maximum
        app.jpegExportPreferences.exportResolution = 72;
        app.jpegExportPreferences.jpegExportRange = ExportRangeOrAllPages.EXPORT_RANGE;
        app.jpegExportPreferences.pageString = "1";

         
         doc.exportFile(ExportFormat.jpg, File(subfolder +"/" + name_paragraph + " " + product_paragraph + " " + email_name + ".jpg"), false);
        }
        if (name_paragraph == null) { 
        }
      }
  
app.activeDocument.transparencyPreferences.blendingSpace = BlendingSpace.CMYK;

 

When I run this I get a file called "First name Last name null null" in c:\temp\testing\First name Last name\null

 

Mission control, please advice. Many thanks in advance 🙂 

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 ,
Mar 10, 2021 Mar 10, 2021

Copy link to clipboard

Copied

Hi Philip,

 

Any chance you can post a test file somewhere, also what is your desired end result........

folder\sub folder final file name(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
Participant ,
Mar 11, 2021 Mar 11, 2021

Copy link to clipboard

Copied

Hey Mike, 

 

Thanks for replying. I realised the script seems to actually work. What seems to be wrong is my document, because whenever I try a new document - it works. Not sure why it only picks up the name_paragraph but not the other paragraphs even when they are available. 

 

I'm now able to export all my pages as separate documents, example below:

pages.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 Expert ,
Mar 11, 2021 Mar 11, 2021

Copy link to clipboard

Copied

I have a paid script that might be what you're after - Data Merge to Single Records PRO:

Screen Shot 2021-03-11 at 23.42.53.png

This script effectively merges each file one at a time to PDF; or ID and then exports to another format... but if exporting to anything other than directly to PDF, there is the ability to run a script prior to export. If you use this script, merge to ID files but use a custom script that you've written to do specific page exports, would that be of use?

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
Participant ,
Mar 11, 2021 Mar 11, 2021

Copy link to clipboard

Copied

Hey Colin, 

 

Thanks, I already own your (awesome) script and gave you praise for it (we just spoke via e-mail in regards to the GREP script vs. bullet lists via Data merge) 🙂 

 

If you sneak a peek at the image I posted in my reply to Mike: I enjoy using your script for the different parts that the document consists. Say I need to produce business cards for all 190+ posts I would just use the 20+ page template, erase all the pages that weren't pertinent to the business card and then save it as a separate document/run your script to produce 190+ business cards that would end up getting proper file names like: John Smith Business card.pdf

I first started using your script when I had to produce christmas cards for all employees. Much obliged 🙂 

 

However, when a new co-worker starts, they need the full setup - so now I can set up my paragraph styles/ text boxes and just run that script to get:

/John Smith/business card/John Smith Business card.pdf

/John Smith/Social/John Smith Instagram_1080x1080px.jpg

/John Smith/Social/John Smith Facebook_1920x1080px.jpg

/John Smith/Ads/John Smith Letterbox ad.pdf

/John Smith/Ads/John Smith Poster.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
New Here ,
Aug 11, 2021 Aug 11, 2021

Copy link to clipboard

Copied

hi guys,

 

I am a bit lost, but I guess this is a similar case. Hopefully someone can solve my problem.

 

I have a document with several pages. I want to export every single page as a JPG. So far no problems.

But I want the filename to be individual for every JPG. I use one graphic on every page on a separat layer and I would love to have the name of the linked graphic be part of the filename.

 

For example:

graphic motive_01.jpg on Page 1

graphic motive_02.jpg on Page 2

graphic motive_01.jpg on Page 3

graphic motive_04.jpg on Page 4

...

 

the exported files should look like "INDD file name + motive_01_PageNumber.jpg"

 

Is that possible?

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
Participant ,
Aug 11, 2021 Aug 11, 2021

Copy link to clipboard

Copied

This might be helpful: https://youtu.be/3ldKqt1p14k

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 11, 2021 Aug 11, 2021

Copy link to clipboard

Copied

LATEST

Oh great...that's exactly what I am looking for.

There is just one issue....the placed graphic has to be on the page....all of my pictures are placed in the master page.

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 11, 2021 Aug 11, 2021

Copy link to clipboard

Copied

Hello @DominikL 

 

You really should create a new post as your question\request doesn't fall under the orininal post...

"[Script] Exporting PDF and JPG with custom name from Data merge"

 

We'll be glad to help you out...

 

 

 

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