Printing without ReportGen.

without knowing how you are doing the scaling & drawing it’s hard to generically answer

it can be done otherwise no one would be printing anything

Initiating the printer with:

Dim g As Graphics
Dim P as PrinterSetup
p= new PrinterSetup
'p.MaxHorizontalResolution=144
g = OpenPrinterDialog§

and then using only

g.drawstring …
g.textsize …
g.drawline …

nothing else

sorry the Apostroph is not alway there (before the p.MaxHorzontalResolution=144

And the result is, that on the pdf-printer the things are horzontally compressed and on the HP-laser-printer not compressed

Here are some snippets of code that work well for me. This first section is in a method that I have for doing the page setup stuff.

gPS = new PrinterSetup if gPS = nil then s = "Unable to create printerSetup class in doPageSetup method in the wStart window. " _ +"The program must quit." beep msgBox s quit end if gPS.maxVerticalResolution = -1 // allow maximum resolution of printer gPS.maxHorizontalResolution = -1 ok = gPS.PageSetupDialog if ok then gxSF = gPS.horizontalResolution \\ 72 // horizontal scale factor gySF = gPS.verticalResolution \\ 72 // vertical scale factor end if

I purposely initially set both the maxVerticalResolution and maxHorizontal resolution to -1 which will return the printers maximum resolution from the PageSetupDialog. Once the code returns from the dialog the x and y scaling factors are set. gxSF and gySF. These are done by dividing the corresponding resolution by 72.

Having the scaling factors these are used to multiply any vertical or horizontal type sizes or locations used during the printing routine. Here are some sample uses of the scaling factors.

headSize = 14 * gySF // heading size scaled for printer resolution normSize = 12 * gySF // normal size scaled for printer resolution smallSize = 10 * gxSF // smaller size for as of date line pg.penHeight = 1 * gySF pg.penWidth = 1 * gxSF pg.textSize = normSize obW = 2 * gxSF // outside border of box is 2 pixels at 72dpi so scale as needed clW = 5 * gxSF // center bar is 5 pixels at 72 dpi vlW = 1 * gxSF // vertical lines making columns are 1 pixel at 72 dpi

headSize, normSize and smallSize are setting up the value to be used for 14, 12, and 10 point font sizes used within this particular report. The penHeight and penWIdth values are also multiplied by the scaling factors. When everything is scaled the way it should be you should see the proper results coming out on the printer and it should work on any printer regardless of the resolution the printer has.

Tomorrw I have to leave for a few days, but will try it out on weekend.
Thanks so far

Robert, it should be working for you, so it’s hard to tell why it isn’t. My guess is that you’re inadvertently applying the scale factor more than once.

Probably it’s a good contribution to Xippets. https://www.boxedbyte.com/xippets.php?xcat=1

It doesn’t work and there is no way, that I am applying any factor more than once.

Looking into the Varaible of gps the maxHorizontalResolution is still -1 and consequently the resulution stays 72.

In the meantime I doubt, if there is a proper conversation between my printer and the computer. After this line :“gPS.maxHorizontalResolution = -1”
there should be the maximum possible resolution in the variable, but isn’t!

gxSF and gySF is still 1

Right, that will not change. What changes is HorizontalResolution. What is that value? And if your factors are 1, then how is it possible that you’re printing too large?

And there is a problem with Harrie’s code, if that is what you’re using. He’s setting the scale factors after PageSetupDialog. The resolution settings are not set until you open the printer and get a graphics object. (As an aside, you can use the dimensions of the graphics object to scale your drawing as well. I lay out all my reports on a mythical 10 characters per inch scale and then scale based on the size of the graphics object. It doesn’t matter how wide the report turns out to be, or what margins the user sets, it all just magically fits.)

A long time ago someone posted a little sample program called PrinterSetupTest which was a fantastic aid in my learning to deal with going directly to the printer when I was writing some programs to assist me in being the scorekeeper for my old bowling league. I totally forgot that part of the reason that PrinterSetupTest was posted was to show how, without opening the printer, you can get the PrinterSetup to hold all of the proper values by invoking invoking “new PrinterSetup” three times as follows. This is the code the program has in the Action event of the “Get Default PS” button on the window.

[code] dim ps as PrinterSetup

if Keyboard.OptionKey then
thePS = new PrinterSetup
thePS.MaxHorizontalResolution = -1
thePS.MaxVerticalResolution = -1
DisplayPSValues thePS, “New default PS”

ps = new PrinterSetup
ps.MaxHorizontalResolution = -1
ps.MaxVerticalResolution = -1
ps.SetupString = thePS.SetupString
thePS = ps
DisplayPSValues thePS, "First restore"

ps = new PrinterSetup
ps.MaxHorizontalResolution = -1
ps.MaxVerticalResolution = -1
ps.SetupString = thePS.SetupString
thePS = ps
DisplayPSValues thePS, "New Improved PS"

else
thePS = new PrinterSetup
thePS.MaxHorizontalResolution = -1
thePS.MaxVerticalResolution = -1
DisplayPSValues thePS, “New default PS”
end if
[/code]

When that code is executed, without ever opening the printer you end up with all of the proper values in the PrinterSetup. I totally forgot how that program worked. So, you can get the proper values without opening the printer; but, to do so, you have to execute the code shown above. In my bowling league programs the printer was opened by the time the values were accessed. So, I am sorry for posting some inaccurate code previously. Thanks for setting me strain on that.

Well,
The above code did also not work, partly because the optionkey is on a mac, which I dont have, also the Line
DisplayPSValues thePS, “New Improved PS”
is for me not understandable and showed up with an error.

Altering everything, so that three times a printersetup was done didn’T change the result. Still in the variable ps and ThePS I can see that the MaxHorizontalResolution = -1 (I only mention horizontal, because I am lazy, but actually have always both directions in the code)
No way, that there is an answer from the printer, to tell me which resolution he has got.
Leaving the printerswetup aside, I can alter the MaxHorizontalResolution to 300 or 600, which actually has no effect to the printed resolution.
And Tim, I was printing large, because I thought, that the printer will make everything smaller, and therefore changed the size of the font to very large.

Thanks anyhow. If I find the reason, I will let you know.

Let’s suppose that you’ve found some undocumented feature (that can stop to work at any non documented time too :)), able to find a way of guessing the characteristics of an attached printer. If you have 3 networked printers available to your system, your code couldn’t “guess” the correct setup to any not chosen printer.

