Printing A Canvas In A Report


I was wondering if it is possible to print the contents of a canvas in a Report, using the ReportPicture. I know you can print an image from a SQLite database and also from a image file. But, I have a little bar graph created on a canvas at runtime, and I want to be able to take that little bar graph canvas image and print it in a report.

Does anyone know if this is possible or how I could go about accomplishing it? Any help would be appreciated.


Theres a couple of ways I can suggest.

#1 Move the code for drawing the bar chart into a method, then when you come to print, call that method and pass it the graphics object.

#2 Subclass your canvas, so that you can pass the canvas a graphics object and have it draw it’s contents there.

#3 Use ‘drawInto’ to draw the canvas into your print graphics object.

Thanks Sam for taking the time to help me. The thing is that the Report needs a database record or an actual file name, so I don’t know how that would work.

I actually figured out how to do it. You save the contents of the Canvas as a jpg file, and then load it on to the Report. See Code Below:
This saves the image.

[code]Dim f as FolderItem
DIM File1 AS String = “BarChart” + “.jpg”
f = SpecialFolder.Documents.Child(“MyFolder”).Child(“MySubFolder”).Child(“Images”).Child( File1 )

Dim pic As New Picture(BarChart.Width, BarChart.Height, 32)
BarChart.DrawInto(pic.Graphics, 0, 0)
pic.Save(f, Picture.SaveAsJPEG)[/code]

This loads it into the Report:

//Load Picture dim f as folderitem = SpecialFolder.Documents.Child("MyFolder").Child("MySubFolder").Child("Images").Child(txtGraph.Text) dim p as picture = f.OpenAsPicture rpt.Picture1.Image =p

If you have a boolean field in the database for loading dynalically pictures you can use this code in the canvas paint event:

If mReportDocument <> Nil Then
//this draws the report like xojo samples
g.DrawPicture(mReportDocument.Page(1), 0, 0)
//this is my recordset that was passed to report
if teamrecordset.Field(“image”).BooleanValue then
dim f as folderitem = GetFolderItem(app.AppImageDirectory.AbsolutePath + “image.jpg”)
dim p as picture = f.OpenAsPicture
g.DrawPicture(p, 4,687, 5,98)
end if
End If

the problem was that i see picture on the canvas but they aren’t printed in file or on printer :frowning:

Dim ps As New PrinterSetup

If ps.PageSetupDialog Then

ps.MaxHorizontalResolution = 1200
ps.MaxVerticalResolution = 1200

Dim g As Graphics
g = OpenPrinterDialog(ps)
If g <> Nil Then
’ Print the report
End If
End If

rpt document doesn’t contain images loaded on canvas paint event :frowning: