Jump to content

Multiple Business Card back images rule


mjlongo

Recommended Posts

Hello,

 

I have a business card that allows a customer to upload anywhere from one to five different images for the back of the card. I have created a fusion pro document that contains the front of the card then back one, the front of the card then back two, etc for a total of ten pages.

 

For each of the 5 backs of the cards, I have created an image box that covers the entire back. Each one of these graphic boxes are labeled "Graphic1", "Graphic2", "Graphic3", etc.

 

In the same folder as my fusionPro document, I have five sample graphic files. They are all named "sample1.jpg", "sample2.jpg", etc. Each graphic file is assigned a matching resource within the fusion pro document. For example I have a resource called image1 that is assigned sample1.jpg, etc for all five resources.

 

So, this is what I am trying to do: If a customer uploads just one image file, I want that file to be applied to all backs . If a customer uploads image 1 and then uploads image 2, I want image 1 to stay on back 1 but then image 2 should apply to backs 2,3,4 and 5. Likewise if a customer uploads image 1, image 2 and then image 3. I want image 1 on back 1, image 2 on back 2 and then image 3 on backs 3,4 and 5. And so forth. Note that there will be a default image if nothing is uploaded at all.

 

To accomplish this, I have been trying to get the following script to work. The script is inside an OnRecordStart.

 

 

var frame1 = FindGraphicFrame("Graphic1");
var frame2 = FindGraphicFrame("Graphic2");
var frame3 = FindGraphicFrame("Graphic3");
var frame4 = FindGraphicFrame("Graphic4");
var frame5 = FindGraphicFrame("Graphic5");

frame1.SetGraphic(Field("Image1"));
frame2.SetGraphic(Field("Image1"));
frame3.SetGraphic(Field("Image1"));
frame4.SetGraphic(Field("Image1"));
frame5.SetGraphic(Field("Image1"));


if (Field("Image2") != "")
   {
       frame2.SetGraphic(Field("Image2"));
       frame3.SetGraphic(Field("Image2"));
       frame4.SetGraphic(Field("Image2"));
       frame5.SetGraphic(Field("Image2"));
   }

if (Field("Image3") != "")
   {
       frame3.SetGraphic(Field("Image3"));
       frame4.SetGraphic(Field("Image3"));
       frame5.SetGraphic(Field("Image3"));
   }

if (Field("Image4") != "")
   {
       frame4.SetGraphic(Field("Image4"));
       frame5.SetGraphic(Field("Image4"));
   }

if (Field("Image5") != "")
   {
       frame5.SetGraphic(Field("Image5"));
   }

 

 

The problem is, that it is just not working. I am getting blank pages. I am also getting the following errors on compose: "Graphic is not found or is not processed properly: image1". That error appears for each graphic resource. I do not have that error if I omit the script and then place "image1" resource directly into the graphics box. Therefore I cannot see why there would be an issue finding the resource. Should I be placing the images in some other location?

 

I'm also curious to see if there may be some better ideas or solutions to this type of business card and what I'm trying to do. I'm open to any and all ideas.

 

Thanks!

Link to comment
Share on other sites

I think you just need to call either Resource or CreateResource on the field value, like so:

frame1.SetGraphic(Resource(Field("Image1")));

The repetetive logic could also be reduced quite a bit with a for loop such as "for (var i = 1; i <= 5; i++)", but I'll leave that as an exercise for others.

Link to comment
Share on other sites

Thank you for the response. Your suggestion of using the "resource" worked when I replace the lines you mention and compose the document. However, when I upload the document and place it on MarcomCentral where someone can upload the images backs, it fails to work. The card will not apply the uploaded image and/or in some cases, it is using the resource from the library of images.
Link to comment
Share on other sites

Thank you for the response. Your suggestion of using the "resource" worked when I replace the lines you mention and compose the document. However, when I upload the document and place it on MarcomCentral where someone can upload the images backs, it fails to work. The card will not apply the uploaded image and/or in some cases, it is using the resource from the library of images.

Okay, this is now a MarcomCentral-specific question, which really should be asked on the MarcomCentral forum.

 

That said, I suspect that the problem is that the uploaded image files have different file names than the file names associated with your resources. So if you want to support arbitrary uploaded file names, you need to forgo the named resources, put file names instead of resource names in your data file, and then use CreateResource on those file names, like so:

frame1.SetGraphic(CreateResource(Field("Image1", "graphic")));

Link to comment
Share on other sites

If the backs are variable, it seems to me you could achieve the same thing by having a two-paged template that is repeated by the number of backs that have been uploaded. I'm not sure what's the point of returning a 10 page preview if all of the fronts and backs are identical (i.e. they uploaded 1 or 0 custom backs). Instead you could count the number of backs that they've uploaded, repeat the record that many times and change the graphic on the back page for each time the record repeats itself:

var backs = [Field("Image1"),Field("Image2"),Field("Image3"),Field("Image4"),Field("Image5")].filter(String).map(function(s){ return CreateResource(s, 'graphic');});
FusionPro.Composition.repeatRecordCount = backs.length;
var back = backs[FusionPro.Composition.repeatRecordNumber-1] || CreateResource("DefaultBack.pdf", 'graphic');
FindGraphicFrame("Graphic1").SetGraphic(back);

In the above code, the "backs" array contains the 5 "custom back" fields. The array is filtered and the empty fields are removed. Then the record is repeated by the length of the array. As it repeats the record, it steps through the "backs" array and assigns the contents to the graphic frame on the back page. If "backs" is empty, it assigns a default image to the back page.

 

If for some reason you need to return a 10 page preview (5 cards) regardless of how many unique backs there are, you could do so like this:

var back = 'DefaultBack.pdf';
var backs = [Field("Image1"),Field("Image2"),Field("Image3"),Field("Image4"),Field("Image5")].map(function(s){ back = (s) ? s : back; return CreateResource(back,'graphic');});
FusionPro.Composition.repeatRecordCount = 5;
FindGraphicFrame("Graphic1").SetGraphic(backs[FusionPro.Composition.repeatRecordNumber-1]);

Link to comment
Share on other sites

Thank you for the reply STEP. I will give your suggestions a try on another test card to see if I can streamline the process.

 

At the moment, I got the card to work with some changes to the script. I had to employ the "CreateResource" methods as described earlier. The remaining issues are now with MarcomCentral (the crop tool in particular) and I am working with their support team on those issues.

 

Thanks!

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