RTF documents as templates

classic Classic list List threaded Threaded
23 messages Options
12
Reply | Threaded
Open this post in threaded view
|

RTF documents as templates

JosepM
Hi everyone,

I need to use some word like docs like templates. Searching and replacing some words or sentences to generate a new document. Any idea or sample to how get the content of a word file and modify it?

Thanks,
Josep M
Reply | Threaded
Open this post in threaded view
|

Re: RTF documents as templates

Andrew Kluthe
Did you ever find a solution for this josep? I am in the early phases of planning to do something exactly like this.
Reply | Threaded
Open this post in threaded view
|

Re: RTF documents as templates

JosepM
Nop. My solution was store the entire document and search and replace before to build the document, and then out as PDF using Quartam PDF Library and Quartam Reports, but also you can print from a card.

But now, some customers need customize reports and documents and again I need do something. Actually I customize the docs and send to the customer her document to use from Quartam Reports.

I was thinking to create the template from a card for example, and convert for Quartam PDF or maybe using the new PrintToPDF when this will be available in the next release 5.0

If you have any idea about I'm very glad to help and collaborate.

Salut,
Josep
Reply | Threaded
Open this post in threaded view
|

Re: RTF documents as templates

Andrew Kluthe
What about using wordLib 1.3 to import template documents into a field, pull the records you need from the database, do the calculations necessary and fill the data into the placeholders saved into the word doc?

This was the approach I was thinking of trying out. I would very much love to collaborate on a solution along these lines. Something customizable, a word Document template based reporting system.

My timeframe on needing this solution is starting to look like the end of the week. How would you best like to work on this? via email?
Reply | Threaded
Open this post in threaded view
|

Re: RTF documents as templates

JosepM
Hi Andrew,

You guess that is posible use the doc template with some graphic or images inside the word and fill all the data respecting the images format? I don't know wordLib 1.3
Also I think that maybe we can found other non-propietary format to use..., but let's try

As you wish, email is fine for me. 

Salut,
Josep

El 31/05/2010, a las 22:27, Andrew Kluthe [via Runtime Revolution] escribió:

What about using wordLib 1.3 to import template documents into a field, pull the records you need from the database, do the calculations necessary and fill the data into the placeholders saved into the word doc?

This was the approach I was thinking of trying out. I would very much love to collaborate on a solution along these lines. Something customizable, a word Document template based reporting system.

My timeframe on needing this solution is starting to look like the end of the week. How would you best like to work on this? via email?


View message @ http://runtime-revolution.278305.n4.nabble.com/RTF-documents-as-templates-tp322967p2237801.html
To unsubscribe from Re: RTF documents as templates, click here.


Reply | Threaded
Open this post in threaded view
|

Re: RTF documents as templates

Andrew Kluthe
WordLib supports many document features, from text fonts, sizes, and styles to highlights, hyperlinks, and bullet lists and even images, tables, and footnotes. Supported file formats are MS Word 2007 (.docx, .docm, .xml), MS Word 2003(.xml), OpenOffice (.odt), and MS Word 97-2003 (.doc, limited support).


:) images and then some. It utilizes an HTML rendering of the formatting, so searching and replacing the data should be fine if we construct the templates correctly. 

I am going to tinker with this tomorrow afternoon and see what I can come up with.

On Mon, May 31, 2010 at 6:11 PM, JosepM [via Runtime Revolution] <[hidden email]> wrote:
Hi Andrew,

You guess that is posible use the doc template with some graphic or images inside the word and fill all the data respecting the images format? I don't know wordLib 1.3
Also I think that maybe we can found other non-propietary format to use..., but let's try

As you wish, email is fine for me. 

Salut,
Josep

El 31/05/2010, a las 22:27, Andrew Kluthe [via Runtime Revolution] escribió:

What about using wordLib 1.3 to import template documents into a field, pull the records you need from the database, do the calculations necessary and fill the data into the placeholders saved into the word doc?

This was the approach I was thinking of trying out. I would very much love to collaborate on a solution along these lines. Something customizable, a word Document template based reporting system.

My timeframe on needing this solution is starting to look like the end of the week. How would you best like to work on this? via email?


View message @ http://runtime-revolution.278305.n4.nabble.com/RTF-documents-as-templates-tp322967p2237801.html
To unsubscribe from Re: RTF documents as templates, click here.





