Skip to main content
Participant
November 3, 2022
Question

Exporting different sets (range) of pages to different file types with data merge input data.

  • November 3, 2022
  • 3 replies
  • 399 views

Hi all,

I'm trying to create a document that will read data from a spreadsheet. The challenge is trying to figure out how to get different pages to export as different files and file types. The document is for marketing purposes. The export would go something like this:

 

  • Page 1 through Page 2: Front and back of a postcard exported to a single PDF for print (file 1)
  • Page 3: Social Media Graphic export to JPG (file 2)
  • Page 4: Alternate Social Media Graphic export to JPG (file 3)
  • Page 5: Alternate Social Media Graphic export to JPG (file 4)
  • Page 6 through page 13: Brochure exported to single PDF for print (file 5)
  • Page 14: Flyer exported to PDF (file 6)

 

The order above isn't set in stone and can be altered. Also, if it's not possible to include the data merge, I think I can do a workaround of "Create Merged Document" and have the data filled in that way. In an ideal world, each file exported would also have a filename that reflected one of the fields from the data merge. I have the Coleandcoo script to name file types & have different exports from a data merge, but it doesn't allow me to export different file types from one export.

 

Is the above possible in any way?

This topic has been closed for replies.

3 replies

Legend
November 3, 2022

Hello @Tyler22079580164x,

 

Give this a try...

 

1. Start off by creating a Script Label named "Export_Name"

2. Create a text box in the slug area with a portion of the box within the page bounds and assign the Script Label

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

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


The below script will export the files named by the contents of the text box using the Script Label in the exact range and format you outlined above.


Note: you will need to adjust the PDF export preset and the jpeg Export Preferences for your specific requirements, also once the order/page ranges are set in stone you'll have to adjust the code if it differs from what you outlined.

 

 

doc = app.documents[0];

var Export_Folder = Folder(doc.filePath + '/Export Folder');
var export_preset = app.pdfExportPresets.item("[High Quality Print]");

if (!(export_preset.isValid)){
  alert("The pdf export preset does not exist.");
  exit();
}

if (!Export_Folder.exists) {
  Export_Folder.create(); 
}

  //get the PDF_1 export name from the Script Label Export_Name from page 1
  var pageItems = doc.pages[0].allPageItems;
      for(var i = 0; i < pageItems.length; i++){
        if(pageItems[i].label == "Export_Name"){
          var PDF_1 = pageItems[i].contents;
        }
      }

      if (PDF_1 == undefined || PDF_1 == ""){
        alert('Error!\nThe "Export_Name" Script Label is not applied to page 1, not labeled correctly or has no content.');
        exit();
        }

        //get the PDF_2 export name from the Script Label Export_Name from page 6
          var pageItems = doc.pages[5].allPageItems;
          for(var i = 0; i < pageItems.length; i++){
            if(pageItems[i].label == "Export_Name"){
              var PDF_2 = pageItems[i].contents;
            }
          }

          if (PDF_2 == undefined || PDF_2 == ""){
            alert('Error!\nThe "Export_Name" Script Label is not applied to page 6, not labeled correctly or has no content.');
            exit();
            }
              //get the PDF_3 export name from the Script Label Export_Name from page 14
              var pageItems = doc.pages[13].allPageItems;
              for(var i = 0; i < pageItems.length; i++){
                if(pageItems[i].label == "Export_Name"){
                  var PDF_3 = pageItems[i].contents;
                }
              }

          if (PDF_3 == undefined || PDF_3 == ""){
            alert('Error!\nThe "Export_Name" Script Label is not applied to page 14, not labeled correctly or has no content.');
            exit();
            }

            app.pdfExportPreferences.pageRange = "1-2"
            doc.exportFile(ExportFormat.PDF_TYPE, File(Export_Folder + "/" + PDF_1 + ".pdf"), false, export_preset);

           app.pdfExportPreferences.pageRange = "6-13"
           doc.exportFile(ExportFormat.PDF_TYPE, File(Export_Folder + "/" + PDF_2 + ".pdf"), false, export_preset);

           app.pdfExportPreferences.pageRange = "14"
           doc.exportFile(ExportFormat.PDF_TYPE, File(Export_Folder + "/" + PDF_3 + ".pdf"), false, export_preset);


           //loop starts @ page 3 less the last 9 pages, exporting jpeg's of pages 3, 4 & 5 named from the Script Label Export_Name from each page
           var myPagesNoID = [];
            for(var p = 2; p <doc.pages.length-9; p++) {
              var myPageName = doc.pages[p].name;        
              var pageItems = doc.pages[p].allPageItems;
                for(var i = 0; i < pageItems.length; i++){
                  if(pageItems[i].label == "Export_Name"){
                    var jpg_Name = pageItems[i].contents;
                    if(jpg_Name == undefined || jpg_Name == "") {
                      myPagesNoID.push(doc.pages[p].name);
                    }
                  }
                }

                if (myPagesNoID.length >= 1){
                  alert('Error!\nThe "Export_Name" Script Label is not applied to page(s) ' + myPagesNoID +', not labeled correctly or has no content.');
                  exit();
                  }

              // Set JPEG export preferences
              app.jpegExportPreferences.properties = {
                 antiAlias: true,
                 embedColorProfile: true,
                 exportResolution: 72,
                 jpegColorSpace: JpegColorSpaceEnum.rgb,
                 jpegExportRange: ExportRangeOrAllPages.exportRange,
                 jpegQuality: JPEGOptionsQuality.maximum,
                 jpegRenderingStyle: JPEGOptionsFormat.PROGRESSIVE_ENCODING,
                 useDocumentBleeds: false,
                 simulateOverprint: false,
                 pageString: myPageName,
               }

              doc.exportFile(ExportFormat.jpg,File(Export_Folder + "/" + jpg_Name + ".jpg"),false);
            } 
            alert("Done exporting files!");

 

 


I'm sure others here probably would have a more refined approach but this works for what you're asking.


Regards,

Mike

Participant
November 4, 2022

Thanks, @Mike Bro. I tried this, but apparently, JS coding is over my head. I couldn't get it to work. Here's to hoping someone else has a different solution. I'm definitely open to paying for the solution (other plug-ins/scripts/etc), I just need something easy to implement. 

Legend
November 4, 2022

@Tyler22079580164x,

 

What didn't seem to work?

When I have the Script Label "Export_Name" on pages 1, 3, 4, 5, 6 & 14 this is what the script exports for me...

Did you create and assign the Script label like this to pages 1, 3, 4, 5, 6 & 14?

 

Regards,

Mike

 

Community Expert
November 3, 2022

There's a batch export script here - I'm clueless how to utilise this way though

https://creativepro.com/files/kahrel/indesign/batch_convert.html

 

@Peter Kahrel 

Peter Kahrel
Community Expert
Community Expert
November 3, 2022

That batch exporter won't work for what the OP wants (but thanks for the mention!).

P.

Robert at ID-Tasker
Legend
November 3, 2022

It could be fully automated - as long as you can prepare info for the script what should be done with each range of pages - perfect example for another set of rules for my tool 😉 

 

Participant
November 3, 2022

Not sure how this helps. I looked into your website, and it all seems to revolve around tables and editing tables in InDesign. Please let me know if I'm missing something.