Print page x to page y : cannot prevent unwanted last page

For as long as I remember, Xojo was incapable of handling a request for a page range when printing.
Last time I looked at it and gave up was 2015
Does anyone know if this has been fixed recently?

I have to left right now, so I do not have time to fully implement the idea. Here you have the start and idea to write the remainding of the code:

Just before my print loop, I put the code below:

[code] // Printing test dode (Page # x to Page # y)
Dim Print_Page_Start As Integer // First page to print
Dim Print_Page_End As Integer // Last page to print
Dim Print_Page_Number As Integer // Current page number (the “page currently in print”)

// Get the pare range to print
Print_Page_Start = g.FirstPage
Print_Page_End = g.LastPage
Print_Page_Number = 1[/code]

In the line before g.NextPage // Form Feed, I add:

Print_Page_Number = Print_Page_Number + 1

Now I have to add something klike:

If Print_Page_Number >= Print_Page_Start And Print_Page_Number <= Print_Page_End Then // I can print the pages now Else // Skip that page * End If

  • Somewhere (there ?), I can also add this (to skip processing out of range pages)
Print_Page_Number > Print_Page_End Then Exit

I will continue after lunch.

PS: that is something I wanted to add, but by lack of time…

How one can detect if the user click in the Pages RadioButton (All vs Page Range) ?
BTW: I will seach later.

I have tried using this approach myself after posting.
What I find is that I get an unwanted page.

If I do not issue the nextpage statement, then I start drawing on the same page again.
But the last page is generated, and when the printer goes out of scope, it gets prnted even if I do not want it.
There doesnt seem to be a ‘delete last page’ method to prevent this.

Don’t call g.nextpage after the last page of your range. Your graphics object (g) going out of scope will force the printing of the last page. If necessary, set g=nil to force that to happen.

I know.
Thats the problem.
I already have the page in memory.
If the page number is a wanted one, I call nextpage
If it is not, I start drawing over the graphic

But if I have drawn a page and decide I dont need it, I cant find a way of stopping it from printing when the printer goes out of scope.

In other words, you want to decide whether or not to print a page after you’ve drawn it, right? It appears that Xojo’s printing mechanisms don’t allow for that–they force you to decide in advance…

What I wanted was to generate a print file and have the printer driver pick out the range selected by the user.

That doesn’t need to be a simple page 4 to 6 range… it could include discontinuous pages, and PageFROM/PageTO doesnt begin to cover that.
Failing to issue nextpage goes some way towards this, but only just.
And it leaves the last page printing whether wanted or not.

I guess the thing to do is wrap the drawing code inside a ‘is this page needed?’ construct.
For a simple linear file, that would work.

Right now some of the rendering code determines what the next page is going to display… (imagine lines of text where some of them wrap… you dont know how many rows the next page will be able to accept until you try rendering the text and find that row 10 takes up 3 lines)

If I omit the rendering action, I lose track of how much I’ve done.

We use an integer in Shorts to keep track of pages / copies before drawing the page, but I’m not sure off the top of my head if it handles ranges.

I render to an internal representation and then draw that to the printer. One advantage is that I can draw it to a canvas instead and produce an exact print preview that takes into account page size, margins, etc. It also allows me to scale the print to fit the page size, margins, etc. Ie., larger (more readable) font on landscape, but fewer lines per page.

So do I.

So you need to change the decision to call NextPage from “I just rendered a page to the printer, eject the page” to “I’m about to render a page and I have one already pending, eject the page”. And only render those pages that are in range. Don’t render a page from your internal representation to the printer if you’re not going to print it.

Which sounds reasonable, other than I dont know what is on page 5 unless I render page 4

What Im getting is 'if you put something on the page, it’s coming out of the printer no matter what.
To implement things the other way around will mean a wholesale rewrite of an already quite complex printing routine, which works fine, as long as I want every page.
Oh well.

You could create a wrapper class for Graphics similar to Norman’s suggestion here:

You’d have to clone all of the drawing methods and have it keep track of the page by incrementing a counter when NextPage is called, but then you could wrap all of the calls to the original Graphics class like this:

if PageNumber >= g.FirstPage and PageNumber <= g.LastPage then g.DrawString(aString,x,y,width,condense) end if

Here’s a sample

Then all you’d have to do is replace Graphics with MyGraphics.