StyledTextPrinter on Windows, horrible print quality

Has anyone tried the StyledTextPrinter Example project (\Example Projects\Printing and Reporting\Printing\StyledTextPrinterExample.xojo_binary_project) that comes with Xojo 2017r2?. Although <https://xojo.com/issue/45971> shows this issue as being fixed, the print qualitly produced by this example project is still as horrible (i.e. unusable) as before. So, is this fixed or not?

That feedback report was specific to the Xojo report feature. I just verified the issue with the Xojo report is fixed.

What version are you using to run the sample ?

Yeah, perhaps. However, I had filed a feedback report specifially for the issue with StyledTextPrinter (<https://xojo.com/issue/47905>). This report was closed due to it reportedly being a duplicate of <https://xojo.com/issue/45971>. So now, #45971 is being marked as being fixed, but I still can’t use StyledTextPrinter. So, maybe it wasn’t a duplicate at all.

Again, has anyone tried the StyledTextPrinter Example project (\Example Projects\Printing and Reporting\Printing\StyledTextPrinterExample.xojo_binary_project) that comes with Xojo 2017r2? If so, what does the print quality look like for you? I’m trying to find out if others are also seeing the same issue before I go and file another feedback report.

I’m running 2017r2.

Looks like that is a separate issue. For myself I wasn’t using styled text printer, but I just tested it and it is a problem.

Thanks for confirming. I’ll create a fresh feedback report.

The resolution problem was reported and I was told that the issues in windows are simply because StyledTextPrinter uses a static image against the static resolution device that is presented by Direct2D printing (96DPI)- while DrawString can always be completely resolution independent. So to me it seemed like it would not be fixed any time soon.

So I re-worked my printing for Windows using StyledTextPrinter to print to a large picture (3 or 4 times the page size at 96DPI) and then draw the large picture to the printer. Slow but looks much better. This is only necessary for Windows builds.

If Drawstring works fine, then why not forego the StyledTextPrinter and take control yourself?
Its a bit more work, but all you have to do is step thru the Styleruns which contain all the font, color, bold, italic etc information and issue the appropriate DrawString… Yes I know there is a bit more to it than just that… but write it once, use it forever.

And this type solution would be resolution independent, and platform independent.

Thanks. I hacked up a quick and dirty routine to replace the “PrintButton.Action” event handler in the StyledTextPrinterExample to test this (see below). It does indeed produce better quality. However, multiple pages don’t seem to work. There is enough “Lorem Ipsum…” text for 2 pages, and the code does indeed print 2 pages, but the contents on both pages is the same. I checked the contents of pic after stp.DrawBlock is called (it gets called twice), and the its contents are updated properly. I haven’t been able to figure out what the issue is. Any ideas? How are you handling multiple pages in your solution?

Here’s my test code. You can easily try it out for yourself by replacing the code in the PrintButton.Action event handler in the StyleTestPrinterExample project with the code below.

[code]Dim stp As StyledTextPrinter
Dim g As Graphics
Dim ps As New PrinterSetup

// Set the scale
Dim scale As Double = 4
Dim oldFontSize, newFontSize As Integer
oldFontSize = PrintTextArea.TextSize
If oldFontSize = 0 Then newFontSize = 48 Else newFontSize = scale * oldFontSize
PrintTextArea.TextSize = newFontSize

dim w, h as integer

If ps <> Nil Then
ps.MaxHorizontalResolution = 72
ps.MaxVerticalResolution = 72
g = OpenPrinterDialog(ps) //open Print dialog with pagesetup properties
w = scale * ps.Width
h = scale * ps.Height
Else
g = OpenPrinterDialog //open with no pageSetup properties
w = scale * 72 * 7.5
h = scale * 72 * 10
End If

Dim pic As New Picture(w,h,32)
Dim gp As Graphics = pic.Graphics
stp = PrintTextArea.StyledTextPrinter(gp, w)
Do Until stp.EOF
stp.DrawBlock(0, 0, h)
g.DrawPicture pic, 0, 0, g.Width, g.Height, 0, 0, pic.Width, pic.Height
If Not stp.EOF Then
// There is more text, so add a page
gp.NextPage
g.NextPage
End If
Loop

// Restore font size
PrintTextArea.TextSize = oldFontSize[/code]

I figured it out inserting the following line before stp.DrawBlock fixes the issue.

  gp.ClearRect 0, 0, gp.Width, gp.Height

I filed a feedback report. Please sign on.

<https://xojo.com/issue/49288>

[quote]If Drawstring works fine, then why not forego the StyledTextPrinter and take control yourself?
Its a bit more work, but all you have to do is step thru the Styleruns which contain all the font, color, bold, italic etc information and issue the appropriate DrawString… Yes I know there is a bit more to it than just that… but write it once, use it forever.
[/quote]

Yep, I thought about that for a while but have a few more pressing things at the moment. Printing is something I really wish would just go away! I thought everything would be paperless by now… So using StyledTextPrinter was always a quick and dirty way to let the user print a text area - not that they need to do that very often. I just want it to look decent if they do. When it looks bad it makes the entire app look bad.