FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to edit a EMF file
Posts: 1067
Joined: Wed Nov 09, 2005 02:17 AM
How to edit a EMF file
Posted: Wed Mar 21, 2018 09:20 PM
Hi Guys,

I have a program where I print something like this Page: 1/NNN, after generated all pages I wanted edit them and change NNN for the total of pages(Ex: 40), so the EMF files will have Page: 1/40, Page: 2/40, etc

Do you know if It´s possible ?
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: How to edit a EMF file
Posted: Wed Mar 21, 2018 10:01 PM

Look Len( ::oDevice:aMeta )

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
Posts: 1067
Joined: Wed Nov 09, 2005 02:17 AM
Re: How to edit a EMF file
Posted: Wed Mar 21, 2018 10:56 PM

Thanks,

But I already have the total number of pages, what I need is to change this pages to insert this total in them.

Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: How to edit a EMF file
Posted: Thu Mar 22, 2018 10:49 AM

Do you want to change NNN by the total number of pages after generating the EMF?
I think not possible, you have to regenerate the EMF

Well, you can try to read the emf and with a strtran change the contents of the file and re-record it, but I have not tried it

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
Posts: 1067
Joined: Wed Nov 09, 2005 02:17 AM
Re: How to edit a EMF file
Posted: Thu Mar 22, 2018 11:30 AM

I have already tried it. But, after to change the file, its turns invalid.
IF I try open the modified file, it's showing the message bellow:

Can't read file reader!
Unknow file format, empty/damaged file

Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
Posts: 375
Joined: Tue Feb 10, 2015 09:48 AM
Re: How to edit a EMF file
Posted: Thu Mar 22, 2018 11:49 AM
The EMF file are binary so I think the strTran can not work... Besides the text inside them is saved as WideChar...
The correct solution is difficult but not impossible: https://msdn.microsoft.com/en-us/library/dd162509(v=vs.85).aspx..-.
you need to add a lot of support for harbour or write your procedure in C...

I think the simpler solution is do 2 prints, the first to see how much pages it will create, and the second with the correct page total number.
Posts: 1088
Joined: Fri Oct 07, 2005 03:33 PM
Re: How to edit a EMF file
Posted: Thu Mar 22, 2018 12:03 PM
Hello,

many years ago, I made changes to the report class, one of them was the page total number

Code (fw): Select all Collapse
Function NumeraPag(oPrn,nRowStep,nColStep)
Local x
Local nPaginas := Len( oPrn:aMeta )
Local aFicheros := oPrn:aMeta
Local nCol := 70*nColStep      //colocalo donde prefieras
Local nLin := 64*nRowStep    //   ""

if nPaginas <= 1 // Solamente una pagina
  Return Nil
endif

oPrn:aMeta := {}

FOR x := 1 TO nPaginas
   //PAGE
   oPrn:startpage()
   oPrn:ImportWMF( aFicheros[ x ], .F. )
   oPrn:Say( nLin,nCol, +Alltrim( Str( x ) ) +"/" + Alltrim( Str( nPaginas ) ) ,,,,,1 )
   oPrn:endPage()
   //ENDPAGE
NEXT

Return NIl


You can call this function from the Report END() method NumeraPag(::oDevice,1,1) or define in external event ON END, etc
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: How to edit a EMF file
Posted: Thu Mar 22, 2018 02:43 PM
AntoninoP wrote:The EMF file are binary so I think the strTran can not work... Besides the text inside them is saved as WideChar...


No, with StrTran not, that is obvious
But it is possible change text


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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: How to edit a EMF file
Posted: Thu Mar 22, 2018 02:44 PM

Marcelo Via Giglio's solution is Good

Regards



G. N. Rao.

Hyderabad, India
Posts: 1067
Joined: Wed Nov 09, 2005 02:17 AM
Re: How to edit a EMF file
Posted: Thu Mar 22, 2018 02:57 PM
How did you do this change ?

cnavarro wrote:
AntoninoP wrote:The EMF file are binary so I think the strTran can not work... Besides the text inside them is saved as WideChar...


No, with StrTran not, that is obvious
But it is possible change text


Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
Posts: 375
Joined: Tue Feb 10, 2015 09:48 AM
Re: How to edit a EMF file
Posted: Thu Mar 22, 2018 03:12 PM
Did you use a binary editor?

cnavarro wrote:
AntoninoP wrote:The EMF file are binary so I think the strTran can not work... Besides the text inside them is saved as WideChar...


No, with StrTran not, that is obvious
But it is possible change text


Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: How to edit a EMF file
Posted: Thu Mar 22, 2018 03:15 PM

No, through programming

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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: How to edit a EMF file
Posted: Thu Mar 22, 2018 04:20 PM
Mr Cristobal's approach must be something like this:
Code (fw): Select all Collapse
   cBuf  := MEMOREAD( "test.emf"
   cBuf  := StrTran( cBuf, AnsiToWide( "/99" ), AnsiToWide( "/40" ) )
   MEMOWRIT( "test.emf", cBuf )

This could work in some simple cases that Mr Vilian requires, but not in all cases.

Explanation why "not in all cases".
emf file stores a lot more information than text and font info. In some cases alignment, kerning etc of characters may get disturbed.

Example:
This substitution looks quite reasonable:
Code (fw): Select all Collapse
cBuf  := StrTran( cBuf, AnsiToWide( "City" ), AnsiToWide( "CITY" ) )

But let us see the result:



We can use this approach if we keep in mind its limitations.
In any case, this should work well for page numbers as required by Mr Vilian
Regards



G. N. Rao.

Hyderabad, India
Posts: 1067
Joined: Wed Nov 09, 2005 02:17 AM
Re: How to edit a EMF file
Posted: Thu Mar 22, 2018 05:03 PM

Thank you,
It's exactly I need ;)

Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil

Continue the discussion