View message @ http://runtime-revolution.278305.n4.nabble.com/RTF-documents-as-templates-tp322967p2237897.html
To unsubscribe from Re: RTF documents as templates, click here.


Reply | Threaded
Open this post in threaded view
|

Re: RTF documents as templates

JosepM
Let's try :)
Reply | Threaded
Open this post in threaded view
|

Re: RTF documents as templates

Robert Brenstein
In reply to this post by JosepM
On 31.05.10 at 10:50 -0700 JosepM apparently wrote:
>Nop. My solution was store the entire document and search and replace before
>to build the document, and then out as PDF using Quartam PDF Library and
>Quartam Reports, but also you can print from a card.
>

If you need to just print, producing PDF files might be a way to go.
Using RTF works as well. I used RTF documents as templates to produce
Word docs. Basically, I created a full blown, properly formatted Word
doc as template, then replaced variable elements with tokens, in my
case things like [title], [description]. Rev stack read RTF directly
into a variable and replaced the tokens, then saved new file. One
needs to use RTF commands for marking new paragraphs, styles, and
code non-English characters. I even used to produce Word table with
varying numbers of rows by marking a repeating code for row in RTF
and replicating it as many times as needed. Some sleuthing required,
though, to decipher blocks in RTF.

Robert
_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: RTF documents as templates

Peter Haworth-2
In reply to this post by JosepM
I've been trying to figure out how to use an RTF document as a  
template using pretty much this same methodology.  The problem I ran  
into is that sometimes, for reasons I don;t understand,  the token  
names I put into the document get interspersed with RTF commands, so  
something that looks like "[myToken]" when displayed in Word ends up  
looking like "[my<RTF commands>token]".  That stops my search for  
tokens dead in it's tracks.

Another method I've tried is to set up a Word document with merge  
fields in it and have my application write out a comma delimited file  
that is the source for the merge data.  That works well if you have a  
predictable number of lines you want to print, not so good for  
variable number of lines.

Right now, I've settled on writing out html code from templates that  
are defined within my Application.  I have some conventions to deal  
with "repeating lines".  For example, if I was printing an invoice,  
I'd define one html line in the format of an invoice line and its  
definition would include a code that tells me I need to repeat that  
line for each invoice line I'm printing.  That works quite well  
although so far I haven't figured out how to deal with printing a  
heading at the top of each page.

I guess I should break down and spend some money on a real report  
writer, especially since all my data is stored in an sqlite database  
but it's a fun challenge to figure this stuff out sometimes!

Pete Haworth

On Jun 1, 2010, at 10:00 AM, [hidden email]  
wrote:

> Message: 16
> Date: Tue, 1 Jun 2010 14:38:10 +0200
> From: Robert Brenstein <[hidden email]>
> Subject: Re: RTF documents as templates
> To: How to use Revolution <[hidden email]>
> Message-ID: <p06240805c82aae20435c@[192.168.1.94]>
> Content-Type: text/plain; charset="us-ascii" ; format="flowed"
>
> On 31.05.10 at 10:50 -0700 JosepM apparently wrote:
>> Nop. My solution was store the entire document and search and  
>> replace before
>> to build the document, and then out as PDF using Quartam PDF  
>> Library and
>> Quartam Reports, but also you can print from a card.
>>
>
> If you need to just print, producing PDF files might be a way to go.
> Using RTF works as well. I used RTF documents as templates to produce
> Word docs. Basically, I created a full blown, properly formatted Word
> doc as template, then replaced variable elements with tokens, in my
> case things like [title], [description]. Rev stack read RTF directly
> into a variable and replaced the tokens, then saved new file. One
> needs to use RTF commands for marking new paragraphs, styles, and
> code non-English characters. I even used to produce Word table with
> varying numbers of rows by marking a repeating code for row in RTF
> and replicating it as many times as needed. Some sleuthing required,
> though, to decipher blocks in RTF.
>
> Robert

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: RTF documents as templates

Andrew Kluthe
Tinkering with the demo version of wordLib. It seems wordLib enters it into the field as HTMLText. This should make searching and replacing very easy, no?  But i've noticed the formatting doesn't stay exact on the import. The alignments are off on even the sample documents. Is there anyway to prevent this I wonder?
Reply | Threaded
Open this post in threaded view
|

Re: RTF documents as templates

Jan Schenkel
In reply to this post by Robert Brenstein
--- On Tue, 6/1/10, Robert Brenstein <[hidden email]> wrote:

