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

"Save each page as PDF" naming mod?

New Here ,
Jan 16, 2008 Jan 16, 2008

Copy link to clipboard

Copied

I have a data merged document that has around 500 records that has been exported to a 500 page document.

I use either the "Page Exporter Utility" or a similar js that will save each page as an individual PDF.

The trouble I'm having is:
I have the job number embedded in a text box in the slug area. I'd like to automatically use that job number to name the PDF upon export.
Does anyone know how I can pull text from a textbox to use as a file name in js?

As always, thanks to everyone for their help

Randy
TOPICS
Scripting

Views

976

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 16, 2008 Jan 16, 2008

Copy link to clipboard

Copied

How do you identify the text frame? Does it have a unique label? Does what is in it have a unique paragraph style name?

Peter

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 ,
Jan 16, 2008 Jan 16, 2008

Copy link to clipboard

Copied

The easiest thing to do would be to give it a unique paragraph style. I could also put it on it's own layer. I'm not sure how difficult it would be to mod the excellent "Page Exporter Utility 5.0" but that would be my preference.

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
Guru ,
Jan 16, 2008 Jan 16, 2008

Copy link to clipboard

Copied

Hi Randy,
I would label the text box in the slug area with something like "My job number" in Script Label panel. Then I would read the contents of the text box:

myDoc = app.activeDocument;
var myText = myDoc.textFrames.item("My job number").contents;
alert("My job number is " + myText);

Kasyan

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 16, 2008 Jan 16, 2008

Copy link to clipboard

Copied

But there are 500 records. Randy, can you identify the job numbers in any way? Do they have any particular number or alphsnumerical format such that you can find them (and nothing else)? You can then label the text frames they're in.

Peter

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 ,
Jan 16, 2008 Jan 16, 2008

Copy link to clipboard

Copied

Thanks for responding, yes, all job numbers start wit "pnxx-" followed by a 4 digit number. i.e, "pnxx-1234".

Randy

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 16, 2008 Jan 16, 2008

Copy link to clipboard

Copied

In that case you can label all their containing text frames like this:

app.findTextPreferences = null;
app.findTextPreferences.findWhat = 'pnxx-^9^9^9^9';
f = app.activeDocument.findText();
for (i = 0; i < f.length; i++)
   f.parentTextFrames[0].label = 'jobnumber';

Then the exporter can retieve the jobnumber on each page like this:

//script
//more script
// you probably have a for-loop that iterates through
// the document page by page
for (i = 0; i < myDoc.pages.length; i++)
{
jobnum = doc.pages.textFrames.item ('jobnumber').contents;
filename = ...
//export
}

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 ,
Feb 13, 2008 Feb 13, 2008

Copy link to clipboard

Copied

OK, I finally have time to mess with this thing.
I put in the lines that Peter so kindly posted here. There are a few things that I'm still not getting though.

in the first part of the suggestion I see that it runs through the document and finds the text box with my job number and labels it "jobnumber"
If I label the text box on the master page "jobnumber" before I import the data merge, that would probably do the trick, right?

The second part of the script I'm really just not getting.

Here's what I have (with the previous code still intact, just commented out.)

As always, Thanks a million!

//############################################################################
// # An InDesign CS3 JavaScript
// # Exports each page of an InDesign CS document as a separate PDF to
// # a selected folder using the current PDF export settings.
// ############################################################################


i //Display a choose folder dialog box.
if(app.documents.length != 0){
var myFolder = Folder.selectDialog (Choose a Folder);
if(myFolder != null){
myExportPages(myFolder);
}
}
else{
alert(Please open a document and try again.);
}

i //Find the textbox that contains the job number.

app.findTextPreferences = null;
app.findTextPreferences.findWhat = pnxx-^9^9^9^9;
f = app.activeDocument.findText();
for (i = 0; i < f.length; i++)
f.parentTextFrames[0].label = jobNumber;

function myExportPages(myFolder){
var myPageName, myFilePath, myFile;
var myDocument = app.activeDocument;
var myDocumentName = myDocument.name;
var myDialog = app.dialogs.add();
with(myDialog.dialogColumns.add().dialogRows.add()){
staticTexts.add({staticLabel:Base name:});
var myBaseNameField = textEditboxes.add({editContents:myDocumentName, minWidth:160});
}
var myResult = myDialog.show({name:ExportPages});
if(myResult == true){
var myBaseName = myBaseNameField.editContents;

i //Remove the dialog box from memory.

myDialog.destroy();

i /* for(var myCounter = 0; myCounter < myDocument.pages.length; myCounter++){
i myPageName = myDocument.pages.item(myCounter).name;
i app.pdfExportPreferences.pageRange = myPageName;
i */

for (i = 0; i < myDocument.pages.length; i++)
{
jobnum = myDocument.pages.textFrames.item (jobNumber).contents;

i //The name of the exported files will be the base name + the page name + .pdf.
i //If the page name contains a colon (as it will if the document contains sections),
i //then remove the colon.
var myRegExp = new RegExp(:,gi);
myPageName = myPageName.replace(myRegExp, _);
i // myFilePath = myFolder + / + myBaseName + _ + myPageName + .pdf;
myFilePath = myFolder + / + myBaseName + _ + jobnum + .pdf;
myFile = new File(myFilePath);
myDocument.exportFile(ExportFormat.pdfType, myFile, false);
}
}
else{
myDialog.destroy();
}
}

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 ,
Feb 14, 2008 Feb 14, 2008

Copy link to clipboard

Copied

Well, you don't really have to label anything beforehand. What you need to do is this: find all job numbers, then for each jobnumber, get the page it's on and export it. The script below does that (assuming that text frames in the bleed area behave the same as any other text frame). It doesn't do any error-checking, it's just something to start off with.

Peter

destination_folder = '/d/';

doc = app.activeDocument;
doc.sections.everyItem().includeSectionPrefix = false;
app.findTextPreferences = null;
app.findTextPreferences.findWhat = 'pnxx-^9^9^9^9';
found = doc.findText();
for (i = 0; i < found.length; i++ )
{
f = File (destination_folder + found.contents + '.pdf');
app.pdfExportPreferences.pageRange = found.parentTextFrames[0].parent.name;
doc.exportFile (ExportFormat.pdfType, f, false);
}

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 ,
Feb 14, 2008 Feb 14, 2008

Copy link to clipboard

Copied

LATEST
Awesome!
Here's the mods I made. This works like a charm. If you want to mod the search just change the "pnxx-^9^9^9^9" part and set the PDF preset by changing the "TV0verlay" part.

This one is so much cleaner than the Adobe supplied "Save Each Page as PDF" script.
++++++++++++++++++++++++++++++++++

var destinationFolder = Folder.selectDialog ("Choose a Folder");

var myPDFExportPreset = app.pdfExportPresets.item("TV0verlay");

doc = app.activeDocument;
doc.sections.everyItem().includeSectionPrefix = false;
app.findTextPreferences = null;
app.findTextPreferences.findWhat = 'pnxx-^9^9^9^9';
found = doc.findText();
for (i = 0; i < found.length; i++ )
{
f = File (destinationFolder + "/" + found.contents + '.pdf');
app.pdfExportPreferences.pageRange = found.parentTextFrames[0].parent.name;
doc.exportFile (ExportFormat.pdfType, f, false, myPDFExportPreset);
}
+++++++++++++++++++++++++++++++++++

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