Printing - left margin

Hi All - I’m having a problem, the cause of which I can’t seem to identify.

my code to print is below (its not pretty but it works) and it successfully generates a .pdf when I print to pdf. However, when I try to actually print it, part of the left hand side gets cut off. So I guess where I’m stuck is that this problem doesn’t seem to happen when I’m printing anything else, which makes me think its a problem in my code but is the left hand margin something I would even set? I thought that styledtextprinter.drawblock started at the appropriate left margin.

[code] // Calling the overridden superclass constructor.
Super.Window
self.hide()

dim mydata(-1) as string = Split(mys0,"------------------------------------------------------------"+endofline+endofline)
dim i as integer

EditField1.TextSize=8
editfield1.Text=mys0

Dim g as Graphics
Dim stp as StyledTextPrinter
dim colwidth as integer = 160
dim spacebetweencols as integer = 18
dim myheight as integer = 7.5*72
dim coltoprint as integer
dim ncols as integer = 4

dim pgsp as new PrinterSetup
call pgsp.PageSetupDialog
g= OpenPrinterDialog(pgsp)
g.TextSize=4

If g <> Nil then
if UBound(mydata)<3 then
MsgBox “Error in report generation. Please contact the software developer, Dan Sandberg.”
self.close()
end if

for coltoprint=1 to 3
  if coltoprint=3 then
    dim secondsplit(-1) as string = split(mydata(coltoprint),"IRAs")
    //First half of investments
    EditField1.text=secondsplit(0)
    stp=EditField1.styledTextPrinter(g,72*7.5)
    stp.width=colwidth
    Do until stp.eof
      stp.DrawBlock (colwidth+spacebetweencols)*(3-1), 0, myheight
    Loop
    
    EditField1.text=endofline+endofline+"IRAs"
    for i=1 to UBound(secondsplit)
      editfield1.text=editfield1.text+secondsplit(i)
    next
    stp=EditField1.styledTextPrinter(g,72*7.5)
    stp.width=colwidth
    
    Do until stp.eof
      stp.DrawBlock (colwidth+spacebetweencols)*(4-1), 0, myheight
    Loop
    
    
    
  else
    EditField1.text=mydata(coltoprint)
    
    stp=EditField1.styledTextPrinter(g,72*7.5)
    stp.width=colwidth
    
    Do until stp.eof
      stp.DrawBlock (colwidth+spacebetweencols)*(coltoprint-1), 0, myheight
      if coltoprint=3 and stp.EOF=false then coltoprint=coltoprint+1
    Loop
  end if
next

End if

self.close()
[/code]

Assuming standard US paper 8.50 x 11.00 inches
you are printing at 72dpi per you code above
that is 612 x 792… IF you could print from edge to edge… which you can’t.
All printers (except some high-end ones) have a MINIMUM set of margins

  ThePS = New PrinterSetup 
  ThePS.Landscape=False
  ThePS.MaxHorizontalResolution=Screen_DPI
  ThePS.MaxVerticalResolution=ThePS.MaxHorizontalResolution
  //
  // These values SHOULD NOT BE CHANGED anywhere else in the program!!
  //
  p.Printer_DPI.x=thePS.HorizontalResolution
  p.Printer_DPI.y=thePS.VerticalResolution
  p.Printer_Paper.x=thePS.PageWidth
  p.Printer_Paper.y=thePS.PageHeight
  p.Printer_Area.x=thePS.Width
  p.Printer_Area.y=thePS.Height
  p.Margin_Top=Abs(thePS.PageTop)
  p.Margin_Left=Abs(thePS.PageLeft)
  p.Margin_Bottom=(p.Printer_Paper.y-p.Margin_Top-p.Printer_Area.y)
  p.Margin_Right=(p.Printer_Paper.x-p.Margin_Left-p.Printer_Area.x)

here is a snippet from one of my programs.
Notice Printer_Paper and Printer_Area
Paper is a portrait page … edge to edge
Printer_Area is what you can “use”

so… variable P is your styledtextprinter? but there is no margin_left property of that… I get the whole resolution x (width - margins) being your printable area I just don’t understand what I need to do to specify starting the drawblock inside the minimum margin

P is a class that stores all the values for later use

The last four lines are the Margins

I’m sorry - I’m not understanding something I guess. Okay, P is a class that stores variables for later use. But at some point you would need to feed those variables to either the graphics class or the styledtextprinter class, right? So in my code I set my column widths to 160 (I print the data in four columns) and for the first column I print with styledtextprinter.drawblock 0,0, 7.572 where my height is 7.572 because I’m in landscape.

