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

InDesign CC Variable Data Printing

Community Beginner ,
Jun 07, 2019 Jun 07, 2019

Good Day,

If anyone can help, I would like to know if there is a script that can be used within INDD that will allow me to produce PDF's from specific pages in a multi page document?

For example:

If I have a INDD doc with a Certificate, Letter and Address page can the script say only export Certificate and Address page ignore Letter? I've bee stuck on this for days now . I'm trying to find a solution within INDD without the use of 3rd party software like Fusion Pro.

This is the current code used for multi page output using Fusion Pro

var outputName = GetFileName(FusionPro.Composition.inputFileName)

//CVPI and page name

var a1 = "LETTG371"

var a2 = "Letter"

var b1 = "CRT3G434"

var b2 = "3.5x5.5"

var c1 = "ADDPG123"

var c2 = "12.75x9.75"

var d1 = ""

var d2 = ""

//file seperaator

if (FieldChanged("CVPI") && Field("CVPI") == a1)

{

    FusionPro.Composition.OpenNewOutputFile( outputName + "_"+ a2 +"."+

        FusionPro.Composition.outputFormatExtension);

}

if (FieldChanged("CVPI") && Field("CVPI") == b1)

{

    FusionPro.Composition.OpenNewOutputFile( outputName + "_"+ b2 +"."+

        FusionPro.Composition.outputFormatExtension);

}

if (FieldChanged("CVPI") && Field("CVPI") == c1)

{

    FusionPro.Composition.OpenNewOutputFile( outputName + "_"+ c2 +"."+

        FusionPro.Composition.outputFormatExtension);

}

if (FieldChanged("CVPI") && Field("CVPI") == d1)

{

    FusionPro.Composition.OpenNewOutputFile( outputName + "_"+ d2 +"."+

        FusionPro.Composition.outputFormatExtension);

}

//page seporator

FusionPro.Composition.SetBodyPageUsage(a2, false);

FusionPro.Composition.SetBodyPageUsage(b2, false);

FusionPro.Composition.SetBodyPageUsage(c2, false);

if (Field("CVPI") == a1)

{

FusionPro.Composition.SetBodyPageUsage(a2, true);

}

else

if (Field("CVPI") == b1)

{

FusionPro.Composition.SetBodyPageUsage(b2, true);

}

else

if (Field("CVPI") == c1)

{

FusionPro.Composition.SetBodyPageUsage(c2, true);

}

else

if (Field("CVPI") == d1)

{

FusionPro.Composition.SetBodyPageUsage(d2, true);

}

Thank you for you time

TOPICS
Scripting
3.4K
Translate
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

Community Expert , Jun 07, 2019 Jun 07, 2019

Hi Greg,

Did you investigate to use the PDF export dialog to input the pages that you want exported. The string format that you can use is using - to denote a range and, separates non continuous pages. Like 1-3,6 will export pages 1,2,3 and 6 of the document

Screen Shot 2019-06-07 at 10.25.14 pm.png

-Manan

Translate
Community Expert ,
Jun 07, 2019 Jun 07, 2019

Hi Greg,

Did you investigate to use the PDF export dialog to input the pages that you want exported. The string format that you can use is using - to denote a range and, separates non continuous pages. Like 1-3,6 will export pages 1,2,3 and 6 of the document

Screen Shot 2019-06-07 at 10.25.14 pm.png

-Manan

Translate
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 ,
Jun 07, 2019 Jun 07, 2019

If you need a script to do the same as i discussed above you can follow the correct answer in the thread mentioned below

Re: Exporting individual pages to PDF / Indesign

Edit line no, 22, change myPageName to the string in the format i described in the above post. It should work

-Manan

Translate
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 ,
Jun 08, 2019 Jun 08, 2019

Would you happen to know how I can get it to select certain pages without me manually entering the page numbers? I would run a data merge and then only have the script select for example all the 25 years of service recipients? If that makes sense or is it not possible?

I really appreciate your help

Translate
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 ,
Jun 08, 2019 Jun 08, 2019

Hi Greg,

you could try Print selected pages script by Luis Felipe Corullón, it exports selected pages to JPG, PDF, PNG formats.

in the current script it will export a multi page pdf based on the selection and it also displays the Pdf Export dialog, I'm guessing for you to select a pdf preset.

if you want to export single page pdfs based on the selection, replace lines 67 though 87 with the code below. You can also define the pdf preset avoiding Pdf Export dialog.

