Jump to content

Label output file with start record and end record


JeremyT

Recommended Posts

I have a large file with 5000 records that I would like to have chunked into 250 records per output pdf.

 

What code do I need so that when outputting files it adds the starting and ending record of that chunk on the output pdf.

 

For example:

 

Output Job 1-250.pdf

Output Job 251-500.pdf

Output Job 501-750.pdf

 

Thanks,

Jeremy

Link to comment
Share on other sites

I think you'd basically just have to name output file the current record (i.e. 1) and then add on the chunk size (i.e. 250) when you're naming the file. Where are you setting the chunk size? If it's in the code, you might do something like this:

OnRecordStart

var chunkSize = 250;
var curr = FusionPro.Composition.inputRecordNumber;
var outputName = "Output Job " + curr + "-" + (curr + (chunkSize-1));
//return outputName // Output Job 1-250;

if (FusionPro.Composition.inputRecordNumber % chunkSize == 1){
   FusionPro.Composition.OpenNewOutputFile(outputName + "." + FusionPro.Composition.outputFormatExtension);
}

 

If you're setting it in the the composition dialog page, you may want to try something like this:

var chunkSize = Int(FusionPro.Composition.JobOptions["RecordsPerChunk"]);
var curr = FusionPro.Composition.inputRecordNumber;
var outputName = "Output Job " + curr + "-" + (curr + (chunkSize-1));
//return outputName // Output Job 1-250;

if (FusionPro.Composition.inputRecordNumber % chunkSize == 1){
   FusionPro.Composition.OpenNewOutputFile(outputName + "." + FusionPro.Composition.outputFormatExtension);
}

Link to comment
Share on other sites

If you're setting it in the the composition dialog page, you may want to try something like this:

var chunkSize = Int(FusionPro.Composition.JobOptions["RecordsPerChunk"]);
var curr = FusionPro.Composition.inputRecordNumber;
var outputName = "Output Job " + curr + "-" + (curr + (chunkSize-1));
//return outputName // Output Job 1-250;

if (FusionPro.Composition.inputRecordNumber % chunkSize == 1){
   FusionPro.Composition.OpenNewOutputFile(outputName + "." + FusionPro.Composition.outputFormatExtension);
}

 

I am chunking it in the composition dialog so I used the code from above. Thanks!

 

The job I am working on has 5076 records so the last pdf output is labelled 5001-5250.

 

Is there a way to have it labelled by the last record in the output pdf?

 

Jeremy

Link to comment
Share on other sites

You can do a check to see if the chunk is going to be less than the total number of records. If it is, use the chunk size. If it isn't, you know you're at the last chunk and you should just use the total number of records instead:

var chunkSize = Int(FusionPro.Composition.JobOptions["RecordsPerChunk"]);
var curr = FusionPro.Composition.inputRecordNumber;
var totalRecords = FusionPro.Composition.totalRecordCount;
var range = curr + (chunkSize-1);

if (range >= totalRecords) {
   range = totalRecords;
}
var outputName = "Output Job " + curr + "-" + range;

if (FusionPro.Composition.inputRecordNumber % chunkSize == 1){
   FusionPro.Composition.OpenNewOutputFile(outputName + "." + FusionPro.Composition.outputFormatExtension);
}

 

Keep in mind that "FusionPro.Composition.totalRecordCount" requires preprocessing to be done before it's accessible. If you are using an imposition then FP preprocesses already, if not you will need to force preprocessing in the OnJobStart callback:

FusionPro.Composition.forcePreprocessing = true;

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...