Page 1 of 1

How to edit a EMF file

Posted: Wed Mar 21, 2018 9:20 pm
by vilian
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 ?

Re: How to edit a EMF file

Posted: Wed Mar 21, 2018 10:01 pm
by cnavarro
Look Len( ::oDevice:aMeta )

Re: How to edit a EMF file

Posted: Wed Mar 21, 2018 10:56 pm
by vilian
Thanks,

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

Re: How to edit a EMF file

Posted: Thu Mar 22, 2018 10:49 am
by cnavarro
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

Re: How to edit a EMF file

Posted: Thu Mar 22, 2018 11:30 am
by vilian
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

Re: How to edit a EMF file

Posted: Thu Mar 22, 2018 11:49 am
by AntoninoP
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.

Re: How to edit a EMF file

Posted: Thu Mar 22, 2018 12:03 pm
by Marcelo Via Giglio
Hello,

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

Code: Select all | Expand


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

Re: How to edit a EMF file

Posted: Thu Mar 22, 2018 2:43 pm
by cnavarro
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

Re: How to edit a EMF file

Posted: Thu Mar 22, 2018 2:44 pm
by nageswaragunupudi
Marcelo Via Giglio's solution is Good

Re: How to edit a EMF file

Posted: Thu Mar 22, 2018 2:57 pm
by vilian
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

Re: How to edit a EMF file

Posted: Thu Mar 22, 2018 3:12 pm
by AntoninoP
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

Re: How to edit a EMF file

Posted: Thu Mar 22, 2018 3:15 pm
by cnavarro
No, through programming

Re: How to edit a EMF file

Posted: Thu Mar 22, 2018 4:20 pm
by nageswaragunupudi
Mr Cristobal's approach must be something like this:

Code: Select all | Expand

  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

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

Re: How to edit a EMF file

Posted: Thu Mar 22, 2018 5:03 pm
by vilian
Thank you,
It's exactly I need ;)