> On 31.05.10 at 10:50 -0700 JosepM
> apparently wrote:
> > Nop. My solution was store the entire document and
> search and replace before
> > to build the document, and then out as PDF using
> Quartam PDF Library and
> > Quartam Reports, but also you can print from a card.
> >
>
> If you need to just print, producing PDF files might be a
> way to go. Using RTF works as well. I used RTF documents as
> templates to produce Word docs. Basically, I created a full
> blown, properly formatted Word doc as template, then
> replaced variable elements with tokens, in my case things
> like [title], [description]. Rev stack read RTF directly
> into a variable and replaced the tokens, then saved new
> file. One needs to use RTF commands for marking new
> paragraphs, styles, and code non-English characters. I even
> used to produce Word table with varying numbers of rows by
> marking a repeating code for row in RTF and replicating it
> as many times as needed. Some sleuthing required, though, to
> decipher blocks in RTF.
>
> Robert
>

Sorry for the late reply - I'm just resurfacing after several months of deadlines at the day-job.

Anyway, a while ago I wrote two articles for the revUp newsletter, titled 'The Word of Merge':
- part 1: <http://runrev.com/newsletter/november/issue61/newsletter3.php>
- part 2: <http://www.runrev.com/newsletter/december/issue62/newsletter3.php>

In short, create a template file in Word, with double square brackets around variable names or revTalk expressions; save the template file in RTF format; read the file into a variable and use the 'merge' function to dynamically replace the content of each bit of text inside the double square brackets with its value.

HTH,

Jan Schenkel
=====
Quartam Reports & PDF Library for Revolution
<http://www.quartam.com>





     

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: RTF documents as templates

JosepM
Hi Jan,

Nice... :) and work with images... seems that some of my problems are solved...  

But why (maybe a stupid question but...) the local var Description is replaced into the RTF automatically with the merge function? In my sample I used [[Description]] into the RTF

Any why of insert a page break on the fly?


on mouseUp
   local descripcion, theTemplateFile, theMergedFile, theRTFtext
   --
   ask "What message do you have for the world?" with "Hello, world!"
   if it is empty then exit mouseUp
   
   put mactoiso(it) into Description
   
   answer file "Where is 'theMessage.rtf' template file?"
   if it is empty then exit mouseUp
   
   put it into theTemplateFile
   
   ask file "Save your message as:"
   
   if it is empty then exit mouseUp
   put it into theMergedFile
   --
   put URL("binfile:" & theTemplateFile) into theRTFtext
   set the fileType to "MSWDRTF "
   put merge(theRTFtext) into URL ("binfile:" & theMergedFile)
end mouseUp


Salut,
Josep M.
Reply | Threaded
Open this post in threaded view
|

Re: RTF documents as templates

JosepM
Hi again,

Some questions for the experts...

How can open or print a RTF file without Word? TextEdit loss the images and format of tables...
I search in the MS website for Mac but I can't get any kind of viewer...

How can open and print from Applescript without view the flashing RTF file?

