PressTalk Carriage Return or Feed Line not working

Posted by: phinix_mike

PressTalk Carriage Return or Feed Line not working - 10/27/21 03:16 AM

I'm trying to make CR and LF work in PressTalk - how can I do that?
I tried to switch those to different character, but there must be a proper way to do that, right?

Please help!
Posted by: Jean-Cédric

Re: PressTalk Carriage Return or Feed Line not working - 10/27/21 09:10 AM

Use the PressTalk procedure CRLF()
Posted by: phinix_mike

Re: PressTalk Carriage Return or Feed Line not working - 10/28/21 03:51 AM

Originally Posted By: Jean-Cédric
Use the PressTalk procedure CRLF()


Yes, but how can I define where to use CRLF?
I have a txt file which has CR or LF in it, but how can I make it work, so PlanetPress would see them and process?
Posted by: Jean-Cédric

Re: PressTalk Carriage Return or Feed Line not working - 10/28/21 08:43 AM

You need to more specific about how the text is and what is your intended result.

If your texthas CR and LF in it, then simply read it line by line and display those lines as they are in your text object.

Can you provide an example of what the data looks like and the expected result (as an example too)?
Posted by: phinix_mike

Re: PressTalk Carriage Return or Feed Line not working - 10/28/21 08:55 AM

Originally Posted By: Jean-Cédric
You need to more specific about how the text is and what is your intended result.

If your text has CR and LF in it, then simply read it line by line and display those lines as they are in your text object.

Can you provide an example of what the data looks like and the expected result (as an example too)?


So txt file has message field which I want to display on A4 pdf.

For example :

"Card ID", "From","Message"
"012839","Jessica","All the best{LF}{LF}I hope you'll have great day out{LF}{LF}from{LF}John"

I would like to display it as:

FROM: Jessica

All the best

I hope you'll have great day out

from
John



So each LF or CR would be treated as supposed to be.
Of course LF or CR are not normally seen, so I cannot just do "if you find LF or CR, do CRLF()"

Something like this would be best, but I know its not working:

Code:
define(&str, string, '')
&str := @(13,1,500)
search(&str, Chr(10) or Chr(13))
show(&str)
crlf()
endsearch()
show(&str)



I hope that makes sense.
Posted by: Jean-Cédric

Re: PressTalk Carriage Return or Feed Line not working - 10/28/21 09:42 AM

Yes that makes a lot more sense.
Knowing now that you have a CSV file as input and that a field contains text with LF in it, helps in designing a solution.

So here's my text example:
"CU98408920","Mrs","Alice","Aubin","Hello, {LF}{LF}Please enjoy blablabla {LF}{LF}blablabla"
"CU98408920","Mrs","Michele","Stuart","Congratulations, {LF}{LF}You are currently our 1 000th customer! {LF}{LF}You will receive your prize..."
"CU98408920","Mr","Pierre","Minion","Hello, {LF}{LF}Tired of winter? {LF}{LF}Select one of our resorts..."


In PPress, first created a Text object and set it up as close to the final result you want (positionning, font color, etc...)
Add all the data where it is supposed to be in it but don't try to do the CRLF yet for the message part. Simply add it as a whhole line.

Next, go to the Tool menu and select Convert to PlanetPress Talk, while having your Text object selected.
Once done, double-click on what is now a PressTalk object. what you see now is the actual PressTalk generated by the Text Object based on your inital settings.

Mine looks like this:
Code:
MoveTo(0,0)
MoveTo(&Width,&Height)
Define(&LocalVariable,string,@(2,1,3))
Set(&LocalVariable,@(2,1,3))
Define(&LocalVariable1,string,@(3,1,34))
Set(&LocalVariable1,@(3,1,34))
Define(&LocalVariable2,string,@(4,1,23))
Set(&LocalVariable2,@(4,1,23))
Define(&LocalVariable3,string,@(5,1,100))
Set(&LocalVariable3,@(5,1,100))
Margin(0.0000,0.0000)


BeginParagraph(0.0000,&Width,0.0000,'left',0.1667,False)
   SetStyle(&Style1)
   Show('Dear '+&LocalVariable+' '+&LocalVariable1+' '+&LocalVariable2)
EndParagraph()
CRLF(0.1667)

search(&LocalVariable3,'{LF}')
   BeginParagraph(0.0000,&Width,0.0000,'left',0.1667,False)
      SetStyle(&Style1)
      Show(&LocalVariable3)
   EndParagraph()
endsearch()

BeginParagraph(0.0000,&Width,0.0000,'left',0.1667,False)
   setStyle(&Style1)
   Show(&LocalVariable3)
EndParagraph()


Notice the use of the Search()...EdnSearch() procedure, which acts as a loop. Basically it goes through all the words in your variable and look for a specific pattern {LF}. It will loop as many time as it finds it. When it does, it execute its inner content while removing the found pattern from the content of the variable, leaving in the variable what was there that is not the pattern (I know, not quite intuitive but it works...see link to online help for more technical explanation).

That should be a good start for you.

Best,
Posted by: phinix_mike

Re: PressTalk Carriage Return or Feed Line not working - 10/28/21 10:02 AM

Originally Posted By: Jean-Cédric
Yes that makes a lot more sense.
Knowing now that you have a CSV file as input and that a field contains text with LF in it, helps in designing a solution.

