Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > The JavaScript Library > Formatting Text

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old April 23rd, 2015, 01:04 PM
dennis.wolfers dennis.wolfers is offline
Junior Community Member
 
Join Date: Jun 2012
Posts: 24
Default Preserving Literal Text in a Plain Text Resource

I need to bring in approximately 50,000 plain text resources (one per record), preserving leading space characters, blank lines, etc. so that the formatting remains intact when using a mono-space font (Courier). TaggedTextFromRaw() looks like the logical solution, but it creates entities for the elements of tags so that checking 'Treat returned strings as tagged text' results in the tags being returned as literal text rather than being interpreted as tags.

This is my code:
return TaggedFromRaw(Resource("Raw Bill").content);

Screen capture from preview and source text file attached.

What am I missing?
Attached Images
File Type: png Screen Shot 2015-04-23 at 12.46.49 PM.png (27.8 KB, 20 views)
Attached Files
File Type: txt Sample Page without font command lines.txt (4.4 KB, 18 views)

Last edited by dennis.wolfers; April 23rd, 2015 at 01:09 PM..
Reply With Quote
  #2  
Old April 23rd, 2015, 01:48 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,322
Default Re: Preserving Literal Text in a Plain Text Resource

To handle the markup properly, check the "Treat returned strings as tagged text" box in the Rule Editor dialog. Or, remove the call to TaggedTextFromRaw().

But I don't think either of these is going to give you monospace text in the way you want, where each space "character" is the same width. FusionPro doesn't really do that.

The way to get things to line up in a tabular format, like in your plain text file, in FusionPro is to either use tabs (<t> tags) or a table. In this case, the plain text file probably needs to be parsed to re-generate it as a table.
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
  #3  
Old April 23rd, 2015, 02:14 PM
dennis.wolfers dennis.wolfers is offline
Junior Community Member
 
Join Date: Jun 2012
Posts: 24
Default Re: Preserving Literal Text in a Plain Text Resource

Thank you for your quick response!

I do have the "Treat returned strings as tagged text" box checked. I'll attach a capture of the output with it un-checked.

