FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour RTF files
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
RTF files
Posted: Thu Nov 24, 2016 03: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)
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Re: RTF files
Posted: Thu Nov 24, 2016 04: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)
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: RTF files
Posted: Thu Nov 24, 2016 04:34 PM
Jeff,

I just tried this:

word2pdf.prg
Code (fw): Select all Collapse
#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
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: RTF files
Posted: Thu Nov 24, 2016 05:10 PM
Master,



Saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Re: RTF files
Posted: Thu Nov 24, 2016 06: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)
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: RTF files
Posted: Thu Nov 24, 2016 08: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=3t=13495p=69231hilit=docx#p69231

&&&

Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Re: RTF files
Posted: Thu Nov 24, 2016 08: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)
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: RTF files
Posted: Thu Nov 24, 2016 08:49 PM

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

Otto

Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Re: RTF files
Posted: Thu Nov 24, 2016 08: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)
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: RTF files
Posted: Thu Nov 24, 2016 09:56 PM

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

Best regards,
Otto

Posts: 933
Joined: Sun Oct 09, 2005 01:05 PM
Re: RTF files
Posted: 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)
Posts: 1467
Joined: Mon Oct 10, 2005 11:26 AM
Re: RTF files
Posted: 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. 25.12 - Harbour 3.2.0 (May 2025) - xHarbour Builder (January 2020) - Bcc773

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: RTF files
Posted: Wed Nov 30, 2016 01: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

Continue the discussion