So here's my text example:
"CU98408920","Mrs","Alice","Aubin","Hello, {LF}{LF}Please enjoy blablabla {LF}{LF}blablabla"
"CU98408920","Mrs","Michele","Stuart","Congratulations, {LF}{LF}You are currently our 1 000th customer! {LF}{LF}You will receive your prize..."
"CU98408920","Mr","Pierre","Minion","Hello, {LF}{LF}Tired of winter? {LF}{LF}Select one of our resorts..."


In PPress, first created a Text object and set it up as close to the final result you want (positionning, font color, etc...)
Add all the data where it is supposed to be in it but don't try to do the CRLF yet for the message part. Simply add it as a whhole line.

Next, go to the Tool menu and select Convert to PlanetPress Talk, while having your Text object selected.
Once done, double-click on what is now a PressTalk object. what you see now is the actual PressTalk generated by the Text Object based on your inital settings.

Mine looks like this:
Code:
MoveTo(0,0)
MoveTo(&Width,&Height)
Define(&LocalVariable,string,@(2,1,3))
Set(&LocalVariable,@(2,1,3))
Define(&LocalVariable1,string,@(3,1,34))
Set(&LocalVariable1,@(3,1,34))
Define(&LocalVariable2,string,@(4,1,23))
Set(&LocalVariable2,@(4,1,23))
Define(&LocalVariable3,string,@(5,1,100))
Set(&LocalVariable3,@(5,1,100))
Margin(0.0000,0.0000)


BeginParagraph(0.0000,&Width,0.0000,'left',0.1667,False)
   SetStyle(&Style1)
   Show('Dear '+&LocalVariable+' '+&LocalVariable1+' '+&LocalVariable2)
EndParagraph()
CRLF(0.1667)

search(&LocalVariable3,'{LF}')
   BeginParagraph(0.0000,&Width,0.0000,'left',0.1667,False)
      SetStyle(&Style1)
      Show(&LocalVariable3)
   EndParagraph()
endsearch()

BeginParagraph(0.0000,&Width,0.0000,'left',0.1667,False)
   setStyle(&Style1)
   Show(&LocalVariable3)
EndParagraph()


Notice the use of the Search()...EdnSearch() procedure, which acts as a loop. Basically it goes through all the words in your variable and look for a specific pattern {LF}. It will loop as many time as it finds it. When it does, it execute its inner content while removing the found pattern from the content of the variable, leaving in the variable what was there that is not the pattern (I know, not quite intuitive but it works...see link to online help for more technical explanation).

That should be a good start for you.

Best,


Thanks, I'll try that, but am I correct - does this search for actual string {LF}?

Thing is, in csv file you don't see those, LF or CR are invisible, so it looks like this:

"CU98408920","Mrs","Alice","Aubin","Hello,Please enjoy BlablablaDododoBlablablaFromJohn"

then once processed, message field should look like

Hello,
Please enjoy Blablabla
Dododo
Blablabla

From
John


So instead of : search(&LocalVariable3,'{LF}')
can it be: search(&LocalVariable3,Chr(10) or Chr(13)) ?
Posted by: Jean-Cédric

Re: PressTalk Carriage Return or Feed Line not working - 10/28/21 10:15 AM

Then that migth become more tricky.

When you look at your data in a text editor, you don't see you "message" all on the same line, right?

I mean you don't see it as I display my text example?
Posted by: Jean-Cédric

Re: PressTalk Carriage Return or Feed Line not working - 10/28/21 10:22 AM


To help you properly we would need to see the form and reproduce the issue. I suggest you open a technical support ticket through our website.
Posted by: phinix_mike

Re: PressTalk Carriage Return or Feed Line not working - 10/29/21 07:36 AM

Originally Posted By: Jean-Cédric
Then that migth become more tricky.

When you look at your data in a text editor, you don't see you "message" all on the same line, right?

I mean you don't see it as I display my text example?


Yes, I don't see special characters, only in specific editing software, like notepad++.


In general, does it mean that PP design doesn't automatically accept Chr10 or Chr13?

I found walkaround way to use them, I need to swap them with some regular string/characters, then replace them in PressTalk, but I was hoping that there is way to "natively" use CRs.


Posted by: Jean-Cédric

Re: PressTalk Carriage Return or Feed Line not working - 10/29/21 08:33 AM

Problem is that in a CSV file, CRLF duo are used to separate the lines. The problem here is to known when it is a end of line CRLF and a end of line in your "message" field.

Your best bet would be to replace your CRLF inside your "message" field by any other string like {CRLF}, in Workflow using Regex and then use my solution in PPress.
Posted by: Jean-Cédric

Re: PressTalk Carriage Return or Feed Line not working - 10/29/21 08:58 AM

Here is how I did it:
  1. steps up to here
  2. Advanced Search and Replace using REGEX (explanation below)
  3. Advanced Search and Replace using REGEX (explanation below)
  4. Advanced Search and Replace using REGEX (explanation below)
  5. steps continue


So, I used REGEX:

In step 2., I used:
-String to search = "(\r\012)
-Replace with = "{goodCRLF}
which replace the end of line CRLF by {goodCRLF}

In step 3., I used:
-String to search = (\r\012)
-Replace with = {CRLF}
which replace the end of line CRLF, from the "message" field by {CRLF}

In step 4., I used:
-String to search = \{goodCRLF\}
-Replace with = \n
which replace the end of line {goodCRLF} from earlier back into a end of line

and then that works with my previous PressTalk smile