function exportPDF(selectedPgs){

  var curDoc = app.documents[0];

  export_preset1 = app.pdfExportPresets.itemByName("[High Quality Print]");

  if (!(export_preset1.isValid)){

  alert("Error!\nThe pdf export preset ''High Quality Print'' does not exist.");

  exit();

  }

  

    var theFolder = Folder.selectDialog("Choose a folder for export");

    if (theFolder == null) {

        exit();

    }

      

     for (i = 0; i < curDoc.pages.length; i++) {

     if (String(selectedPgs).match("\\b"+curDoc.pages.name+"\\b")){

    app.pdfExportPreferences.pageRange = curDoc.pages.name;

    var myPageName = curDoc.pages.name;

    var fileName = curDoc.name.replace(/.indd$/,"");

  

    try {

        curDoc.exportFile(ExportFormat.PDF_TYPE , File(theFolder + "/" + fileName + "-Page-" + myPageName +'.pdf') , false, export_preset1);

      

    }catch(e) {

        alert(e);

    }

}

    }

}

Regards

Mike

Translate
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 ,
Jun 08, 2019 Jun 08, 2019

Hi Greg,

I would not say it is impossible without knowing the whole scenario, Mike above gave a script see if it fits your need. The key point here is how do you want the script to identify the pages to export. You could have a script that prompts the user for the pages to export, you could name the pages in a specific manner so the script can search based on that or anything that can help identify which pages to export.

-Manan

Translate
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 ,
Jun 09, 2019 Jun 09, 2019

Hi Manan,

"you could name the pages in a specific manner so the script can search based on that or anything that can help identify which pages to export." This is exactly what I would need the script to do I just don't know how to go about doing it.

Translate
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 ,
Jun 10, 2019 Jun 10, 2019

Hi Greg,

"you could name the pages in a specific manner so the script can search based on that or anything that can help identify which pages to export." This is exactly what I would need the script to do I just don't know how to go about doing it.

Create paragraph style called "filename", assign that style to a text frame in the slug area for each page with its own identifier.

If you're doing a data merge you could add a column to the .csv for the page identifier and merge the page names at that point.

Just be sure to assign the paragraph style "filename" to the text frame before hand.

Screen Shot 2019-06-10 at 2.48.19 AM.png

in the Print selected pages script replace lines 67 though 87 with the code below.

//Function Returns pdf_name for Selected Pages
function getTextFromPageUsingParagraphStyle(myPage){
if(app.activeDocument.paragraphStyles.itemByName("filename") == null) {
alert ('Error!\nThe Paragraph Style "filename" does not exist or is Labeled Incorrectly.');
exit();

}

app.findTextPreferences = app.changeTextPreferences = null;
app.findTextPreferences.appliedParagraphStyle = "filename";

var myTextframes = myPage.textFrames;
var pdf_name = null;
for (y=0; y < myTextframes.length; y++){
var mySearchResult = myTextframes.findText();
if (mySearchResult.length > 0){
pdf_name = mySearchResult[0].contents;
break;
}
}
return pdf_name;

}

function exportPDF(selectedPgs){

  var curDoc = app.documents[0];

  export_preset1 = app.pdfExportPresets.itemByName("[High Quality Print]");

  if (!(export_preset1.isValid)){

  alert("Error!\nThe pdf export preset ''High Quality Print'' does not exist.");

  exit();

  }

    var theFolder = Folder.selectDialog("Choose a folder for export");

    if (theFolder == null) {

exit();

    }

for (i = 0; i < curDoc.pages.length; i++) {
if (String(selectedPgs).match("\\b"+curDoc.pages.name+"\\b")){

app.pdfExportPreferences.pageRange = curDoc.pages.name;

//~var fileName = curDoc.name.replace(/.indd$/,"");
var pdf_name = getTextFromPageUsingParagraphStyle(curDoc.pages);

    try {

curDoc.exportFile(ExportFormat.PDF_TYPE, File(theFolder  +"/"+ pdf_name + ".pdf") , false, export_preset1);

    }catch(e) {

alert(e);

    }

}

    }

}

hope this helps in what you're looking for.

Regards

Mike

Translate
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 ,
Jun 10, 2019 Jun 10, 2019

This is really good as it adds the page name to the end filenames, however I am still prompted to select which pages to export. What I need is for the script to choose and export only whats on the .csv file. Basically if the Indesign file as Cert, Letter, Notecard and Address page and the data file only as data for Cert and Notecard. Can the script only select those 2 pages to export through automation or can this only be done manually?

Sorry for all the back and worth

Translate
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 ,
Jun 10, 2019 Jun 10, 2019

Greg,

Are you using the .csv file to do data merge?

Did you look at post #7 and walk through creating the paragraph style and adding a column to the .csv for the page identifier? This could then be merged with the rest of the data. The code could be modified to only export pages with the applied style and lose the dialog.

Regards

Mike

Translate
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 ,
Jun 10, 2019 Jun 10, 2019

Screen Shot 2019-06-10 at 10.28.57 PM.pngScreen Shot 2019-06-10 at 10.29.50 PM.pngScreen Shot 2019-06-10 at 10.30.12 PM.png

Screen Shot 2019-06-10 at 10.35.37 PM.png

I did all of the following above as instructed, I created the paragraph style and applied it to the text box with in the slug area. I also linked it to the data file. I'm new to the java script language which is why i'm having such a hard time with this code.

