ricky10ss Posted March 1, 2017 Share Posted March 1, 2017 I am trying to figure out the most simple way to import multiple pdf's that have the same variable text boxes in the same location but on different pages. Below are the document names and the page the variable text fields are on. Everyone gets the standard form but if they are in any of the states below they get that specific state form. LNG-3001 (Standard form - Page 20) LN-3001 CO (Colorado – Page 21) LN-3001 LA (Louisiana – Page 24) LN-3001 MO (Missouri – Page 20) LN-3001 NC (North Carolina – Page 26) LN-3001 NV (Nevada – Page 23) LN-3001 SD (South Dakota – Page 22) In the past I was able to use the code below to import specific pages till I got to the variable page 4 then import the rest of the pages since all documents had the variable on the same page. Bringing in specific page: var image = CreateResource(path + image,"graphic",true); image.pagenumber = 1; return image; Then the last pages after page 4: var result = []; var r = CreateResource(path + image,"graphic",true); for (r.pagenumber = 4; r.pagenumber <= r.countPages; r.pagenumber++) result.push(r.content); return result.join("<p>\n"); Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted March 2, 2017 Share Posted March 2, 2017 Sorry, it's not clear to me what you're trying to do. Perhaps seeing some of the PDFs in question, and the desired output, would be illuminating. Quote Link to comment Share on other sites More sharing options...
ricky10ss Posted March 2, 2017 Author Share Posted March 2, 2017 Attached are two documents. LNG-3001.pdf is the standard form and has the variable boxes only all states except CO, LA, MO, NC, NV and SD. LN-3001 CO.pdf is the form only for CO. The variable text boxes are on page 21. Each state form has the variable boxes on different pages.LN-3001 CO.pdfLNG-3001.pdf Quote Link to comment Share on other sites More sharing options...
step Posted March 2, 2017 Share Posted March 2, 2017 Ignoring the fact that the two forms in the PDFs you posted do not appear to have the variable frames in the same location, one option you have is to: Create an 8.5x11 template Put a graphic frame on it that will return your graphic rule Duplicate that page FusionPro > Manage Pages > Page Usage and name the first page "page" and the second page "form" Draw your variable frames on the "form" page Create an onRecordStart rule that toggles the appropriate body page based on the state OnRecordStart var [ver, state] = Field("version").split(' '); var pdf = CreateResource('/path/to' + Field("version") + '.pdf', 'graphic', true); var pages = pdf.countPages; var form = 20; switch(state) { case 'CO': form = 21; break; case 'LA': form = 24; break; case 'NC': form = 26; break; case 'NV': form = 23; break; case 'SD': form = 22; break; } FusionPro.Composition.repeatRecordCount = pages; var isForm = FusionPro.Composition.repeatRecordNumber == form; FusionPro.Composition.SetBodyPageUsage('page', !isForm); FusionPro.Composition.SetBodyPageUsage('form', isForm); If the variable frame locations move based on the state, you may have to create a body page for each form, set them all to unused, and name them "form," "form-CO," "form-NC," etc. Then you'd modify the OnRecordStart code: FusionPro.Composition.SetBodyPageUsage(['form',state].filter(Boolean).join('-'), isForm); Quote Link to comment Share on other sites More sharing options...
ricky10ss Posted March 2, 2017 Author Share Posted March 2, 2017 Thanks Ste. Yes I noticed that after as well that the text boxes are not in the same locations. So with this rule you are just pulling in the specific pages correct? What if I need to pull in the whole form all pages for the standard form and all pages for the state forms? The only way I could think is make a page for all the common count pages till each variable pages then bring in the pages after. But the issue there is MO state form only has 22 total pages. Some of the state forms variable pages are past page 22. Quote Link to comment Share on other sites More sharing options...
step Posted March 2, 2017 Share Posted March 2, 2017 So with this rule you are just pulling in the specific pages correct? No. The rule that I posted is not pulling in any pages. It's counting the number of pages in the document and repeating the record by that number. For example, when the version is "LN-3001 CO," it counts the number of pages in "LN-3001 CO.pdf." Since there are 24 pages in that file, that record will be repeated 24 times. The rule will enable the "form-CO" body page the 21st time the record is repeated. Pulling in the pages would be done in the graphic rule and would look something like this: var pdf = CreateResource('/path/to/' + Field("Version") + '.pdf'); pdf.pagenumber = FusionPro.Composition.repeatRecordNumber; return pdf; What if I need to pull in the whole form all pages for the standard form and all pages for the state forms? So all pages in "LNG-3001.pdf" and all pages in "LN-3001 CO.pdf"? You'd do the same thing except you'd repeat the record by the number of pages in both files and you'd have to edit which pages the forms fall on for each state. For example: "LNG-3001.pdf" has 22 pages so you'd have to adjust the "form" page for "CO" by 22 pages: case 'CO': form = 43; break; //21st page + 22 pages in LNG-3001.pdf You'd also have to change your graphic rule a little bit: var pdf = CreateResource('/path/to/LNG-3001.pdf'); var page = FusionPro.Composition.repeatRecordNumber; var pages = pdf.countPages; if (page > pages) { page -= pages; pdf = CreateResource('/path/to/' + Field("Version") + '.pdf'); } pdf.pagenumber = page; return pdf; The only way I could think is make a page for all the common count pages till each variable pages then bring in the pages after. But the issue there is MO state form only has 22 total pages. Some of the state forms variable pages are past page 22. I don't think I follow what you're suggesting here but I don't think it's something you should be concerned with if you use the method I've detailed here. Quote Link to comment Share on other sites More sharing options...
ricky10ss Posted March 2, 2017 Author Share Posted March 2, 2017 Sorry I am not trying to combine "LNG-3001.pdf" and all pages in "LN-3001 CO.pdf". So it sounds like your first response is what I am trying to do. With the code you posted below I have another question. How would I call the forms only from a field called State? I don't have a field calling out the specific name of the form. All I have in data provided to me is the State. So if the state equals to CO then I need to pull the resource "LN-3001 CO.pdf" and so one for LA, NC, NV, SD. All other states get "LN-3001.pdf". var [ver, state] = Field("version").split(' '); var pdf = CreateResource('/path/to' + Field("version") + '.pdf', 'graphic', true); var pages = pdf.countPages; var form = 20; switch(state) { case 'CO': form = 21; break; case 'LA': form = 24; break; case 'NC': form = 26; break; case 'NV': form = 23; break; case 'SD': form = 22; break; } FusionPro.Composition.repeatRecordCount = pages; var isForm = FusionPro.Composition.repeatRecordNumber == form; FusionPro.Composition.SetBodyPageUsage('page', !isForm); FusionPro.Composition.SetBodyPageUsage('form', isForm); Quote Link to comment Share on other sites More sharing options...
step Posted March 2, 2017 Share Posted March 2, 2017 How would I call the forms only from a field called State? I don't have a field calling out the specific name of the form. All I have in data provided to me is the State. There are several ways you can do that. One way is to write some if/if else/else statements like you mentioned. So if the state equals to CO then I need to pull the resource "LN-3001 CO.pdf" and so one for LA, NC, NV, SD. All other states get "LN-3001.pdf". if (Field("State") == "CO") { var pdf = "LN-3001 CO.pdf"; } else if (Field("State") == "LA") { var pdf = "LN-3001 LA.pdf"; } // ... else { var pdf = "LN-3001.pdf"; } But since we already have that switch statement for those states, we can just key off of that 'form' value instead: var state = Field("State"); var pdf = '/path/to/LN-3001'; var form = 20; switch(state) { case 'CO': form = 21; break; case 'LA': form = 24; break; case 'NC': form = 26; break; case 'NV': form = 23; break; case 'SD': form = 22; break; } if (form > 20) pdf += ' ' + state; pdf = CreateResource(pdf + '.pdf', 'graphic', true); Quote Link to comment Share on other sites More sharing options...
ricky10ss Posted March 3, 2017 Author Share Posted March 3, 2017 I created a OnRecordStart rule using the last bit of code you sent but nothing seems to be happening. I validate rule and Expression is OK. Do I need to do something with the graphic frame since no variable is assigned? Could it be this is incorrect? var pdf = 'G:\VP\Variable Elements\LifeShield\LN-3001.pdf'; Quote Link to comment Share on other sites More sharing options...
step Posted March 3, 2017 Share Posted March 3, 2017 Do I need to do something with the graphic frame since no variable is assigned? No variable is assigned? I said you need to create a graphic rule to return the graphic: Pulling in the pages would be done in the graphic rule and would look something like this: var pdf = CreateResource('/path/to/' + Field("Version") + '.pdf'); pdf.pagenumber = FusionPro.Composition.repeatRecordNumber; return pdf; Quote Link to comment Share on other sites More sharing options...
ricky10ss Posted March 3, 2017 Author Share Posted March 3, 2017 Sorry Step I am definitely confused. Sorry. So I should I still use this code for the onRecordStart ? var [ver, state] = Field("version").split(' '); var pdf = CreateResource('/path/to' + Field("version") + '.pdf', 'graphic', true); var pages = pdf.countPages; var form = 20; switch(state) { case 'CO': form = 21; break; case 'LA': form = 24; break; case 'NC': form = 26; break; case 'NV': form = 23; break; case 'SD': form = 22; break; } FusionPro.Composition.repeatRecordCount = pages; var isForm = FusionPro.Composition.repeatRecordNumber == form; FusionPro.Composition.SetBodyPageUsage('page', !isForm); FusionPro.Composition.SetBodyPageUsage('form', isForm); Or this one as the OnRecordStart? var state = Field("State"); var pdf = '/path/to/LN-3001'; var form = 20; switch(state) { case 'CO': form = 21; break; case 'LA': form = 24; break; case 'NC': form = 26; break; case 'NV': form = 23; break; case 'SD': form = 22; break; } if (form > 20) pdf += ' ' + state; pdf = CreateResource(pdf + '.pdf', 'graphic', true); Do all the "form" and "page" pages get the same graphic variable assigned to them? I used this below. Right now only the first page comes in when I compose. if (Field("State") == "CO") { var pdf = "LN-3001 CO.pdf"; } else if (Field("State") == "LA") { var pdf = "LN-3001 LA.pdf"; } else if (Field("State") == "NC") { var pdf = "LN-3001 NC.pdf"; } else if (Field("State") == "NV") { var pdf = "LN-3001 NV.pdf"; } else if (Field("State") == "SD") { var pdf = "LN-3001 SD.pdf"; } // ... else { var pdf = "LN-3001.pdf"; } var pdf = CreateResource('G:\\BTS\\Variable Elements\\LifeShield STM UltraCare\\' + pdf ); pdf.pagenumber = FusionPro.Composition.repeatRecordNumber; return pdf; Quote Link to comment Share on other sites More sharing options...
step Posted March 3, 2017 Share Posted March 3, 2017 Do all the "form" and "page" pages get the same graphic variable assigned to them? I used this below. Right now only the first page comes in when I compose. Yes, you should have the same graphic variable assigned to the graphic frame on every page. You should only have 1 "page" body page. In addition to that, you should have the following body pages (all set to "unused"): form form-CO form-LA form-NC form-NV form-SD Each of those "form*" body pages should have the variable frames required by that version's form in the positions required by that version's form. Your OnRecordStart should have this (and only this) in it: var state = Field("State"); var file = 'LN-3001'; var form = 20; switch(state) { case 'CO': form = 21; break; case 'LA': form = 24; break; case 'NC': form = 26; break; case 'NV': form = 23; break; case 'SD': form = 22; break; } if (form > 20) file += ' ' + state; pdf = CreateResource('G:\\BTS\\Variable Elements\\LifeShield STM UltraCare\\' + file + '.pdf', 'graphic', true); var pages = pdf.countPages; FusionPro.Composition.repeatRecordCount = pages; var isForm = FusionPro.Composition.repeatRecordNumber == form; FusionPro.Composition.SetBodyPageUsage('page', !isForm); FusionPro.Composition.SetBodyPageUsage(['form', file.split(' ')[1]].filter(Boolean).join('-'), isForm); You can name the graphic rule whatever you want to but in an effort to minimize the room for error, name it "background" and paste this into it: pdf.pagenumber = FusionPro.Composition.repeatRecordNumber; return pdf; Apply the "background" rule to every graphic frame in the template – there should be seven in total. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.