Bob Gatto


I have a report that I used a reportlistener on to get my graphics sized and positioned properly. I need this report to be saved as an HTML. The code I tried was this:

 vfile = FULLPATH("")+SYS(2015)+".html"
 oSystem = CREATEOBJECT("gdisystems")
 DO reportoutput.app WITH 5,oSystem
 oSystem.targetfilename = vfile
 osystem.quietmode = .T.
 REPORT FORM eventscal OBJECT oSystem

********************************************************************************

DEFINE CLASS gdiSystems as _reportlistener OF _reportlistener.vcx

ogfx = NULL
lo_pen = NULL
oColor = NULL
obrush = NULL

barheight = 200 && Change this to the desired height for all bar s drawn

FUNCTION BeforeReport
 DODEFAULT()
 this.ogfx = CREATEOBJECT("gpgraphics")
ENDFUNC


FUNCTION BeforeBand(nBandObjCode,nFRXRecNo)
 this.sharedGdiplusGraphics = this.GDIPlusGraphics
 this.ogfx.sethandle(this.sharedGdiplusGraphics)
 DODEFAULT(nBandObjCode,nFRXRecNo)
ENDFUNC

PROCEDURE Render
LPARAMETERS nFRXRecNo,nLeft,nTop,nWidth,nHeight,;
 nObjectContinuationType,cContentsToBeRendered,GDIPlusImage
 
 LOCAL oflds,vboxnum
 
 ***********************************************
 ** If the width is more than 1 day, subtract 8
 ** times the number of days from the width.
 ***********************************************
 
 oflds = this.GetRec(nFRXRecNo)
 IF AT("DAYBOX",oflds.user) != 0
  this.lo_pen = NULL
  this.oColor = NULL
  this.obrush = NULL
  
  vboxnum = INT(VAL(RIGHT(ALLTRIM(oflds.user),1)))
  vday = "daylist.day"+ALLTRIM(STR(vboxnum))
  GO TOP IN eventloc
  DO WHILE !EOF("eventloc")
   IF eventloc.dowstart = vboxnum AND &vday = DAY(eventloc.startdate) AND eventloc.daylistid = daylist.idnum
    this.ocolor = CREATEOBJECT("gpcolor")

    DO CASE
    CASE eventloc.eventnum = 1
     this.ocolor.foxrgb = RGB(0,0,255)
    CASE eventloc.eventnum = 2
     this.ocolor.foxrgb = RGB(0,255,0)
    CASE eventloc.eventnum = 3
     this.ocolor.foxrgb = RGB(255,0,0)
    CASE eventloc.eventnum = 4
     this.ocolor.foxrgb = RGB(255,0,255)
    CASE eventloc.eventnum = 5
     this.ocolor.foxrgb = RGB(255,255,0)
    CASE eventloc.eventnum = 6
     this.ocolor.foxrgb = RGB(0,255,255)
    ENDCASE
    this.lo_pen = CREATEOBJECT("gppen")
    this.lo_pen.create(this.ocolor,2,2)
    this.obrush = CREATEOBJECT("gpsolidbrush",this.ocolor)
    vtop = (nTop+250) + (eventloc.eventnum-1)*this.barheight
    this.ogfx.drawrectangle(this.lo_pen,nLeft,vtop,(nWidth*eventloc.eventlngth)-(8*(eventloc.eventlngth-1)),this.barheight)
    this.ogfx.fillrectangle(this.obrush,nLeft,vtop,(nWidth*eventloc.eventlngth)-(8*(eventloc.eventlngth-1)),this.barheight)
   ENDIF
   SKIP IN eventloc
  ENDDO
 ENDIF
ENDPROC

PROCEDURE GetRec
LPARAMETERS FrxRec

LOCAL vsession,oret

vsession = SET("datasession")
SET DATASESSION TO this.frxdatasession
GO FrxRec IN FRX
SCATTER NAME oret memo
SET DATASESSION TO vsession

RETURN oret

ENDPROC

ENDDEFINE


this code gives me an HTNL file without the graphics I need. If I replace:

 vfile = FULLPATH("")+SYS(2015)+".html"
 oSystem = CREATEOBJECT("gdisystems")
 DO reportoutput.app WITH 5,oSystem
 oSystem.targetfilename = vfile
 osystem.quietmode = .T.
 REPORT FORM eventscal OBJECT oSystem


With:

 oSystem = CREATEOBJECT("gdisystems")
 REPORT FORM eventscal OBJECT oSystem PREVIEW


I get my HTML file but not with my graphics that I need.

Can someone help me with this

Thanks.





Re: FRX to HTML

CChalom

Hi Bob,

I've never tried that, but anyway I'm afraid this will not be totally possible, because you seem to be direct drawing in your form using GDI+, bypassing in some times the report engine. This way, the original report listener will not be able to convert the GDI+ part to HTML.

IMHO, there remaIN 2 good options

1 - Output your report to PDF instead of HTML

2 - Use only native VFP Report controls, like rectangles, and OLE objects for the images. That's totally possible, even for your specific case, but for that case you may need to create your images using a UDF() that will use GDI+ and save severam images to the disk before printing. This way, VFP Report Assisted will locate your images, and properly create your HTML.

Hope this helps

Cesar






Re: FRX to HTML

Bob Gatto

Hi Cesar,

I see what you are saying now. I would like to go with your second suggestion. I need to create different colored rectangles that could be directly under one another, and these will change for every record. I've been studying the GpImage class to figure out how to create the image and then store the image as a file. I took the code that I showed you using the DrawRectangle method and what I did was after I finished the drawing I used the command:

this.oimage = CREATEOBJECT("gpimage",this.sharedgdiplusgraphics)

this.oimage.savetofile(ADDBS(FULLPATH(""))+"imagetest1.jpg","image/jpeg")

When I ran the program and looked for the image file, It was never created. Isn't this the way to create an image file via GDI+

Thanks for the help,

Bob






Re: FRX to HTML

CChalom

Bob,

In your sample you did that:

this.oimage = CREATEOBJECT("gpimage",this.sharedgdiplusgraphics)

this.oimage.savetofile(ADDBS(FULLPATH(""))+"imagetest1.jpg","image/jpeg")

No !

The property "This.SharedGdiPlusGraphics" is the graphic handle that the report listener uses to draw the report.

In the previous sample, I used this handle when I wanted to bypass the natural behavior of the report and draw a new rectangle around those textboxes.

But if you want to create a new image, you shoud do something like that:

Code Snippet

loBmp = CREATEOBJECT("GpBitmap", 100,70) && 100 = width 100 - 70 = height in pixels

loGfx = CREATEOBJECT("GpGraphics")

loGfx.FromImage(loBmp)

loGfx.DrawRectangle(loBrush, 10,10,20,20)

loBmp.SavetoFile("imgTest.jpg", "image/jpeg")

Don`t forget to create the brush object, loBrush, ok

etc etc

Have in mind that GpBitmap is a subclass of GpImage, so it inherits all GpImage functions, and brings the additional possibility to create new bitmaps, as I did above

In my blog, look for the old posts from last year, there you`ll find some cool samples that show how to draw using _gdiplus.vcx. Personally, I prefer to use GdiplusX library, since it brings much more possibilities, but for your case this classes will do the job.

Hope this helps

Cesar