Jump to content

Pad Batched Output Numbers with Zeros


Recommended Posts

When composing chunked output files FP appends a number to the end of the filename. Is there a way to pad that number with zeros?

Yes, if you create the OnNewOutput file rule, you can name the output file whatever you want by setting FusionPro.Composition.outputFileName. You can base it on a record number such as FusionPro.Composition.processedRecordNumber, or you can keep your own global counter variable. You can use FormatNumber to pad with zeros.

Link to comment
Share on other sites

  • 3 years later...

Dan, a while back you had given me this script to pad zeros in a batched output file where I could set the amount of padding...

if (Int(FusionPro.Composition.JobOptions["FinalPrint"]))  {
var oldEnding = FusionPro.Composition.currentOutputFileNumber +
   "." + FusionPro.Composition.outputFormatExtension
var originalNameNoExt = FusionPro.Composition.outputFileName.replace(oldEnding, "");
FusionPro.Composition.outputFileName = originalNameNoExt + 
   FormatNumber("000", FusionPro.Composition.currentOutputFileNumber) +
   "." + FusionPro.Composition.outputFormatExtension;
}

Up to now it has been working like a charm...as do most if not all of your suggestions...however I have now made the jump to FusionPro 9.3.15 (need to update my signature line) and it is not working as per normal.

 

I would expect output names such as..."JobName_001.pdf", "JobName_002.pdf", "JobName_003.pdf", and so on. I've set it to 3 digits in the script so I expect a three digit number with leading zeros. However I am now getting "JobName_1001.pdf", "JobName_1002.pdf", "JobName_1003.pdf". FOUR digits and the first is always a "1".

 

At first I thought it might be because the batched amount was going to be larger that the 3 digits will allow, but what I added a fourth zero to the script it just added another zero to the padded section and still put the 1 in front.

 

Also if I put the extension ".pdf" in the output name section command line I'm giving to FP Server I get output names like "JobName_.pdf1001.pdf", "JobName_.pdf1002.pdf", "JobName_.pdf1003.pdf".

 

What happened from FP8 to FP9? A new command for padding zeros in the output?

 

.

Link to comment
Share on other sites

David, that sounds like the issue that was being discussed here where there was a 1 being appended to the file name in earlier versions of FP9. However, Dan also says that problem was fixed in the 9.3.12 release so if you're running 9.3.15, I wouldn't think it's the same problem but it sounds too familiar not to bring up.

 

That being said, I guess you could try to remove all numbers preceeding the extension and replacing it with the formatted output file number (rather than just replacing the output file number and extension):

FusionPro.Composition.outputFileName = FusionPro.Composition.outputFileName.replace(new RegExp('\\d*\\.' + FusionPro.Composition.outputFormatExtension + '$',''), function(){return FormatNumber("000", FusionPro.Composition.currentOutputFileNumber) + "." + FusionPro.Composition.outputFormatExtension;});

Link to comment
Share on other sites

Thanks Step. If I use your expression would that only remove the number exactly prior to the extension such as just the 1 in the name "JobNumber_1.pdf"?

 

Would that expression also effect the number 12345 as is "12345-JobName_1.pdf", or again would it only effect the "1.pdf"?

 

I sometimes have to put job numbers within the name of the output file prior to a "descriptive name" or "client name" in the output file.

Link to comment
Share on other sites

The regular expression is starting at the end of the file and matching the extension, the period, and then as many numbers as it can find so in your example it would match (in red):

12345-JobName_1.pdf

 

As long as you have the underscore separating the JobName, you should be safe.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...