RTF files

Post Reply
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

RTF files

Post by Jeff Barnes »

I am wondering if the following is possible via FWH ????

I would like to open an RTF file, search for some text (ie: <DAT:NAME>) and replace the found text with a filed from a DBF file (ie: MyDBF->Name ).
After the text is changed I would like to save the RTF as a PDF file.
I would like to be able to do all of this with nothing displayed on the screen.

Is this possible?
Thanks,
Jeff Barnes

(FWH 12.01, xHarbour 1.2.1, Bcc582)
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Re: RTF files

Post by Jeff Barnes »

Never mind.

My original files were created in Word then saved as RTF files. They lose some formatting so I can't go with RTF.

Is there any way to do the same type of thing with Word files, without having Word installed?
Thanks,
Jeff Barnes

(FWH 12.01, xHarbour 1.2.1, Bcc582)
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: RTF files

Post by Antonio Linares »

Jeff,

I just tried this:

word2pdf.prg

Code: Select all

#include "FiveWin.ch"

function Main()

   local oWord := CreateObject( "Word.Application" )
   local oDoc  := oWord:Documents:Open( "c:\document.docx" )

   oDoc:Activate()
   oDoc:SaveAs2( "c:\document.pdf", 17 )
   oDoc:Close()

return nil
https://msdn.microsoft.com/en-us/librar ... e.12).aspx

but it does not work as expected. Also I guess that the user must have Word installed

Also I realized that a docx document is a renamed zip file. So maybe you could replace text inside it.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
karinha
Posts: 4882
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: RTF files

Post by karinha »

Master,

Image

Saludos.
João Santos - São Paulo - Brasil
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Re: RTF files

Post by Jeff Barnes »

Hi Antonio,

I am able to do exactly what I need if I have MS-Word installed.
The problem I run into is that Word does not really like being run from a program that is running as a service.
It works "most" of the time but every now and then Word get hung up and stalls my program.
I was hoping to do this somehow without needing Word :(
Thanks,
Jeff Barnes

(FWH 12.01, xHarbour 1.2.1, Bcc582)
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: RTF files

Post by Otto »

Jeff,
a docx is a zip file. Open the file and you find document.xml.
You can change document.xml and then pack all files and rename it back to docx.
Best regards,
Otto


http://forums.fivetechsupport.com/viewt ... ocx#p69231
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Re: RTF files

Post by Jeff Barnes »

Thanks Otto ... one step closer.
This will work for replacing text but I also need to be able to replace one of my "tokens" (ie: <DAT:SIG>) with an image.
Would you know how I could do this?
Thanks,
Jeff Barnes

(FWH 12.01, xHarbour 1.2.1, Bcc582)
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: RTF files

Post by Otto »

Jeff,
please look into the folder:
word\media
Best regards,

Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Re: RTF files

Post by Jeff Barnes »

Hi Otto,

I saw that the images are in that folder. I guess what I need to know is how (or where) would I tell word to use the image so that it goes in place of my text <DAT:SIG> ?
Thanks,
Jeff Barnes

(FWH 12.01, xHarbour 1.2.1, Bcc582)
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: RTF files

Post by Otto »

Jeff,
use a dummy jpg in your template.
Then you can overwrite the jpg in media folder.


Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
User avatar
Jeff Barnes
Posts: 912
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada
Contact:

Re: RTF files

Post by Jeff Barnes »

Otto you are a genius :)
That is an excellent idea.

Thanks.
Thanks,
Jeff Barnes

(FWH 12.01, xHarbour 1.2.1, Bcc582)
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: RTF files

Post by driessen »

The OLE-error, could it be that a wrong Office version is installed?
Not all versions have OLE included (student versions, private versions, etc.).
You need to have a professional Office version to be able to use OLE.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
cnavarro
Posts: 5792
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: RTF files

Post by cnavarro »

In new version Fwh 16.11 implemented:

* RICHEDIT5

- New METHOD SaveToPDF( cName, cFile, lView )
cName := <Optional - Name of report - Not used yet>
cFile := File of PDF file
lView := View PDF file, if .T.

You do not need to have WORD installed
TESTRTF5.PRG in folder samples

Menu
- File - Open
- File - To Pdf
C. Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
Si alguien te dice que algo no se puede hacer, recuerda que esta hablando de sus limitaciones, no de las tuyas.
Post Reply