Jump to content

Switch Rule for PDF Resources


Recommended Posts

Hello,

 

Looking for some help on a project I am working on. There are a total of 12 states that have specific plans based on the state and the plan number.

 

AL, AR, DE, MS, NE, NM, NV, OK, PA, WI have 16 plans. So I have 16 PDF's that are 28 page PDF's. There is a field called "Plan" that determines what PDF is needed.

 

KY has 16 different plans determined based on the field "Plan". There are 16 PDF's that are 26 page PDF's.

 

ND has 16 different plans determined based on the field "Plan". There are 16 PDF's that are 28 page PDF's.

 

I attached the rule I am using to pull the correct resource for the first page of my project. I also attached the data file and template. The third page as variable text fields. What I am trying to do is pull page 1, 2 and 3 with the Graphic Switch rule. I would like page 4 to just over flow from the plan PDF's based on the state and plan. I then have state specific forms and endorsements I will then add.

 

Does anyone have any recommendations and am I doing this the long route?

Rule.txt

ASFLIC STM Sample File 2015 05 06.txt

AFSLIC_Short_Term_V1.pdf

Link to comment
Share on other sites

Well, judging from your code (snippet below), it looks like you're trying to build the PDF name.

switch (Field("Plan").toLowerCase()) /////Plan 1/////
{
   case "1":
   {
   switch (Field("State").toLowerCase())
   {
case "KY".toLowerCase():
   {
       var image = Resource("AF ST CERT KY 714 - The National Congress of Employers (NCE) Plan 1 - Accepted - 4-7-15.pdf");
       image.pagenumber = 1
       return image;
   }
   case "ND".toLowerCase():
   {
       var image = Resource("AF ST CERT ND 714 - The National Congress of Employers (NCE) Plan 1 - Accepted - 4-2-15.pdf");
       image.pagenumber = 1
       return image;
   }

default:
	var image = Resource("AF ST CERT 714 - The National Congress of Employers (NCE) Plan 1 - 3-27-15.pdf");
       image.pagenumber = 1
       return image;
}
}
}

switch (Field("Plan").toLowerCase()) /////Plan 2/////
{
   case "2":
   {
   switch (Field("State").toLowerCase())
   {
case "KY".toLowerCase():
   {
       var image = Resource("AF ST CERT KY 714 - The National Congress of Employers (NCE) Plan 2 - Accepted - 4-7-15.pdf");
       image.pagenumber = 1
       return image;
   }
   case "ND".toLowerCase():
   {
       var image = Resource("AF ST CERT ND 714 - The National Congress of Employers (NCE) Plan 2 - Accepted - 4-2-15.pdf");
       image.pagenumber = 1
       return image;
   }

default:
	var image = Resource("AF ST CERT 714 - The National Congress of Employers (NCE) Plan 2 - 3-27-15.pdf");
       image.pagenumber = 1
       return image;
}
}
}
.
.
.
switch (Field("Plan").toLowerCase()) /////Plan 16/////
{
   case "16":
   {
   switch (Field("State").toLowerCase())
   {
case "KY".toLowerCase():
   {
       var image = Resource("AF ST CERT KY 714 - The National Congress of Employers (NCE) Plan 16 - Accepted - 4-7-15.pdf");
       image.pagenumber = 1
       return image;
   }
   case "ND".toLowerCase():
   {
       var image = Resource("AF ST CERT ND 714 - The National Congress of Employers (NCE) Plan 16 - Accepted - 4-2-15.pdf");
       image.pagenumber = 1
       return image;
   }

default:
	var image = Resource("AF ST CERT 714 - The National Congress of Employers (NCE) Plan 16 - 3-27-15.pdf");
       image.pagenumber = 1
       return image;
}
}
}

You don't need a separate 'switch' statement for each case. That defeats the whole purpose of a switch statement. Also, typing a string in all caps and then passing it through a function to make it lowercased is pretty silly. You could just type the string in lowercase from the beginning:

case "ky":
// case "KY".toLowerCase():

But if you want the states listed in all caps, I would just force your "State" field to be all caps and set your switch up like this:

