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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing Images 1

Status
Not open for further replies.

Shanachie

Programmer
Jun 18, 2000
92
US
I've got an application that needs to print images. (This is for an embroidery operation using images of clients' logos.) I've got the image's file name in a memo field. The problem I'm stumped by is how to get the Picture/ActiveX Bound control to print it. The control's properties dialog looks for either a single, static, named image file (like for the embroiderer's logo) or a general field containing the image.

How do I get the file name into the control? This has got to be one of those so-simple-I-can't-figure-it-out problems.

Shanachie
 
Shanachie

One way is to create a report and in the file option of the Picture/ActiveX report object, place:-

SYS(5)+SYS(2003)+[\temp.gif]

PRINTOUT.filename contains the image filename without path.

SET SAFE OFF
lcFileName = ALLT(PRINTOUT.filename)
COPY FILE &lcFileName TO SYS(5)+SYS(2003)+[\temp.gif]
REPORT form reports\print_gif.frx NEXT 1 TO PRINTER NOCONSOLE
SET SAFE ON

The image filename can also be placed in a character rather than a memo field.

The advantage of what you are doing is that you are not embedding the image in a general field and thus you are avoiding the space and performance issues that such a method brings.

Chris :)
 
Thanks, that's helpful.

A couple of questions: since the clients send logos in a number of different formats (bmp, gif, etc.), how does the control know which format to expect? If it's the file extension, I'd have to have a different control and tempfile for each possible format and set flags or something to control which one gets used through print-when.

It's do-able but seems clumsy. Is there no way to dynamically reset the file name for each record? This has got to be a problem others have faced.

My other solution is to set up a temporary general field in the extracted dbf and to append the image there. Again, seems clumsy though it will work.

(BTW How do you put the image in the general field? Would it look something like this:

SCAN
APPEND GENERAL genrlfield FROM (filenamefield)
ENDSCAN

I thought that APPEND added records.)

TIA,
Shanachie
 
Shanachie

One way would be to open the report as a table and replace the filename with the filename reference from the table

lcFilename = ["]+SYS(5)+SYS(2003)+ALLT(PRINTOUT.filename)+["]
USE report1.frx IN 0 ALIAS TEMPREPO
SELE TEMPREPO
LOCATE FOR TEMPREPo_Objtype = 17 && ActiveX/Picture object
REPL TEMPREPO.picture WITH lcFilename
USE

Another longer way would be to recover the filename's extension from the field in the table using the JUSTEXT() function in Foxtools.fll

Then copy the first report as many times as there are file types and replace the file reference with "temp.jpg", "temp.bmp" etc

DO CASE
CASE UPPE(JUSTEXT(PRINTOUT.filename)) = [BMP]
[tab]&& Copy file and run appropriate report
CASE UPPE(JUSTEXT(PRINTOUT.filename)) = [GIF]
[tab]&& Copy file and run appropriate report
CASE UPPE(JUSTEXT(PRINTOUT.filename)) = [JPG]
[tab]&& Copy file and run appropriate report
ENDC

APPEND GENERAL can be confusing - a new record is not added, instead the contents of the general field are REPLaced with the new OLE object. Its also worth remembering that unless you use the LINKED argument, you will be embedding an instance of the graphics editor in every general field, hence the previous comments about space.

Chris :)
 
Shanachie

lcFilename = ["]+SYS(5)+SYS(2003)+ALLT(PRINTOUT.filename)+["]

should be

lcFilename = ["]+SYS(5)+SYS(2003)+[\]+ALLT(PRINTOUT.filename)+["]

Also your use of APPEND GENERAL is fine.

Chris :)
 
Thanks for all your help! It's working now. I chose the "APPEND GENERAL" approach and it seems to work fine. One small note for anyone trying this: the filename field has to be a character field. I had been storing the filenames in memo fields and APPEND GENERAL didn't like that. I set up a temporary 100-character variable and stored the filename in that and it works fine.

Thanks again! You've once more earned my "ever-asking" gratitude!

Shanachie
 

Shanachie and Chris

I am hoping your logo printing discussion can help me.

I'm not a programmer but wrote extensive Foxpro code for my office years ago which we still use in Visual Foxpro 5. Our programs use fread() to print 'fill-in-the blank" type forms built with PCL code in a 3rd party software. The form goes to the printer without ejecting, then the data follows to fill in the blanks and put x's in the squares.

This code was given to me by the 3rd party company to do what I've just described.

???chr(27)+"&f0y" *
???chr(27)+"&f0X" *
H=fopen(ZXNFILE) *
do while not feof(h) *
??? fread(H,254) *
enddo *
=fclose(h) *
???chr(27)+"&f1X"
???chr(27)+"&f10X"
???chr(27)+"&f4X"
h=fopen('\foxpro2\exp\datafile.txt')
do while not feof(h)
??? fread(h,254)
enddo
=fclose(h)
???chr(12)
???chr(27)+"&f5X"
??? chr(27)+"&l0H"


Anyway, it is VERY painstaking to build a form, and I currently need to update things.
Can I use a scanner instead then send the image to the printer (i.e. without ejecting)? If your code for the logo applies, and since my image file name is not variable, can I use the following code?

COPY FILE myform.gif TO SYS(5)+SYS(2003)+[\temp.gif]
REPORT form reports\print_gif.frx TO PRIN


and place it instead of the lines I've showed you that are followed by *

(I've never used the REPORT form command, so I dont really understand it.)

Leo
 
The process to build a form IS tedious, whether you're using that 3rd party software or VFP's Report Designer.

I don't think that scanning in the image and then printing it will give you what you want.

If I were you, I'd either learn Report Designer (it's pretty easy, as long as your needs are simple and straightforward; complex stuff can get hinckey (sp?)) or else hire someone to do it for you. A competent VFP programmer should be able to crank out a one-page report in a day or two. (It'd be faster than that if he/she didn't have to learn the context.)

Shanachie
 
I'm also having problem printing images without embedding them in my DBFs. I'm using VFP 5.0a and I can't figure out where everybody on this thread get the PRINTOUT.filename. May I ask what version of VFP are you using?
 
medic

PRINTOUT.filename refers to the field filename in table printout.

This would be created by COPY FROM maintable FIELDS filename TO path\PRINTOUT, and would be the temporary table to provide the records for printing.

If you are going to use a table to store filenames, then you either need a single field such as filename and store the path\filename in that field, or two fields, path and filename and store the path and filename separately, and if applicable, concatenate them at runtime.

Another way to print images is to use a WinAPI call such as ShellExecute(). You could dispense with the report and make the call from a FOR ... ENDFOR loop.

Depending on the application associated with the file type, you may need to force a small delay between each call, and the application may or may appear on screen.

VFP 6.0 in answer to your second question.

Chris :)

 
medic

Depending on the application associated with the file type, you may need to force a small delay between each call, and the application may or may not appear on screen.

Chris :)
 
Thanks Chris.
There's one more thing I need to ask. I don't know if I'm just missing something but my report designer in VFP5 doesn't support images other than BMP format. I think it is handy if I can readily use image formats such as GIF, JPEG and TIFF in my report forms. Is there a way to solve this limitation? If there is, can you give me an example code or steps?

Medic
 
medic

One way would be to convert the images to .bmp format.

It sounds like a lot of hassle, but try
The viewer has a batch conversion facility so you can programatically convert entire folders if you wish.

If the images do not form part of a report and you simply want to print them standalone, ShellExecute() could be another option.

Chris :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top