# Printing without ReportGen.

**URL:** <https://forum.xojo.com/t/printing-without-reportgen/16803>\
**Category:** Getting Started\
**Created:** [May 26, 2014, 5:03am UTC](https://forum.xojo.com/t/printing-without-reportgen/16803 "2014-05-26T05:03:00Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![Norman\_P](https://forum.xojo.com/letter_avatar_proxy/v4/letter/n/858c86/32.png) [@Norman\_P](https://forum.xojo.com/u/Norman_P)\
**Post date:** [May 26, 2014, 6:13pm UTC](https://forum.xojo.com/t/printing-without-reportgen/16803/21 "2014-05-26T18:13:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Robert\_Blazek](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/c68b51/32.png) [@Robert\_Blazek](https://forum.xojo.com/u/Robert_Blazek)\
**Post date:** [May 26, 2014, 6:19pm UTC](https://forum.xojo.com/t/printing-without-reportgen/16803/22 "2014-05-26T18:19:35Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Robert\_Blazek](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/c68b51/32.png) [@Robert\_Blazek](https://forum.xojo.com/u/Robert_Blazek)\
**Post date:** [May 26, 2014, 6:21pm UTC](https://forum.xojo.com/t/printing-without-reportgen/16803/23 "2014-05-26T18:21:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Robert\_Blazek](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/c68b51/32.png) [@Robert\_Blazek](https://forum.xojo.com/u/Robert_Blazek)\
**Post date:** [May 26, 2014, 6:23pm UTC](https://forum.xojo.com/t/printing-without-reportgen/16803/24 "2014-05-26T18:23:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Harrie\_Westphal](https://forum.xojo.com/letter_avatar_proxy/v4/letter/h/7feea3/32.png) [@Harrie\_Westphal](https://forum.xojo.com/u/Harrie_Westphal)\
**Post date:** [May 26, 2014, 6:46pm UTC](https://forum.xojo.com/t/printing-without-reportgen/16803/25 "2014-05-26T18:46:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Robert\_Blazek](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/c68b51/32.png) [@Robert\_Blazek](https://forum.xojo.com/u/Robert_Blazek)\
**Post date:** [May 26, 2014, 8:59pm UTC](https://forum.xojo.com/t/printing-without-reportgen/16803/26 "2014-05-26T20:59:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [May 26, 2014, 9:05pm UTC](https://forum.xojo.com/t/printing-without-reportgen/16803/27 "2014-05-26T21:05:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [May 27, 2014, 12:28am UTC](https://forum.xojo.com/t/printing-without-reportgen/16803/28 "2014-05-27T00:28:02Z")

</div>

> [@91926:@Harrie Westphal](#):
>
> Here are some snippets of code that work well for me…

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

---

<div class="post-metadata">

**Author:** ![Robert\_Blazek](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/c68b51/32.png) [@Robert\_Blazek](https://forum.xojo.com/u/Robert_Blazek)\
**Post date:** [May 29, 2014, 10:02pm UTC](https://forum.xojo.com/t/printing-without-reportgen/16803/29 "2014-05-29T22:02:43Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Robert\_Blazek](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/c68b51/32.png) [@Robert\_Blazek](https://forum.xojo.com/u/Robert_Blazek)\
**Post date:** [May 29, 2014, 10:03pm UTC](https://forum.xojo.com/t/printing-without-reportgen/16803/30 "2014-05-29T22:03:40Z")

</div>

gxSF and gySF is still 1

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [May 29, 2014, 10:45pm UTC](https://forum.xojo.com/t/printing-without-reportgen/16803/31 "2014-05-29T22:45:39Z")

</div>

> [@93278:@Robert Blazek](#):
>
> Looking into the Varaible of gps the maxHorizontalResolution 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.)

---

<div class="post-metadata">

**Author:** ![Harrie\_Westphal](https://forum.xojo.com/letter_avatar_proxy/v4/letter/h/7feea3/32.png) [@Harrie\_Westphal](https://forum.xojo.com/u/Harrie_Westphal)\
**Post date:** [May 30, 2014, 5:39pm UTC](https://forum.xojo.com/t/printing-without-reportgen/16803/32 "2014-05-30T17:39:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Robert\_Blazek](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/c68b51/32.png) [@Robert\_Blazek](https://forum.xojo.com/u/Robert_Blazek)\
**Post date:** [May 31, 2014, 1:46pm UTC](https://forum.xojo.com/t/printing-without-reportgen/16803/33 "2014-05-31T13:46:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Robert\_Blazek](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/c68b51/32.png) [@Robert\_Blazek](https://forum.xojo.com/u/Robert_Blazek)\
**Post date:** [May 31, 2014, 1:46pm UTC](https://forum.xojo.com/t/printing-without-reportgen/16803/34 "2014-05-31T13:46:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [May 31, 2014, 2:27pm UTC](https://forum.xojo.com/t/printing-without-reportgen/16803/35 "2014-05-31T14:27:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Robert\_Blazek](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/c68b51/32.png) [@Robert\_Blazek](https://forum.xojo.com/u/Robert_Blazek)\
**Post date:** [May 31, 2014, 3:43pm UTC](https://forum.xojo.com/t/printing-without-reportgen/16803/36 "2014-05-31T15:43:08Z")

</div>

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 …

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [May 31, 2014, 6:47pm UTC](https://forum.xojo.com/t/printing-without-reportgen/16803/37 "2014-05-31T18:47:54Z")

</div>

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.

```auto
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.

---

<div class="post-metadata">

**Author:** ![Robert\_Blazek](https://forum.xojo.com/letter_avatar_proxy/v4/letter/r/c68b51/32.png) [@Robert\_Blazek](https://forum.xojo.com/u/Robert_Blazek)\
**Post date:** [May 31, 2014, 11:16pm UTC](https://forum.xojo.com/t/printing-without-reportgen/16803/38 "2014-05-31T23:16:09Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [May 31, 2014, 11:22pm UTC](https://forum.xojo.com/t/printing-without-reportgen/16803/39 "2014-05-31T23:22:29Z")

</div>

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

```auto
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?

---

<div class="post-metadata">

**Author:** ![Rick\_Araujo](https://forum.xojo.com/user_avatar/forum.xojo.com/rick_araujo/32/251_2.png) [@Rick\_Araujo](https://forum.xojo.com/u/Rick_Araujo)\
**Post date:** [June 1, 2014, 1:00am UTC](https://forum.xojo.com/t/printing-without-reportgen/16803/40 "2014-06-01T01:00:54Z")

</div>

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

[Previous page](https://forum.xojo.com/t/printing-without-reportgen/16803.md?page=1)

[Next page](https://forum.xojo.com/t/printing-without-reportgen/16803.md?page=3)