There is absolutely no way to convert the input files into tables, or any other automated formatting (as you'll see if you look at the text file). Remember that there are tens-of-thousands of these files, each unique!

I have a very convoluted work around, but I'm looking for an elegant solution.

Is there any way to fine-tune the TaggedTextFromRaw functionality so that it doesn't entity-ize the tags themselves?

Dennis
Attached Images
File Type: png Screen Shot 2015-04-23 at 1.40.35 PM.png (31.5 KB, 7 views)
Reply With Quote
  #4  
Old April 23rd, 2015, 02:47 PM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: Preserving Literal Text in a Plain Text Resource

You can somewhat fake this since you're going to be using a mono-spaced font by converting all of the random entities that come over when you import the file into FP to non-breaking spaces ( &nbsp; ). I also converted all of the regular spaces to non-breaking spaces to make them line up. Here's an example ("Treat returned strings as tagged text" in the Rule Editor must be checked):
Code:
var page = CreateResource('./Sample\ Page\ without\ font\ command\ lines.txt')
return page.content.replace(/&[^;]*;|\s/g,'&nbsp;');
Attached PDF of output.
Attached Files
File Type: pdf text-import-example.pdf (9.8 KB, 15 views)
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
  #5  
Old April 23rd, 2015, 03:17 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,322
Default Re: Preserving Literal Text in a Plain Text Resource

Quote:
Originally Posted by dennis.wolfers View Post
I do have the "Treat returned strings as tagged text" box checked. I'll attach a capture of the output with it un-checked.
Okay, well, if the file is a Plain Text File Resource, then the contents are automatically turned into tagged markup. That's really the only difference from a Tagged File Resource. So you're doubly-escaping the contents with entities by calling TaggedFromRaw. At any rate, simply using tagged markup is not going to do what you want.
Quote:
Originally Posted by dennis.wolfers View Post
Is there any way to fine-tune the TaggedTextFromRaw functionality so that it doesn't entity-ize the tags themselves?
No, the "tags themselves" are the result of that "entity-izing" having already been done to the Plain Text File Resource.
Quote:
Originally Posted by dennis.wolfers View Post
There is absolutely no way to convert the input files into tables, or any other automated formatting (as you'll see if you look at the text file).
Well, I don't agree that "There is absolutely no way." There actually is a way to convert those files to table markup, but it's something that has to be coded into a rule. Although Step's solution is a lot simpler than what I was thinking of.
Quote:
Originally Posted by dennis.wolfers View Post
Remember that there are tens-of-thousands of these files, each unique!
Okay, but if you come up with a rule to convert them, then it doesn't really matter how many there are. This is why we have computers, to write programs to automate repetitive tasks.
Quote:
Originally Posted by dennis.wolfers View Post
I have a very convoluted work around, but I'm looking for an elegant solution.
Step's solution is pretty elegant, although I have one quibble with it: Converting "all of the random entities that come over" can sweep up other non-space characters which may have been converted to entities, such as ampersands, quotes, and angle brackets. To guard against that, I would change the last line to this:
Code:
return page.content.replace(/(&#\d+;)|\s/g,'&nbsp;');
But this is pretty clever by Step.
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
  #6  
Old April 23rd, 2015, 06:47 PM
step's Avatar
step step is offline
Senior Contributor
 
Join Date: Jan 2010
Location: Charlotte, NC
Posts: 955
Default Re: Preserving Literal Text in a Plain Text Resource

Quote:
Originally Posted by Dan Korn View Post
Okay, well, if the file is a Plain Text File Resource, then the contents are automatically turned into tagged markup.
Ahh, I did not know that. I couldn't understand why the (what looked to me like) tabs were being converted to entities so I was just trying to get rid of all of them; but that makes much more sense now.

Quote:
Originally Posted by Dan Korn View Post
Step's solution is pretty elegant, although I have one quibble with it: Converting "all of the random entities that come over" can sweep up other non-space characters which may have been converted to entities, such as ampersands, quotes, and angle brackets. To guard against that, I would change the last line to this:
Code:
return page.content.replace(/(&#\d+;)|\s/g,'&nbsp;');
But this is pretty clever by Step.
Thanks, Dan. And after learning how Plain Text File Resources are handled that solution seems much safer.

As I said in my original post, this solution only works because of the monospaced font and wouldn't work with a font like Helvetica. I am curious to see something like this formatted into a table, though. I wracked my brain trying to figure out how to tackle that one but came up short when trying to wrap my head around how to delimit cells and keep the formatting without editing the original text files.
__________________
Ste Pennell
FusionPro VDP Creator 9.3.15
Adobe Acrobat X 10.1.1
Mac OS X 10.12

LinkedIn
Reply With Quote
  #7  
Old April 27th, 2015, 03:29 PM
dennis.wolfers dennis.wolfers is offline
Junior Community Member
 
Join Date: Jun 2012
Posts: 24
Default Re: Preserving Literal Text in a Plain Text Resource

I just read the most recent posts. I really appreciate the thought you both have put into this quirky problem. As it turns out, I came to the same conclusions that you've suggested. Though I really need to learn to use regex, this is the code I came up with that gets the result I need:

var bill = ReplaceSubstring(Resource("Raw Bill").content, "", "*");
bill = ReplaceSubstring(bill, " ", "*");
bill = ReplaceSubstring(bill, " ", "*");

return bill;

P.S. I don't see documentation of entity #32; what is it?
P.P.S. I see that the browser converted my entities into space characters, making my code into nonsense, but I was replacing #19, #32, and regular spaces with #160 (non-breaking space) characters.

Last edited by dennis.wolfers; April 27th, 2015 at 03:41 PM..
Reply With Quote
  #8  
Old April 27th, 2015, 03:52 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,322
Default Re: Preserving Literal Text in a Plain Text Resource

Quote:
Originally Posted by dennis.wolfers View Post
var bill = ReplaceSubstring(Resource("Raw Bill").content, "", " ");
bill = ReplaceSubstring(bill, " ", " ");
bill = ReplaceSubstring(bill, " ", " ");

return bill;
That doesn't seem like it would do anything. I think the vBulletin forum software is being "helpful" here, and converting entities in your post back to spaces. The way I've gotten around this is to change the point size of one of the characters in the entity, such as the # (pound sign). (You can see this in the markup of this post if you Quote it.)
Quote:
Originally Posted by dennis.wolfers View Post
P.S. I don't see documentation of entity #32; what is it?
The entity "&#32;" is a numeric entity, calling out out the character with ASCII code decimal 32, which is the space character. It could also be represented in hexadecimal as "&#x20;"
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
Reply

Tags
entities, literal text, tags

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 06:21 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.