[Gambas-user] Print probleem with pictures/text

Ron Onstenk ronstk at ...239...
Thu Jul 20 07:41:39 CEST 2006


I use A4 paper
On that sheet should be 2 sections.
Every section consists of a picture and some labels with a
textbox as overlay on the picture
The first step was using a Me.Grab() on the the form and was printed OK.
Then I add the second section.
I had of course to change the height of the form.
Using the .Grab() shows me garbage on the bottom.
The bottom of the form was below the taskbar.

Then I did use a stand alone Image 
try to put from both picturebox a .grab() in the Image.
The second replace the first one.
Using Picture, Panel, Scrollview and Drawingarea did not solve the replace.


from the print project 
' Name: ModulePrinting
' Author: Timothy Marshal-Nichols


PUBLIC SUB PrintImage(img AS Image, OPTIONAL FitToPage AS Boolean)
  DIM imageToPrint AS Image
  DIM imageWidth AS Integer
  DIM imageHeight AS Integer
  DIM scaleIsotropic AS Float
  ' Display printer dialog
  IF Printer.Setup() THEN RETURN
  INC Application.Busy
  ' Get image size for the printer resolution
  imageWidth = (img.Width * Printer.Resolution) / Desktop.Resolution
  imageHeight = (img.Height * Printer.Resolution) / Desktop.Resolution
  ' Adjust image size if it does not fit on the printer page
  ' Also if the fit to page option is set fill the page with the image
  IF FitToPage OR imageWidth > Printer.Width OR imageHeight > Printer.Height THEN
    ' Scale Isotropic, keep aspect ratio of the image
    scaleIsotropic = Min(Printer.Width / imageWidth, Printer.Height / imageHeight)
    imageWidth *= scaleIsotropic
    imageHeight *= scaleIsotropic
  END IF
  ' Scale image
  imageToPrint = img.Stretch(imageWidth, imageHeight, TRUE)
  ' Draw image centred on printer page
  Draw.Begin(Printer)
  Draw.Image(imageToPrint, (Printer.Width - imageWidth) / 2, (Printer.Height - imageHeight) / 2)
  Draw.End
  DEC Application.Busy
END


This was usable to print my first trial with 1/2 A4 sheet

PUBLIC SUB PrintImage(img AS Image,img2 AS Image, OPTIONAL FitToPage AS Boolean)
  DIM imageToPrint AS Image
  DIM imageToPrint2 AS Image

......
'STATIC SUB Image ( Image AS Image, X AS Integer, Y AS Integer 
     [ , SrcX AS Integer, SrcY AS Integer, SrcWidth AS Integer, SrcHeight AS Integer ] ) 


  Draw.Begin(Printer)
'                image                    x                   y   srcx srcy  srcw        srch
  Draw.Image(imageToPrint,  (Printer.Width - imageWidth) / 2, 0,   0,   0,   imageWidth, 528)
  Draw.Image(imageToPrint2, (Printer.Width - imageWidth) / 2, 528, 0,   0,   imageWidth, 528)
  Draw.End


Same result. not working or not correct.

Basic I need to print two sections as described above. 
I do have a Form with the size of 1/2 A4.
The place of the labels and textbox are adjustable to fit the image below.

Next trial:
Printing text using Draw.Text

STATIC SUB Text ( Text AS String, X AS Integer, Y AS Integer 
	[ , Width AS Integer, Height AS Integer, Alignment AS Integer ] ) 

If you specified the optional parameters, then the text is constrained to 
the given rectangle, and aligned according to the Alignment parameter. 

The original text in the section is around 6 lines and on the left half of the section.
It is not in a boxed way but 1 long line.

I did try also to use the draw.clip

  .DrawClip 
  This virtual class is used for defining the clipping area of a drawing. 
  The drawing methods never draw outside of the clipping area. 

  STATIC SUB .DrawClip ( X AS Integer, Y AS Integer, Width AS Integer, Height AS Integer )

draw.clip(100, 100, 100, 100) as trial example.
No success. Printing one line full width.

The screen is 96 dpi and the printer is, with gambas printer.resolution, 600 dpi.
(The print test say 300 in cups, HP Laserjet 4si)

Using for the positions with Draw the pixel is multiply by (printer.resolution/desktop.resolution)
The tests I did and when there is something printed where on the right positions.


But also not allways the print did work on Draw.End
It looks to me the case when Draw positions are out of page values. 
(Printing beside the paper sheet.
In console (xterm) no report of error to see.

What me is irritating is that i'm not able to Draw two pictures on one sheet.
Direct printing of the texts in parts of the section/sheet are not clipped/wrapped
in the dimensions I wish, and that should be regarding Draw.Clip explanation.

Why Pictures? Well I need 4 upper sections with 8 lower sections and they
contain logo and object diagrams.
Bit stupid to preprint 32 different sheets. 
Beside the object diagrams does not allow those also preprinted.
The labels and textbox are on different places for the objects.

They are used to be able to place them graphically and the textbox for the 
values need for that print.
The client that will use it is a ordinary user and may/can not change program.
The press a 'Safe Layout' and/or 'Print This' button.

Is there someone that can help me to print those 2 pictures and place the text
over the picture in a boxed way    

I'm desperate crying for help after 2 weeks trial/error 6hours/day in a
not so very friendly environment for programming (and cant change it :( ). 

Ron





More information about the User mailing list