Translate
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 ,
Jun 13, 2019 Jun 13, 2019

Greg,



You actually need to run Data Merge in InDesign to pull in the identifier information from the .csv file, as the script doesn't read the from the data source.

Follow the original instructions by creating the paragraph style, apply the style to the text frame, link to the data file and run data merge. The data merge process will merge the records from the csv into your document automatically creating a page for each record.

The script below will only export pages that contain a text frame with the applied style. The pdfs will be named by the “DocumentName_text frame contents.pdf”

  var curDoc = app.documents[0];

  export_preset1 = app.pdfExportPresets.itemByName("[High Quality Print]");

  if (!(export_preset1.isValid)){

  alert("Error!\nThe pdf export preset ''High Quality Print'' does not exist.");

  exit();

  }

       //Function Returns pdf_name for all Pages with applied Paragraph Style "filename"

      function getTextFromPageUsingParagraphStyle(myPage){

   

     if(app.activeDocument.paragraphStyles.itemByName("filename") == null) {

      alert ('Error!\nThe Paragraph Style "filename" does not exist or is Labeled Incorrectly.');

      exit();

}

          app.findTextPreferences = app.changeTextPreferences = null; 

          app.findTextPreferences.appliedParagraphStyle = "filename";

          var myTextframes = myPage.textFrames;

          var pdf_name = null;

        

          for (y=0; y < myTextframes.length; y++){

                var mySearchResult = myTextframes.findText();

                if (mySearchResult.length > 0){

                pdf_name = mySearchResult[0].contents;

                 break;

                }

          }

    

         return pdf_name;    

}

    var theFolder = Folder.selectDialog("Choose a folder for export");

    if (theFolder == null) {

        exit();

    }

      

     for (i = 0; i < curDoc.pages.length; i++) {

    app.pdfExportPreferences.pageRange = curDoc.pages.name;

  

    var fileName = curDoc.name.replace(/.indd$/,"");

    var pdf_name = getTextFromPageUsingParagraphStyle(curDoc.pages);

    if(pdf_name != null) { 

    curDoc.exportFile(ExportFormat.PDF_TYPE, File(theFolder + "/" + fileName + "_"+  pdf_name + ".pdf") , false, export_preset1);

    }

}

alert("Done Exporting the pdfs!")

Regards,

Mike

Translate
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 ,
Jun 27, 2019 Jun 27, 2019
LATEST

Greg,

Try creating just one Paragraph Style like before named "filename" and link that to the "Page Identifier" column in your .csv file. Run data merge to fill the text frame(s) and create the pages in InDesign. with the data from the .csv.

The script below is looking at the contents of the applied style for each page and only exporting those pages that it finds a match for.(Add, Cert, Lett........) naming the pdfs by the “DocumentName_text frame contents.pdf” .

The Script is only looking for those three instances.

  var curDoc = app.documents[0];

 

  export_preset1 = app.pdfExportPresets.itemByName("[High Quality Print]");

  if (!(export_preset1.isValid)){

  alert("Error!\nThe pdf export preset ''High Quality Print'' does not exist.");

  exit();

  }

       //Function Returns pdf_name for all Pages with applied Paragraph Style "filename"

      function getTextFromPageUsingParagraphStyle(myPage){

    

     if(app.activeDocument.paragraphStyles.itemByName("filename") == null) {

      alert ('Error!\nThe Paragraph Style "filename" does not exist or is Labeled Incorrectly.');

      exit();

}

          app.findTextPreferences = app.changeTextPreferences = null;  

          app.findTextPreferences.appliedParagraphStyle = "filename"; 

 

          var myTextframes = myPage.textFrames; 

          var pdf_name = null;

         

  try{

          for (y=0; y < myTextframes.length; y++){ 

                var mySearchResult = myTextframes.findText(); 

                if (mySearchResult.length > 0){ 

                pdf_name = mySearchResult[0].contents;

                 break; 

                } 

           }     

      }catch (e){

  }

         return pdf_name;     

}

    var theFolder = Folder.selectDialog("Choose a folder for export"); 

    if (theFolder == null) {

        exit(); 

    }

       

     for (i = 0; i < curDoc.pages.length; i++) {

    app.pdfExportPreferences.pageRange = curDoc.pages.name;

   

    var fileName = curDoc.name.replace(/.indd$/,"");

    var pdf_name = getTextFromPageUsingParagraphStyle(curDoc.pages);

    if(pdf_name != null) {

      var myName = pdf_name;

        var my_pdf_Name = myName.match(/.*Add.*|.*Cert.*|.*Lett.*|/gi);

       

   }

     if(my_pdf_Name != null) {       

    curDoc.exportFile(ExportFormat.PDF_TYPE, File(theFolder + "/" + fileName + "_"+  my_pdf_Name + ".pdf") , false, export_preset1);

    }

}

alert("Done Exporting the pdfs!")

Regards,

Mike

Translate
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