I've seen all over the web some examples showing how to print individual images directly to the printer.

I don't know why, but in some situations this approach simply denies to work. maybe, or probably a developer bug ?

One of the easiest and more secure ways to do this task is to use the native report designer, and let vfp deal with the whole process of printing.

Below there is an example that receives an image file name as a parameter, creates a report on the fly, adding an ole image object that will print the selected image.

This example is totally based in mskb 895602 "how to print pictures and how to display pictures that are stored in a blob field in visual foxpro 9.0" the adapted code should work on any version of vfp. thanks to trevor hancock and msdn ! the code is easy to understand. you can easily change the position of the image changing the hpos and vpos values. If you like the example and need more information, see "understanding and extending report structure" from the vfp help.

Save the code below as printimage.prg

To print an image, just call printimage(GETPICT())


lparameters tcimage
*tcimage = getpict()
* vfp code that shows how to print image files.
* code adapted from microsoft knowledge base article
* 895602.
* most of the codes and comments below come from
* trevor hancock, from ms

local lnarea
lnarea =

create cursor reporttemp (imagefile c(150))
insert into reporttemp values (tcimage)
*-- this calls a function that makes a report programmatically.
*-- this is included here just to make sure that this sample can be run
*-- as-is, without asking the developer to manually create a report.

*-- make sure that the cursor is selected,
*-- and then run the report to preview using
*-- the instance of our report listener.
select reporttemp
report form ___imagereport preview
delete file "___imagereport.fr*"
select (lnarea)


*-- this function programmatically creates a report
*-- with an ole bound control and other fields. this is included
*-- only for demonstration purposes so this article code can stand-alone.
*-- typically, you would create your own report manually by using
*-- the report designer.
function makereport
create report ___imagereport from reporttemp
*-- open the report file (frx) as a table.
use ___imagereport.frx in 0 alias thereport exclusive
select thereport
*-- remove from the frx the auto generated fields and labels
delete from thereport where objtype = 5 and objcode = 0 && remove the labels
delete from thereport where objtype = 8 and objcode = 0 && remove the fields

*-- add a picture/ole bound control to the report by inserting a
*-- record with appropriate values. using an object that is based on the empty
*-- class here and the gather name class later to insert the record makes it easier to
*-- see which values line up to which fields (when compared to a large
*-- sql-insert command).
local lonewrecobj as empty
lonewrecobj = newobject( 'empty' )
addproperty( lonewrecobj, 'platform', 'windows' )
addproperty( lonewrecobj, 'uniqueid', sys(2015) )
addproperty( lonewrecobj, 'objtype', 17 )&& "picture/ole bound control"
addproperty( lonewrecobj, 'name', 'reporttemp.imagefile' ) && the object ref to the image object.
addproperty( lonewrecobj, 'hpos', 100)
addproperty( lonewrecobj, 'vpos', 600)
addproperty( lonewrecobj, 'height', 100000)
addproperty( lonewrecobj, 'width', 100000)
addproperty( lonewrecobj, 'double', .t. ) && picture is centered in the "picture/ole bound control"
addproperty( lonewrecobj, 'supalways', .t. )
*-- for the picture/ole bound control, the contents of the offset field specify whether
*-- filename (0), general field name (1), or expression (2) is the source.
addproperty( lonewrecobj, 'offset', 2 )
*-- add the picture/ole bound control record to the report.
append blank in thereport
gather name lonewrecobj memo
*-- clean up and then close the report table.
pack memo
use in select( 'thereport' )


  1. Cesar,

    A big fan of your blog on VFP and images. Your "Print Image" post - a perfect self contained feature that many VFP developers can use 'out-of-the-box'.

    Thank you!


  2. Hi Malcolm,

    Thanks for the kind words, and the references you've been passing at Profox.

    That's the best fuel to continue blogging !



  3. Versión en Español de este artículo en / Spanish version at http://www.portalfox.com/article.php?sid=2212

  4. Muito bom Cezar, parabens.

    very good