switch (ToUpper(Field("State"))
   {
case "KY":
.
.
.

Along the same lines, there's no point in making your "Plan" field lowercased if you're trying to match numbers. I've never seen a lowercased number, but I imagine they look an awful lot like uppercased numbers. Anyway, you get the idea, that function can go.

 

Anyway, from looking at your rule, it appears that you're trying to build a PDF name with 'switch' rules. To me, it looks like there are 3 basic ways this PDF could be named:

"AF ST CERT 714 - The National Congress of Employers (NCE) Plan [PLAN NUMBER] - 3-27-15.pdf"

"AF ST CERT KY 714 - The National Congress of Employers (NCE) Plan [PLAN NUMBER] - Accepted - 4-7-15.pdf"

"AF ST CERT ND 714 - The National Congress of Employers (NCE) Plan [PLAN NUMBER] - Accepted - 4-2-15.pdf"

 

If that's the case, you can use a switch statement like this:

var image = "AF ST CERT 714 - The National Congress of Employers (NCE) Plan " + Field("Plan") + " - 3-27-15.pdf"
var state = ToUpper(Field("State"));
switch(state){
   case "KY":
       image = "AF ST CERT " + state + " 714 - The National Congress of Employers (NCE) Plan " + Field("Plan") + " - Accepted - 4-7-15.pdf";
   break;
   case "ND":
       image = "AF ST CERT " + state + " 714 - The National Congress of Employers (NCE) Plan " + Field("Plan") + " - Accepted - 4-2-15.pdf";
   break;
}
image.pagenumber = 1;
return image;

 

If you wanted to avoid the switch statement all together and just use a find/replace you could do something like this:

var state = ToUpper(Field("State"));
var plan = Field("Plan");
var date = (state == "KY") ? "4-7-15" : "4-2-15";
var image = "AF ST CERT 714 - The National Congress of Employers (NCE) Plan " + plan + " - 3-27-15.pdf"
image = (~["KY","ND"].indexOf(state)) ? image.replace(/^(.*CERT)(.*)\d+-\d+-\d+(.*)$/,'$1 ' + state + '$2Accepted - ' + date + '$3') : image;
image.pagenumber = 1;
return image;

Link to comment
Share on other sites

Thanks Ste again! Question to input this as a graphic I tried making the rule a text rule and check "Treat returned strings as tagged text" but I just get the name of the pdf in the text box. When I create the rule as a graphic I get an error "This graphic rule must return a Resource of type graphic". How would I set this to input the PDF that is being called from the rule?

 

With one of the states ,KY, all the 16 plans have 26 pages. All other plans have 28 pages. I am going to insert additional pages after the plan. I can insert 2 blank pages in the KY plans to make them even to 28 pages. But I would prefer for the files to not have blank pages as I am going to output each record separately by the fields on the list. Is the only way to do this using the SetBodyPageUsage with an onRecordStart rule? I think if I base the rule off the state I should be able to turn on and off all the pages needed, correct?

Link to comment
Share on other sites

Thanks Ste again! Question to input this as a graphic I tried making the rule a text rule and check "Treat returned strings as tagged text" but I just get the name of the pdf in the text box. When I create the rule as a graphic I get an error "This graphic rule must return a Resource of type graphic". How would I set this to input the PDF that is being called from the rule?

Well you still need to create the resource. If you're putting the image in a text rule you can do this:

return CreateResource(image).content;

 

If you're putting it in a graphic rule:

return CreateResource(image);

 

 

With one of the states ,KY, all the 16 plans have 26 pages. All other plans have 28 pages. I am going to insert additional pages after the plan. I can insert 2 blank pages in the KY plans to make them even to 28 pages. But I would prefer for the files to not have blank pages as I am going to output each record separately by the fields on the list. Is the only way to do this using the SetBodyPageUsage with an onRecordStart rule? I think if I base the rule off the state I should be able to turn on and off all the pages needed, correct?

You definitely don't need to have blanks if they aren't required. I would think the easiest way to do this would be to use a text rule, a text frame on your first page and set it to overflow to your second page (an overflow page). See this thread for more details and an example of how to accomplish that.

Link to comment
Share on other sites

Then maybe you should have a rule that returns page 1, 2 and 3 of the PDF onto their respective pages in the template and then use the link I posted to only pull in page 4 through the rest of the pages using an overflow page. You'd only have to modify the for loop to start at 4 rather than 1.
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...