RTF files

RTF files

Postby Jeff Barnes » Thu Nov 24, 2016 3:11 pm

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 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: RTF files

Postby Jeff Barnes » Thu Nov 24, 2016 4:02 pm

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 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: RTF files

Postby Antonio Linares » Thu Nov 24, 2016 4:34 pm

Jeff,

I just tried this:

word2pdf.prg
Code: Select all  Expand view
#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/library/bb238158(v=office.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
Antonio Linares
Site Admin
 
Posts: 42093
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: RTF files

Postby karinha » Thu Nov 24, 2016 5:10 pm

Master,

Image

Saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7814
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: RTF files

Postby Jeff Barnes » Thu Nov 24, 2016 6:12 pm

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 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: RTF files

Postby Otto » Thu Nov 24, 2016 8:08 pm

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


viewtopic.php?f=3&t=13495&p=69231&hilit=docx#p69231
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: RTF files

Postby Jeff Barnes » Thu Nov 24, 2016 8:32 pm

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 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: RTF files

Postby Otto » Thu Nov 24, 2016 8:49 pm

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

Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: RTF files

Postby Jeff Barnes » Thu Nov 24, 2016 8:56 pm

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 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: RTF files

Postby Otto » Thu Nov 24, 2016 9:56 pm

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
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: RTF files

Postby Jeff Barnes » Thu Nov 24, 2016 11:55 pm

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

Thanks.
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: RTF files

Postby driessen » Mon Nov 28, 2016 10:16 am

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. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: RTF files

Postby cnavarro » Wed Nov 30, 2016 1:28 pm

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
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 114 guests