JeremyT Posted January 22, 2014 Posted January 22, 2014 I am working on a job where I'd like the output pdf to have characters from the input file name. Input file name: ORDERS_01172014_073000_DOOR.xls I'd like the final pdf to be named: FORM-01172014_073000.pdf I've done something similar on this post with code that Dan suggested: http://forums.pti.com/showpost.php?p=14231&postcount=10 This code was used in a OnRecordStart. if (FusionPro.Composition.processedRecordNumber == 1 || (FieldChanged("Form Type") && Field("Form Type")=="Form F")) { var outputPrefix = Field("Form Type")=="Form F" ? "Form F" : "Combined"; var outputName = GetFileName(FusionPro.Composition.inputFileName).replace(/^[^1-9]*([^\.]*)20(\d{2})\.\w+$/,outputPrefix+'-$1$2.'); var outputPath = "/some path here/folder/etc/"; // or base this on a field value, or whatever FusionPro.Composition.OpenNewOutputFile(outputPath + outputName + FusionPro.Composition.outputFormatExtension); Print("Changing to output file: " + outputName + FusionPro.Composition.outputFormatExtension); }This time is simpler in that I am only outputting 1 pdf. How do I adjust? Thanks, Jeremy Quote
Dan Korn Posted January 22, 2014 Posted January 22, 2014 I am working on a job where I'd like the output pdf to have characters from the input file name. Input file name: ORDERS_01172014_073000_DOOR.xls I'd like the final pdf to be named: FORM-01172014_073000.pdf It's hard to know from just one data point. Will the input file always start with "ORDERS"? Will it always end with "DOOR.xls"? Can you show examples of other input file names, and the desired output file names, so that I can see the pattern? Quote
JeremyT Posted January 22, 2014 Author Posted January 22, 2014 Input file most often starts with "ORDERS" and ends with "DOOR.xls". Only 1 or 2 a month that don't. But, I also have a Spanish version of this job that is run a couple of days each month with input files like: ORDERS_11042013_073000_DOOR SP.txt Is there a way to capture just the numerals with the underscore between so that I could use the same code for both versions(English and Spanish)? Screen shots of the input and output files are attached. Quote
Dan Korn Posted January 22, 2014 Posted January 22, 2014 Try this: var outputName = "FORM" + GetFileName(FusionPro.Composition.inputFileName).replace(/[^\d_]/g, '') + "." + FusionPro.Composition.outputFormatExtension;And after that, you can just call FusionPro.Composition.OpenNewOutputFile with that file name, or prepend a path to it first if you want. Quote
JeremyT Posted February 3, 2014 Author Posted February 3, 2014 Can the underscores before and after the numerals be eliminated? Right now it produces: FORM_01172014_073000_.pdf I'd like it to be: FORM-01172014_073000.pdf I know how to add the hyphen, but I am unsure how to remove the underscores. Quote
step Posted February 3, 2014 Posted February 3, 2014 var outputName = "FORM-" + GetFileName(FusionPro.Composition.inputFileName).match(/\d+_\d+/g)[0] + "." + FusionPro.Composition.outputFormatExtension; Quote
JeremyT Posted February 3, 2014 Author Posted February 3, 2014 var outputName = "FORM-" + GetFileName(FusionPro.Composition.inputFileName).match(/\d+_\d+/g)[0] + "." + FusionPro.Composition.outputFormatExtension; I get the error "OnJobStart, line 1:TypeError: GetFileName(FusionPro.Composition.inputFileName).match(/\d+_\d+/g) has no properties" using the code above. Quote
step Posted February 3, 2014 Posted February 3, 2014 It appears you put a space between the "m" and "atch" Quote
JeremyT Posted February 3, 2014 Author Posted February 3, 2014 It appears you put a space between the "m" and "atch" I copied the code from this forum page. For some reason, when I typed the error code my response had the extra space in it. The code in my pdf does not have the extra space in it. Quote
step Posted February 3, 2014 Posted February 3, 2014 ok... Try this then: var outputName = "FORM-" + GetFileName(FusionPro.Composition.inputFileName).replace(/^[^_]*_(\d+_\d*).*$/g,'$1') + "." + FusionPro.Composition.outputFormatExtension; Quote
Dan Korn Posted February 3, 2014 Posted February 3, 2014 I get the error "OnJobStart, line 1:TypeError: GetFileName(FusionPro.Composition.inputFileName).match(/\d+_\d+/g) has no properties" using the code above. JavaScript's String.match function can return null if there's no match found, so you should write your code to be able to handle that condition. Also, you'll definitely fail to get a match at rule validation time, in the Rule Editor, because FusionPro.Composition.inputFileName represents an empty string in that context. Like the rest of the properties of the FusionPro.Composition object, it's valid only at composition time. So it should work when you compose, as long as the input file name conforms to the pattern you specified in the original post, i.e. it matches the regular expression pattern /\d+_\d+/ (one or more digits, followed by an underscore, followed by one or more digits). If you want to avoid the error, both in the case where the file name does not follow the convention you're expecting, and for rule validation, you can do something like this: var theMatch = GetFileName(FusionPro.Composition.inputFileName).match(/\d+_\d+/g); if (!theMatch) { Print("Input file name does not match the expected format."); } else { // call FusionPro.Composition.OpenNewOutputFile etc... } Or, just use String.replace instead, as step suggests in his most recent post. Quote
JeremyT Posted February 6, 2014 Author Posted February 6, 2014 ok... Try this then: var outputName = "FORM-" + GetFileName(FusionPro.Composition.inputFileName).replace(/^[^_]*_(\d+_\d*).*$/g,'$1') + "." + FusionPro.Composition.outputFormatExtension; This code worked! Thanks! Quote
Recommended Posts
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.