Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing many images per record 1

Status
Not open for further replies.

keepsafe

Programmer
Sep 22, 2009
14
US
I have two table one hold all the detail information and the other table hold the name of the image file that is store in c:\program\images\ directory. In the images.dbf has a primary key,image name, imgdesc field. The images name such as myphoto.jpg, myphoto.gif etc.

My question is how can I print the main information in one detail band and then print all images on the second detail band and once all the images are printed it goes to the next record.

Thanks
John
 
If you have a new VFP version such as VFP9 then you could simply add a new detail bad, relate your tables and place 'parent' in first detail band, 'child' in second detail band.

If you are using an old VFP version then you could simply:
1) select all data into a cursor,
2) create a grouping on 'parent' Primary key
3) Place all parent fields in group band
4) Place 'child' fields (images in your case) in detail band

However, VFP reporting isn't very flexible in dealing with images. You probably want to do something like:

ParentInfo
Image1 Image2 Image3 .... Image8
Image9 ....

Where the images are all same size under your control (or in their actual size).
If so then I would suggest creating an HTML file and printing through it. Here is an image browser sample with HTML (this one I had done to show HTML in form but it would give the idea) - code contains HTML tags. I am not sure if it would be rendered or displayed as code:
Code:
Public oForm
oForm = Createobject('form1')
oForm.Show()

Define Class form1 As Form
  Top = 0
  Left = 0
  Height = 470
  Width = 740
  DoCreate = .T.
  Caption = "HTML sample"
  Name = "Form1"
  HTMLFile='' && Custom prpoperty to hold temp .htm name

  * This is IE control - you'd use webbrowser4 from gallery instead
  * just because it already has some checks, extra pem. ie: wouldn't need readystate part
  * for the sake of keeping code short here I directly use olecontrol itself
  Add Object htmlviewer As OleControl With ;
    Top = 12, ;
    Left = 12, ;
    Height = 396, ;
    Width = 708, ;
    Visible = .T., ;
    Name = "HTMLViewer", ;
    OleClass = 'Shell.Explorer'

  Add Object text1 As TextBox With ;
    Height = 25, ;
    Left = 12, ;
    Top = 432, ;
    Width = 60, ;
    Name = "Text1"

  Add Object text2 As TextBox With ;
    Height = 23, ;
    Left = 84, ;
    Top = 432, ;
    Width = 204, ;
    Name = "Text2"

  Add Object text3 As TextBox With ;
    Height = 23, ;
    Left = 300, ;
    Top = 432, ;
    Width = 125, ;
    Name = "Text3"

  Add Object text4 As TextBox With ;
    Height = 23, ;
    Left = 432, ;
    Top = 432, ;
    Width = 125, ;
    Name = "Text4"

  Procedure Init
    Local lnImages, lnPerrow, lnCurrent
    lnImages = Adir(arrImages,_samples+'data\graphics\*.gif')
    *You'd use a table let's simulate it
    Create Cursor myImages (ImagePath m,FirstName c(12), LastName c(12))
    For ix=1 To lnImages
      Insert Into myImages Values ;
        (_samples+'data\graphics\'+arrImages[ix,1],'FirstName'+Trans(ix),'LastName'+Trans(ix))
    Endfor
    *Now we have a test table - create HTML
    lnPerRow = 5 && How many would we show on a line
    lnCurrent = 0 && Do not use recno() thinking it might be ordered on an index
    This.HTMLFile = Sys(2015)+'.htm'

    Set Textmerge On
    Set Textmerge To (This.HTMLFile) Noshow
    * Initialize lcHTML
		\<HTML><BODY><TABLE>
    Select myImages
    Scan
      lnCurrent = lnCurrent+1
      If (lnCurrent-1)%lnPerRow=0
        If lnCurrent>1
		\</TR>
        Endif
		\<TR>
      Endif
		\<TD><A href="<<trans(recno())>>">
		\    <img border="0" height="100" width="60" src="<<trim(chrtran(ImagePath,'\','/'))>>"></A></TD>
		
    Endscan
		\</TR>
		\</TABLE></BODY></HTML>
    Set Textmerge To
    Set Textmerge Off
    *!*	    Modify Command (this.HTMLFile) && If you ever wonder created HTML
    With Thisform.htmlviewer
      .Navigate2('file://'+Sys(5)+Curdir()+This.HTMLFile)
      Do While .ReadyState # 4 && Wait for ready state
      Enddo
    Endwith
  Endproc


  Procedure htmlviewer.BeforeNavigate2
    *** ActiveX Control Event ***
    Lparameters pdisp, url, flags, targetframename, postdata, headers, Cancel
    Cancel = .T.  && do not navigate to anywhere
    With Thisform && with webbrowser4 also this.oHost is the form itself or container
      .text1.Value = Justfname(url)
      Go Val(Justfname(url)) In 'myImages'
      .text2.Value = myImages.ImagePath
      .text3.Value = myImages.FirstName
      .text4.Value = myImages.LastName
    Endwith
  Endproc

  Procedure Destroy
    Erase (This.HTMLFile)
  Endproc
Enddefine




Cetin Basoz
MS Foxpro MVP, MCP
 
For a solution that is not dependent on VFP9's additional Report Form properties, the way the I have always done what you suggest is to use a 'backwards' table relation for printing like this.

What you want is to put "the main information in one Group band and then print all images on the Detail band". Then when the next Main Info Group detail is detected, the Report Form will loop back to begin a new Group.

To do that you need to do something like the following:

Code:
USE MyMainInfo IN 0
SELECT MyMainInfo
SET ORDER TO Key

USE MyImages IN 0
SELECT MyImages
SET ORDER TO Key
SET RELATION TO Key INTO MyMainInfo
< Do Whatever >

SELECT MyImages
REPORT FORM MyReport NOCONSOLE TO PRINT

Or alternatively you can do a query to create a cursor from which to do your report

Code:
SELECT MyImages.*,;
   MyMainInfo.*;
   FROM MyImages, MyMainInfo;
   WHERE MyMainInfo.Key = MyImages.Key;
   < and any other criteria >
   INTO CURSOR MyReportData

SELECT MyReportData
REPORT FORM MyReport NOCONSOLE TO PRINT

Good Luck,
JRB-Bldr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top