Jump to content

Reference variable PDF graphics in input data


Recommended Posts

I have a basic ?, I am with a direct mailing compnay and we have some automated programs where we could have a thousand different graphics to use on a single mailing, now I dont want to type in these pdf names every week, on our data file there will be a field with this pdf name, how do I make a rule to look at this field for the name of the pdf and how do I script the location of these pdf's or is there a way that we can put them on the printer, right now I work in desktop pc enviroment but the printer has a unix box on it. We are right now looking at maybe changing over to fusion Pro but I have to know we can do this.
Link to comment
Share on other sites

  • 2 weeks later...

In Graphic rules, the CreateResource function allows you to reference

any graphic, by file name, without having to add a Graphic Resource

to the list in the Resources dialog. You can use any kind of graphic

that FusionPro supports, which is basically all common formats,

including TIF, GIF, JPG, PNG, BMP, EPS, and PDF. (In Text rules, you

can use CreateResource to return the contents of a text file.)

The first parameter to CreateResource is a string that specifies the

full name of the file on disk. It can include the full path to the

file, or it can include a relative path, or it can be just the file

name itself, in which case FusionPro will try to find it in the

search path. Since this is JavaScript, the string can either be a

literal string, like "MyGraphic.png", or it can be built from

variables, such as a field name. Also, as the example shows, the

FusionProResource object returned by CreateResource can itself be

either returned directly from a rule, or assigned to another

variable. There's a lot of flexibility, and what the examples show

may not be what you want to do in your job.

Note that the second parameter to CreateResource, the type of the

resource, is optional. If you're in a Graphic rule, it will assume

the type is "graphic". The third parameter (nonExistOK) is optional

as well; if it's not specified, it will default to false, which means

that you'll get an error if the graphic doesn't exist. If you want

to check the graphic's existence via the .exists property, as in the

example, and take some other action if it's missing, then you really

do need that third parameter in the first call. So the example rule

should look like so:

Pic = CreateResource(Field("Last Name") + ".tif", "graphic", true);

if (Pic.exists)

return Pic;


return CreateResource("PhotoNotAvailable.jpg");

This assumes that there's a TIF file for each "Last Name" field. For

instance, if the last name is Smith, there's a graphic called

Smith.tif, and if the last name is Jones, there's a Jones.tif, etc.

If the .tif file does not exist for the field value in a particular

record, it calls out a default placeholder picture.

If the files are JPG files instead, you could do this:

return CreateResource(Field("Last Name") + ".jpg");

Often, the full name of the graphic, including the extension, will be

specified in a data field, in which case you don't need to add the

extension in the rule; for instance:

return CreateResource(Field("customer_picture"));

If you have EPS files, they probably have the ".eps" extension

(although the extension is optional, especially on Mac), so you

probably want to do something like:

return CreateResource(Field("Name") + ".eps");

Again, this assumes that if the value of the "Last Name" field is

"Joe Johnson", there will be a graphic named "Joe Johnson.eps", in a

location where FusionPro will find it. If the graphics are not in

the same folder as the template PDF or the input file, you will

either need to add their location to the search path (in your

Composition Settings, Advanced tab) or specify the full path in the

CreateResource call. If you're on Windows, you'll need to remember

to double-escape any backslashes in the path, for instance:

return CreateResource("C:\\MailerJob\\resources\\customer pictures\

\Joe Johnson.eps");

Also, even though the example rule returns an alternate resource if

the graphic specified doesn't exist, you don't have to do this. If

your Graphic rule doesn't return a valid resource, you'll simply get

a composition warning and nothing will appear in your output.

Returning a placeholder graphic is completely optional; you may want

to do something different in your job.

If you have named resources in the Resources dialog, you would use

the Resource function instead of CreateResource, like so:

return Resource("MainLogo");

Which would return the graphic resource named "MainLogo", regardless

of the name of the graphic file it's pointing to. (For instance, you

could have a resource named "MainLogo" that points to a file named

"PrintableLogoLarge.tif".) Creating resources is handy if you want

to reference files in various locations without having to specify the

path in JavaScript. It will also ensure that the Resource files are

collected with the job, if you're uploading to FusionPro Web or

otherwise composing on a different Server machine.

You can also mix calls to Resource and CreateResource in the same

rule, as the InsertPicture rule template shows.

Also, if you're simply returning named resources from the list, you

can use the Switch Wizard to build your rules, as in the Frodo Travel

sample, in which case you don't need to use JavaScript at all.

I hope this information is helpful.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...