How to edit a EMF file

How to edit a EMF file

Postby vilian » Wed Mar 21, 2018 9: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
User avatar
vilian
 
Posts: 982
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil

Re: How to edit a EMF file

Postby cnavarro » 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
User avatar
cnavarro
 
Posts: 6552
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: How to edit a EMF file

Postby vilian » 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
User avatar
vilian
 
Posts: 982
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil

Re: How to edit a EMF file

Postby cnavarro » 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
User avatar
cnavarro
 
Posts: 6552
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: How to edit a EMF file

Postby vilian » 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
User avatar
vilian
 
Posts: 982
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil

Re: How to edit a EMF file

Postby AntoninoP » 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.
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Re: How to edit a EMF file

Postby Marcelo Via Giglio » 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: Select all  Expand view  RUN

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
Marcelo Via Giglio
 
Posts: 1071
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: How to edit a EMF file

Postby cnavarro » Thu Mar 22, 2018 2: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

Image
Image
Last edited by cnavarro on Wed Apr 18, 2018 12:20 am, edited 1 time in total.
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: 6552
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: How to edit a EMF file

Postby nageswaragunupudi » Thu Mar 22, 2018 2:44 pm

Marcelo Via Giglio's solution is Good
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10690
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: How to edit a EMF file

Postby vilian » Thu Mar 22, 2018 2: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

Image
Image
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
vilian
 
Posts: 982
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil

Re: How to edit a EMF file

Postby AntoninoP » Thu Mar 22, 2018 3: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

Image
Image
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Re: How to edit a EMF file

Postby cnavarro » Thu Mar 22, 2018 3: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
User avatar
cnavarro
 
Posts: 6552
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: How to edit a EMF file

Postby nageswaragunupudi » Thu Mar 22, 2018 4:20 pm

Mr Cristobal's approach must be something like this:
Code: Select all  Expand view  RUN
  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: Select all  Expand view  RUN
cBuf  := StrTran( cBuf, AnsiToWide( "City" ), AnsiToWide( "CITY" ) )

But let us see the result:

Image

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
User avatar
nageswaragunupudi
 
Posts: 10690
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: How to edit a EMF file

Postby vilian » Thu Mar 22, 2018 5:03 pm

Thank you,
It's exactly I need ;)
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
vilian
 
Posts: 982
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 79 guests