Case: User wants to manually shrink a variable based on the amount of characters that was inputted. In the case below the customer does not want the Slogan to not exceed past the left most part of the Logo (boat image).
Solution: First you need to calculate how many characters can fit within the given space at 100% fontsize and space. Then use that number to control the output of the variable block.
In our example we have two blocks, {Company Name}, {Slogan} and a paragarph Block called {CompanyParagarph}.
Step 1: Figure out the maximum number of characters that can fit. In our example lets in our example the number is 40. Don't forget that would include spaces.
Step 2. In paragraph block for Company and Slogan first enter the {Company Name} into the {CompanyParagraph} Block as you normally would as well as changing the font colour and sizes.
Step 3. Before putting the {Slogan} into the paragraph block you need to check the number of characters that the user entered into the paragraph and adjust the width accordingly.
You can check the number of characters in a block by using string-length in a paragraph. (see below)
You have 2 options for changing the width of a variable. horizscaling and charspacing or both aside from fontsize.
horizscaling (Float or percentage) Horizontal text scaling. Default: 100%
charspacing (Float or percentage) Character spacing. Percentages are based on fontsize. Default: 0
Example:
!!if (string-length("{Slogan}")>40%%<horizscaling=80% charspacing=-5>!!
In our example we want to manually adjust the sizes based on different inputs by the user.
Our {CompanyParagraph} would look like this:
{Company Name}<fontsize =5.76 fillcolor={cmyk .31 .25 .25 0}><nextline>!!if (string-length("{Slogan}")>40 and string-length("{Slogan}")< 50)%%<horizscaling=80% charspacing=0>!!!!if (string-length("{Slogan}")>49)%%<horizscaling=60%>!!{Slogan}
In the above code if both if statements return false (meaning that the characters are less than 40) then the default horizscaling will be used which is whatever is set in the pdf lib block wizard.
IMPORTANT NOTE: When you use the string-legth function have in mind that it will calculate whatever the user inputted plus whatever else you added using the prefix or postfix. So if for example you have a prefix of <nextline> in the {Slogan} block then the number in our example that we will check for is not 40 but 50 which is 40 plus the 10 characters of <nextline>.
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article