Jump to content

Accessing page number variable


bhm8hwcm

Recommended Posts

I am trying to write a rule that accesses the page number of the PDF. I know you can access the page number variable when using a text box but I need to access it within a rule for a variable graphic.

 

Is there a way to do this? I am new to javascript and so not sure when writing rules like this can you just refer to the page itself or must you reference the graphic frame on the page?

 

thanks

Link to comment
Share on other sites

Hi thanks.

 

I have a 12pg pdf file and I am dropping an image into each page. My data file will have 12 fields...one field (containing the image name) for each page basically. Field names something like field1, field2, field3

 

Instead of writing a different rule for each page (or even using if...then) I want to use one rule that can be used for the variable graphic frames on all pages. Instead of hard coding the field name to be used for each page I want to setup a variable something like:

var fieldtouse = "field"+pagenum

 

Based on the page number it would know which field to get the picture name from.

 

I know I can set this up by creating 12 separate rules fairly easily. I am trying to be a little more creative though to make things easier down the road and give me more flexibility.

Link to comment
Share on other sites

I have a 12pg pdf file and I am dropping an image into each page. My data file will have 12 fields...one field (containing the image name) for each page basically. Field names something like field1, field2, field3

 

Instead of writing a different rule for each page (or even using if...then) I want to use one rule that can be used for the variable graphic frames on all pages. Instead of hard coding the field name to be used for each page I want to setup a variable something like:

var fieldtouse = "field"+pagenum

 

Based on the page number it would know which field to get the picture name from.

 

I know I can set this up by creating 12 separate rules fairly easily. I am trying to be a little more creative though to make things easier down the road and give me more flexibility.

You don't need 12 separate rules. You just need to go into the Fields dialog (FusionPro -> Data Definition -> Input Options -> Edit Fields), and change the type of each of the fields to Graphic. Then you can go into each graphic frame and assign it the name of a field.

 

Or, you can "inject" the variables for all 12 graphic frames in OnRecordStart, like so:

for (var i = 1; i <= 12; i++)
   FusionPro.Composition.AddGraphicVariable("Graphic" + i, '<graphic file="' + Field("Field" + i) + '">')

You still need to go into each graphic frame and assign it to use the variables Graphic1, Graphic2, etc. But you don't need 12 different rules.

 

Depending on how the graphics are being placed, another possibility might be to use inline graphics, in a variation of this example.

Link to comment
Share on other sites

Hi Dan thanks. Actually I probably should have clarified...I am placing Fusion Expression images not actual pictures.

 

I am using :

Pic1 = CreateResource (Field("file"), "FP Expression Image");

 

it is the "file" variable I am trying to generate based on the pagenumber. Sorry for not being more specific.

 

Attaching the field name to the graphic frame wont therefore work. Would your second solution of injecting the name work using OnRecordStart...I have not worked with this yet.

 

Looks like 12 rules might still be needed?

Link to comment
Share on other sites

Hi Dan thanks. Actually I probably should have clarified...I am placing Fusion Expression images not actual pictures.

 

I am using :

Pic1 = CreateResource (Field("file"), "FP Expression Image");

 

it is the "file" variable I am trying to generate based on the pagenumber. Sorry for not being more specific.

 

Attaching the field name to the graphic frame wont therefore work. Would your second solution of injecting the name work using OnRecordStart...I have not worked with this yet.

 

Looks like 12 rules might still be needed?

Okay, I see. Yes, based on your previous message, I was assuming you were using regular graphics. With FP Expression, it's a bit more complicated, but it can be done all in one rule still.

 

First of all, simply returning an FP Expression template with CreateResource won't get you much, even for one graphic. You also need to supply some data for the image personalization. (For this reason, you can't just use the FP Expression template name directly in a Graphic field, because you need the personalization data as well.)

 

Normally, a rule which calls out to FP Expression would look either like this (assuming there's a field called "Name" with which you want to personalize the image in FP Expression):

var Pic1 = CreateResource(Field("file"), "FP Expression Image");
Pic1.AddData(Field("Name"));
return Pic1;

Or like this:

return PersonalizedImage(CreateResource(Field("file"), "FP Expression Image"), Field("Name"));

Now, to create the personalized image for all twelve pages, I'm assuming you want to create each image with the same personalization data but different FP Expression templates.

 

So the logic in OnRecordStart would look something like this:

for (var i = 1; i <= 12; i++)
{
   var pic = CreateResource(Field("field" + i), "FP Expression Image");
   pic.AddData(Field("Name"));
   FusionPro.Composition.AddGraphicVariable("Graphic" + i, pic.content);
}

Or, using the PersonalizedImage function:

for (var i = 1; i <= 12; i++)
   FusionPro.Composition.AddGraphicVariable("Graphic" + i, PersonalizedImage(CreateResource(Field("field" + i), "FP Expression Image"), Field("name")).content)

Again, I'm assuming that the personalization data is the field called "Name".

 

You do still need to assign the variables Graphic1, Graphic2, etc. to all 12 graphic frames. But it's still just a single rule.

Link to comment
Share on other sites

Hi Dan thanks for this. Unfortunately I was not able to get it to work and I am not sure what I am doing wrong.

 

 

Am getting error:

"No value associated to graphic copyhole <> in record 1"

I set up the OnRecordStart rule as you had it and used the correct field name.

 

A couple things I am not sure of:

- for the graphic frames I named the frames Graphic1, Graphic2, etc. Under the name it asks for the rule or field...I am not sure what this should be. It should not be some rule should it...OnRecordStart is the rule?

 

I also went into (FusionPro -> Data Definition -> Input Options -> Edit Fields), and changed the type of each of the fields to Graphic but I don't think this was required.

 

Not quite sure what is wrong.

Link to comment
Share on other sites

A couple things I am not sure of:

- for the graphic frames I named the frames Graphic1, Graphic2, etc. Under the name it asks for the rule or field...I am not sure what this should be. It should not be some rule should it...OnRecordStart is the rule?

I think what you may need to do is manually type "Graphic1", Graphic2" etc. into the dropdown box just below the frame name.

 

You're probably like me and did not know you could type something in that box instead of choosing an existing rule. That is required when using the FP addGraphicVariable method. If Dan weren't so good about explaining these things on the forums, I'd be more critical of PTI's documentation. ;)

Link to comment
Share on other sites

I think what you may need to do is manually type "Graphic1", Graphic2" etc. into the dropdown box just below the frame name.

 

You're probably like me and did not know you could type something in that box instead of choosing an existing rule. That is required when using the FP addGraphicVariable method.

Yes, Eric is correct, you need to set the variable used for each graphic frame. Setting the name of the graphic frame might help you navigate the Document Overview palette, but it won't assign the picture to use.

 

That said, the rule could be made to work with frame names instead of variable names by using the FindGraphicFrame() and FusionProGraphicFrame.SetGraphic() functions, instead of calling FusionPro.Composition.AddGraphicVariable().

If Dan weren't so good about explaining these things on the forums, I'd be more critical of PTI's documentation. ;)

Aww, thanks!

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...