stp.DrawBlock (colwidth+spacebetweencols)*(3-1), 0, myheight

that is (160+18)*2 or 178 = 2.47 inches and you are printing a 7.5 inch wide column it seems so this is 2.47 to 9.97
you next moves over again to 4.94 which now puts you past the right margin (4.94+7.5)=12.44 inches

assuming I read your code correctly.

no actually I don’t
I use those to store the Printers MINIMUM values
else where in the program the user is allowed to INCREASE the margins…
at which point I modifiy my graphics

Say the printer min is 0.25 inches (18 pixels)
if you draw a line from 0,0 to 100,100 that line will actually appear on the printer 1/4 from the edge (0,0 is NOT the paper edge… it is the print area edge, relative to the paper)

If my user decides to increase that margin to 0.75 inches…
then I offset every thing by (36 pixels) (.075-.25=0.5)
The printer can never go below its own minimum… that is a hardware issue. but it can go above… but YOU have to deal with it

hmmm… so I understood the first and second parameters of drawblock to be the offset of the top left corner. Interestingly the code you pulled

stp.DrawBlock (colwidth+spacebetweencols)*(3-1), 0, myheight

is for the third column, which prints in the correct place. The column getting cut off is the first column, which is printed by

 stp.DrawBlock (colwidth+spacebetweencols)*(coltoprint-1), 0, myheight

where coltoprint=1 and so (colwidth+spacebetweencols)*(coltoprint-1)=0.

If I print at 0,0 on my printer… the line starts at 0.25,0.25 which are the left/top margins (0.56 and 0.25) are bottom/right on my printer

a modified vrsion of that code will give you data about your specific printer.

At first blush, it sounds like you’re setting your printer’s left margin too small. As Dave pointed out, each printer has a minimum border where it will not print. Anything in that area is just clipped off. What settings are you using in the printer setup dialog?

Thanks for weighing in Tim. I declare a PrinterSetup class and set PrinterSetup.LandScape=true. I do not call the setup dialog. Is this the problem? I thought the default would be to set margins correctly for the printer. I think I’m getting closer to the problem

hmmm… so the .left and .leftmargin properties of the PrinterSetup class are read-only. I mean this is probably where I need to make changes, right? Just not sure how to set the properties because they are read-only.

you are mis-understanding I think

Graphics Pixel (0,0) is at your left margin, top margin (or top margin, left if landscape)

I would check you code to make sure you are not some how ending up with negative values

Just for drill, try it once using the pagesetupdialog. And do look for negative values as Dave suggests. The printersetup reacts to being modified directly differently on the various platforms. Which OS are you using?

@Dave - exactly. I did check the code by using msgbox to print the values and they are all positive.

@ Tim - I’m on Mac OS 10.8.4. I did attempt PageSetupDialog. The dialog that comes up does not provide much. Theres 3 dropdown menus, an orientation (landscape or portrait) and a scale value. I don’t see the actual margin values (e.g. values that could be negative). But the values in the pagesetupdialog aren’t going to be negative, the DrawBlock first two arguments would have to be and they aren’t.

I guess I’ll keep at this and report back. :-/

would you be willing to email me a copy?

Is this on a Mac? What are the margins of the existing PDF target that works correctly? I ask because in the past I’ve created a zero-pixel-margin page-size to print some reports into so I could maintain absolute positioning control.

PDF (on OSX at least) inherits page properties from the current printer.

The Graphics object returned it what you draw on… as stated before coor. 0,0 is the inside of the top/left margin which is some distance from the top and edge of the page.

So the Graphics.Width/72 will be smaller than the physical width of the page by the sum total of the left/right margins, and same is true for top and bottom

I can think of only two things that are happening here.

a) Negative values are being used, such that the content is written outside of the Graphics Object
b) the Graphics Object returned is in fact not the corrrect size, and represents margins that are in fact smaller than the print head is capable of.

Have you run a modified version of the code I provided? It will tell you EXACTLY what you have to work with

This is a bit off-topic, but on OSX you can create a custom page size with custom margins, irrespective of default printer settings. It’s under Paper Size - Manage Custom Sizes. I often use a custom Letter size with 0 sized margins to create my PDFs (and manage my own margins internally).

Hi Dave - I guess i quit for the day yesterday before you. I’m back at it and I emailed a copy to you. I sincerely appreciate your time and effort. Thanks so much for the help. I’ll be really interested in what is causing this problem.