Jump to content

Use Input Date File Name For Output File Name


Pierhouse

Recommended Posts

When creating my output PDF file I am wanting the output file name to be based upon the name of the seletcted input data file.

 

For example:

 

Selected data input file name: Std4_0310.txt

 

Desired PDF output file name: Std4_0310.pdf

 

I have tried to acheive this using the following OnNewOtputFile rule:

 

FusionPro.Composition.OutputFileName = FusionPro.Composition.InputFileName

 

The rule validates ok but I'm obviously doing something wrong as it still creates the output file with the name designated within the Compose Template-Output-Ouput Filename section.

 

Any ideas would be greatly appreciated.

 

G

:)

Edited by Pierhouse
Link to comment
Share on other sites

Callback rules do not need to be placed into text frames. Actually, they can't be used that way. They're different than regular rules which return a value for composition. Instead, they're hooks into specific composition-time functionality.

 

 

The complete list of callback rules is:

  • OnJobStart
  • OnJobEnd
  • OnRecordStart
  • OnRecordEnd
  • OnNewOutputFile
  • OnCopyfit

To create them, click on "New" in the Rules dialog, then select the "Callback" radio button.

Link to comment
Share on other sites

Thanks Dan. I can now see the error of my ways. I didn't realise that the "inputFileName" and "outputFileName" parts are case sensitive.

 

The only thing is that when using that rule my preview no longer works for some reason. As soon as I remove the rule the preview works. Any ideas??

 

Cheers

 

G

Link to comment
Share on other sites

Thanks Dan. I can now see the error of my ways. I didn't realise that the "inputFileName" and "outputFileName" parts are case sensitive.

 

Yes, property names in JavaScript are case-sensitive. The file names may also be case-sensitive, depending on the operating system. (Mac is case-sensitive, while Windows is generally not, although some shared network drives may be case-sensitive even when mounted on Windows.)

 

The only thing is that when using that rule my preview no longer works for some reason. As soon as I remove the rule the preview works. Any ideas??

 

Can you be more precise about the failure mode? In exactly what way does Preview not work?

Link to comment
Share on other sites

Sorry, the preview no longer works in as much as when I click the preview button in the Preview pane the screen refreshes, automatically deselects the tick in the preview button but does not preview anything.

 

Ah, sorry, that's a bug.

 

The workaround is to use the FusionPro.Composition.isPreview property to disable the output file rename for Preview. For example:

if (!FusionPro.Composition.isPreview)
   FusionPro.Composition.outputFileName = FusionPro.Composition.inputFileName + ".pdf";

This is on our list of issues to address. Please reference case FP-11072.

Link to comment
Share on other sites

I'm unable to find the case you refer to (FP-11072) Where are all the recorded cases held?

That's a case number in our internal defect-tracking system. It's not generally accessible to customers. But you can reference that case number in any subsequent inquiries about the issue, so that we can track it.

Link to comment
Share on other sites

  • 2 weeks later...
Ah, sorry, that's a bug.

 

The workaround is to use the FusionPro.Composition.isPreview property to disable the output file rename for Preview. For example:

if (!FusionPro.Composition.isPreview)
   FusionPro.Composition.outputFileName = FusionPro.Composition.inputFileName + ".pdf";

This is on our list of issues to address. Please reference case FP-11072.

 

This is great, but is there a way to trim the file extension of the input file? For instance myinputfile.csv.pdf to be myinputfile.pdf?

Link to comment
Share on other sites

Hi Chad

 

Create a Rule of type Callback and select OnNewOuputFile. This rule will then be called when a new output file is about to be opened.

 

Use the below code within the rule to create the output filename using the input file name, stripping off the extention and adding .pdf.

 

PDFName = FusionPro.Composition.inputFileName;

FullName = PDFName.split(".");

FileName = FullName[0];

FileExt = FullName[1];

FusionPro.Composition.outputFileName = FileName + ".pdf"

 

Hope this helps

 

G

Link to comment
Share on other sites

Chad,

 

I've used this in the OnJobStart callback rule to get the incoming file name. You could then store it off to a variable and call it when you do your output file creation as in the rule mentioned in the above postings. This was done on a PC so if you need a Mac version simply put in the correct string to look for in the lastIndex rule.

 

inFile = ToLower(FusionPro.Composition.inputFileName);

var i = inFile.lastIndexOf("\\");

myInputFile = Mid(inFile, i+2, (inFile.length - i));

replaceCheck1 = ReplaceSubstring(myInputFile, ".csv", "");

finalFileName = ReplaceSubstring(replaceCheck1, ".txt", "");

 

 

This will give you the finalFileName value of instance file that you are using for your composition but without any extension. I don't know if you normally use a "csv" or a "txt" file for your data, but you should leave both in there to remove either case. Again if you're on a Mac you do need to watch out for those few programmers that like to use dots within the middle of filenames since that string might appear twice.

 

Good Luck ;)

Link to comment
Share on other sites

  • 3 years later...

any ideas why I would be getting "R:\70948-J and 70949-K\FP data\J240B.TXT.pdf" as my name, when my input name is "J 240 B_.TXT"??

I've never tried it off of the input name, but I've had success using static text + fields. I tried taking the spaces and underscore out of my original data name, but no success.

Link to comment
Share on other sites

any ideas why I would be getting "R:\70948-J and 70949-K\FP data\J240B.TXT.pdf" as my name, when my input name is "J 240 B_.TXT"??

I've never tried it off of the input name, but I've had success using static text + fields. I tried taking the spaces and underscore out of my original data name, but no success.

What JavaScript logic are you using which gives those results? I would just do this:

if (!FusionPro.Composition.isPreview)
   FusionPro.Composition.outputFileName =
       ReplaceFileExtension(GetFileName(FusionPro.Composition.inputFileName),
       FusionPro.Composition.outputFormatExtension);

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