Also with Pages loss the images and format of tables... :(

Salut,
Josep
Reply | Threaded
Open this post in threaded view
|

Re: RTF documents as templates

Stephen Barncard-4
"Pure" RTF text files created by Rev are a styled text format that is
readable by Word and most text editors, but does not include images.

  On the mac, RTF documents (note the suffix .rtfd) created by TextEdit are
actually BUNDLES, not files, and contain the RTF file and the graphic files.
 RTF files saved by Word I believe do not save images either,  that is for
the .doc format.

On 8 June 2010 15:20, JosepM <[hidden email]> wrote:

>
> Hi again,
>
> Some questions for the experts...
>
> How can open or print a RTF file without Word? TextEdit loss the images and
> format of tables...
>
> How can open and print from Applescript without view the flashing RTF file?
>
>
>
> Salut,
> Josep
> --
> View this message in context:
> http://runtime-revolution.278305.n4.nabble.com/RTF-documents-as-templates-tp322967p2248114.html
> Sent from the Revolution - User mailing list archive at Nabble.com.
> _______________________________________________
> use-revolution mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>



--
-------------------------
Stephen Barncard
San Francisco
_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: RTF documents as templates

Jan Schenkel
I recall a post from November 2008 where Franz Böhmisch posted a way to embed images into RTF files, followed by Ken Ray's abstraction of said method. Searching the use-revolution archives, I found these two links for you:
<http://mail.runrev.com/pipermail/use-revolution/2008-November/117180.html>
<http://mail.runrev.com/pipermail/use-revolution/2008-November/117212.html>

Other than that, I'm afraid there's no built-in way to print those RTF documents and you'd have to rely on the presence of MS Word on the end-user machine. While it's nearly ubiquitous on Windows, MacOSX is another matter so you may have to decypher the .rtfd bundle format that TextEdit uses, to cram your images into it.

Jan Schenkel
=====
Quartam Reports & PDF Library for Revolution
<http://www.quartam.com>

=====
"As we grow older, we grow both wiser and more foolish at the same time."  (La Rochefoucauld)


--- On Wed, 6/9/10, stephen barncard <[hidden email]> wrote:

>
> "Pure" RTF text files created by Rev
> are a styled text format that is
> readable by Word and most text editors, but does not
> include images.
>
>   On the mac, RTF documents (note the suffix .rtfd)
> created by TextEdit are
> actually BUNDLES, not files, and contain the RTF file and
> the graphic files.
>  RTF files saved by Word I believe do not save images
> either,  that is for
> the .doc format.
>
> On 8 June 2010 15:20, JosepM <[hidden email]>
> wrote:
>
> >
> > Hi again,
> >
> > Some questions for the experts...
> >
> > How can open or print a RTF file without Word?
> TextEdit loss the images and
> > format of tables...
> >
> > How can open and print from Applescript without view
> the flashing RTF file?
> >
> >
> >
> > Salut,
> > Josep
> >


   

_______________________________________________
use-revolution mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-revolution
Reply | Threaded
Open this post in threaded view
|

Re: RTF documents as templates

JosepM
Hi List,

Here my tests...
In MacOSX the RTF is RTFD that is a bundle as explained Jan.
 
Showing the contents of bundle you can found one TXT.rtf file that contain the text and the n files for the asociated images used in the creation of the file from TextEdit.

Steps.

1 Open TextEdit and create your template using images and positioning using tables if you need. If not put your text formated as you need.
2 Where you need replace some part, use the [[myreplacedtext1]] using [[ to open and ]] to close. As Jan show in her link above.
3 Save as RTFD
4 Open from Rev with the following code. The question is to open the TXT.rtf file and modify it.
5 Open directly from TextEdit and Print using Rev or Applescript.

Pro
No MS Word need.
Easy way to use templates for the user.

Con
Poor alignment format, only tables, so to build some document A4 or Letter for example you need to check the lines, footers, etc...

on mouseUp
   
   put mactoiso("áàïô_test") into text1
   put "This a long text to see how is showed inside the rtf file" into description
   put "Bottom text" into footer
   put the system date into tDate
     
   answer file "Where is the template file?"
   if it is empty then exit mouseUp
   
   put it into theTemplateFile
   
   -- Duplicate the file with a new name

   put "TXT.rtf" into tFichero
   put theTemplateFile & "/" & tFichero into tTheFile
   put URL("binfile:" & tTheFile) into theRTFtext
   
   set the fileType to "MSWDRTF "
   
   put merge(theRTFtext) into URL ("binfile:" & tTheFile)
end mouseUp


Salut,
Josep
Reply | Threaded
Open this post in threaded view
|

Re: RTF documents as templates

JosepM
Update code using the RTFText of field XXXX
The revCopyFile don't copy the bundle, only create the file so searching for the list I found a piece of code to copy using the shell.

If someone want the stack and the RTF file to test with, email me and I send you.

Salut,
Josep

on mouseUp
   
   put mactoiso(the RTFText of fld f_texto1) into texto1
   put mactoiso(the RTFText of fld f_texto2) into texto2
   
   put mactoiso(the RTFText of fld f_texto_f1c1) into texto_f1c1
   put mactoiso(the RTFText of fld f_texto_f1c2) into texto_f1c2
   put mactoiso(the RTFText of fld f_texto_f1c3) into texto_f1c3
   
   put mactoiso(the RTFText of fld f_texto_f2c1) into texto_f2c1
   put mactoiso(the RTFText of fld f_texto_f2c2) into texto_f2c2
   put mactoiso(the RTFText of fld f_texto_f2c3) into texto_f2c3
   
   answer file "Where is the template file?"
   if it is empty then exit mouseUp
   put it into theTemplateFile
   
   ask file "Save your message as:" with "TheResultingRTF.rtfd"
   if it is empty then exit mouseUp
   put it into theMergedFile
   
   set the fileType to "MSWDRTF "
   --
   put ("cp -R -p ""e&theTemplateFile"e&"e&theMergedFile"e) into tCommand
   get shell(tCommand)
   --
   
   put TXT & ".rtf" into tFichero
   put theTemplateFile & "/" & tFichero into tTheFile
   put URL("binfile:" & tTheFile) into theRTFtext
   
   set the fileType to "MSWDRTF "
   
   put merge(theRTFtext) into URL ("binfile:" & theMergedFile & "/" & tFichero)
end mouseUp
Reply | Threaded
Open this post in threaded view
|

Re: RTF documents as templates

Andrew Kluthe
I have been trying to implement the methods described in revUp's articles on the subject. The trouble that I am having is that some of the [[Placeholders]] don't get changed at all. Some are replaced and some are left as placeholders.

I am getting so aggravated with not having a templatable reporting method for printing out Lease Contracts. The user needs to be able to customize the lease contract to fit their needs and my rev program fills out the variable data and spits it out as a pdf or word doc.

I've looked into other reporting engines and the closest thing I found to what I need is Docmosis and it only interfaces with java. I wish it interfaced through a command line or that I had Java knowledge so I could build one.
Reply | Threaded
Open this post in threaded view
|

Re: RTF documents as templates

Alex Tweedly
Andrew,

I see this is at the end of a long-ish conversation (and I've not read
much of it :-)

So forgive me if this wild guess is way off track ....

The most likely cause of "some placeholders not being replaced" is that
the relevant variable is mistyped or otherwise doesn't exist.  The
effect of the double square brackets in a 'merge' string is to evaluate
what's between the brackets as though it was Livecode script - and using
a variable which doesn't exist simply evaluates to itself. So for instance

> put 1 into aaa
> put "[[aaa]] and [[bbb]]" into c
> put merge(c)
will result in the output

> 1 and bbb

i.e. it looks like the first placeholder was replaced and the second wasn't.

I hope that might be some help.

-- Alex.


On 29/11/2010 19:00, Andrew Kluthe wrote:

> I have been trying to implement the methods described in revUp's articles on
> the subject. The trouble that I am having is that some of the
> [[Placeholders]] don't get changed at all. Some are replaced and some are
> left as placeholders.
>
> I am getting so aggravated with not having a templatable reporting method
> for printing out Lease Contracts. The user needs to be able to customize the
> lease contract to fit their needs and my rev program fills out the variable
> data and spits it out as a pdf or word doc.
>
> I've looked into other reporting engines and the closest thing I found to
> what I need is Docmosis and it only interfaces with java. I wish it
> interfaced through a command line or that I had Java knowledge so I could
> build one.


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: RTF documents as templates

Jan Schenkel
In reply to this post by Andrew Kluthe
--- On Mon, 11/29/10, Andrew Kluthe <[hidden email]> wrote:

>
> I have been trying to implement the methods described in
> revUp's articles on
> the subject. The trouble that I am having is that some of
> the
> [[Placeholders]] don't get changed at all. Some are
> replaced and some are
> left as placeholders.
>
> I am getting so aggravated with not having a templatable
> reporting method
> for printing out Lease Contracts. The user needs to be able
> to customize the
> lease contract to fit their needs and my rev program fills
> out the variable
> data and spits it out as a pdf or word doc.
>
> I've looked into other reporting engines and the closest
> thing I found to
> what I need is Docmosis and it only interfaces with java. I
> wish it
> interfaced through a command line or that I had Java
> knowledge so I could
> build one.
>

Hi Andrew,

I had a quick look at Docmosis - looks pretty cool, but a tad complicated to implement. Not only the syntax for the template writer, but also the architecture with converters seemed a bit involved (and I have been around the block in Java so to speak).

Back to the [[Placeholder]] issue, I can think of a few reasons this would fail:
- typos are obviously a problem (and I've made more than my fair share of those so no need to feel frustrated)
- older versions of Word may mangle parts of the RTF unless you 'Save as' to a new RTF file
- your variable names still have to abide the rules, and be available in the context where you call the 'merge' function

Can you give us a concrete example where it fails?
- the RTF template file
- the script itself

I'm sure we can help you figure out a solution.

Jan Schenkel.
=====
Quartam Reports & PDF Library for LiveCode
www.quartam.com

=====
"As we grow older, we grow both wiser and more foolish at the same time."  (La Rochefoucauld)



     

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
12