The last Time I plugged the computer directly to the printer by USB-cable. And no - there is only one printer in the net. and in the printersetupdialog I choose the printer.
But even the landscape-order doesn’t work.
I have to turn the page in the pagesetup.
Slowly there is a tiny panic-attack crowling up my legs …

Please note that you must set MaxHorizontalResolution AFTER you call PageSetupDialog and BEFORE you call OpenPrinter. Otherwise, it should just work. I’ve never had a problem getting a higher resolution on a printer.

Try this in a new project.

dim ps as new printersetup
dim g as graphics

if ps.PageSetupDialog then
   ps.MaxHorizontalResolution = 300
   ps.MaxVerticalResolution = 300
   g = OpenPrinterDialog(ps)
   if g <> nil then
      g.TextSize = 48
      g.drawstring("Hello World", 300, 300)
   end
end

Adjust the values of Max???Resolution and observe what happens.

Tried it.
From the “Hello world” was only the Hello Wor on the page.

The Text, which is drawn in the resolution of 72 is ok, means, that the edges are smooth. The only reason, why I wanted the scaling, was that the lines are too thick for a nice form.
But as I do not have any hope, to obtain a solution, I started to drow the lines mith a point of a text:
for i=1 to 404
g.DrawString(".",12+i*2,55)
next
Looks quite good. And the landscape also works.

But for me it is a miracle, why this doesn’t work here.

Could it be the printer-spooler?

Windows 8 shouldn’t have any spooler issues. Trying again:

dim ps as new printersetup
dim g as graphics

if ps.PageSetupDialog then
   ps.MaxHorizontalResolution = -1
   ps.MaxVerticalResolution = -1
   g = OpenPrinterDialog(ps)
   if g <> nil then
      msgbox "Resolution: " + str(ps.HorizontalResolution)
      g.TextSize = 48
      g.drawstring("Hello World", 300, 300)
   end
end

What do you get in the msgbox?

Seems that he wants to draw forms with thinner lines and can’t.
Use g.DrawLine and DrawRect. Adjust thickness in PenHeight and PenWidth. :wink: