AddPageBreak

In using AddPageBreak in some script I’m seeing the page breaks displayed on screen but they aren’t happening when printed.

Looking in the forum I haven’t got a definitive answer to whether or not this was a known bug or what the workaround might be (other than Intelliprint).

Any help is appreciated.

Subject: RE: AddPageBreak

You have to say in more detail what you’re doing.

  • Andre Guirard

IBM/Lotus Development

To get your questions answered, get C R I S P Y

Subject: RE: AddPageBreak

In answer to Andre’s question, here’s what I’m doing:

I’m trying to generate a report using data from the db. From one form, a user will complete three fields to indicate what should be included on the report (Office, Year, Quarter). The first page of the report should be high level summary information. The following pages should be one page each for the detail information supporting the high level summary. Because a number of variables are involved, there’s no way of knowing how many detail pages there should be, so creating fields on the print form ahead of time is out of the question.

As I said, the page breaks show up on the document, they just don’t happen when printing. And if I use a single field dedicated to a page break, that works. But since I use one field for all the detail information, I need to insert the page breaks within that.

So…

Subject: RE: AddPageBreak

You have to say in more detail what you’re doing, including source code and a description of what your situation is at the time the code runs.

Subject: RE: AddPageBreak

Here’s a sample of the code…

	If Val(edoc.TotErrors(0)) > 0 Then

			Call rtitem8.AddPageBreak

			richstyle4.Bold = True

			richstyle4.FontSize = 8

			Call rtitem8.AppendStyle(richstyle4)

This will run in any number of spots depending on whether or not a new page is needed. At completion it creates a printdoc.

Subject: RE: AddPageBreak

Sorry, I don’t know where to go with this. There’s not nearly enough information for me to try to reproduce the problem. You know a lot more about your code than you’ve said, and you’re not sharing any of that knowledge. I’m not any kind of a psychic.

The code sample is useless because I don’t know how you created the document you’re working with, how you created the rich text field, and what you’re doing with it when you’re done. The only thing I know now that I didn’t know before is that you set a style immediately after inserting the page break, sometimes.

Saying that the code executes “in any number of spots” adds precisely no information to the picture. Saying “it creates a printdoc” adds no information. We knew you were creating something to print. The question is HOW do you create your printdoc.

Strategic calls to the NotesRichTextItem.Update method might help you. With what I know, that’s as detailed an answer as it’s possible to give.

Subject: AddPageBreak - an example

I may be able to provide an example of where AddPageBreak is not working for me. I am using Notes 7.0.1. The code’s objective is to take the Rich Text Body fields from several documents and combine them into one Rich Text field in another document. This works find using AppendRTItem(). However, if I also try to insert a page break in between each appended chunk of text, the AddPageBreak() call seems to be ignored. The source document’s rich text content (called ‘attachments’) are mostly simple text with basic formatting.

Here’s the code (simplified from my actual):

Sub AppendAttachments( s as NotesSession, thisDb As NotesDatabase )

Dim p_d_letter As NotesDocument ’ new doc

Dim p_attachments(1 To 2) As String

Set thisDb = s.CurrentDatabase

p_attachments(1) = “sampledoc1”

p_attachments(2) = “sampledoc2”

Set p_d_letter = New NotesDocument( thisDb )

Call p_d_letter.ReplaceItemValue(“Form”, “ResponseLetter”)

Set l_v_attachments = thisDb.GetView(“attachments”)

Set l_rt_body = p_d_letter.CreateRichTextItem( “AttachmentsBody” )

Forall a In p_attachments

  Set l_d_attachment = l_v_attachments.GetDocumentByKey( a, True )

  Set l_rt_attbody = l_d_attachment.GetFirstItem("Body")

  Call l_rt_body.AddPageBreak( ) ' ******* this is ignored **********

  Call l_rt_body.AppendRTItem( l_rt_attbody )

End Forall

Call p_d_letter.Save(True, False)

End Sub

The resulting field and document is complete except for the page breaks. I’ve tried several options:

  1. Use the parameter to AddPageBreak( rtstyle) to add a style to the subsequent parapgrah, and specify Pagination = PAGINATE_BEFORE.

  2. I tried calling AddNewLine(1, True) before AddPageBreak().

  3. I tried calling l_rt_body.Update() in a few places. My understanding was that this was only helpful if you’re using the UI classes also, which I am not.

  4. I added a page break at the very beginning of each Rich Text field that was being copied in. They showed up in the source doc ok, but not in the destination doc when copied programmatically.

The only thing that worked somewhat was a variation on #4 above. Instead of putting a page break in the beginning of the source content field, I added it in the middle (i.e. text above and below the break). Only then was the page break copied into the destination field.

The bottom line is that NotesRichTextItem.AddPageBreak() does not seem to work, or it has an undocumented prerequisite that I’m not meeting. Any help would be greatly appreciated.

Subject: RE: AddPageBreak - an example

Yeah – I still think calling Update just before AddPageBreak might do some good.

Subject: AddPageBreak - GOT IT!

After reading my own post (sometimes that helps… weird), I realized that I did not try adding a newline/newparagraph immediately AFTER the AddPageBreak. It seems like calling AppendRTItem somehow overrides the page break if it’s the same paragraph. Anyway, the following code inside my Forall statement works every time. No need to call Update.

Set l_d_attachment = l_v_attachments.GetDocumentByKey( a, True )

Set l_rt_attbody = l_d_attachment.GetFirstItem(“Body”)

Call l_rt_body.AddPageBreak( ) ’ this need a new pargraph right after

Call l_rt_body.AddNewline(1, True )

Call l_rt_body.AppendRTItem( l_rt_attbody )

So you need to call AddPageBreak() immediately followed by AddNewLine(). This may only be necessary if you’re going to append more Rich Text after the page break, but that’s my case here.

Subject: RE: AddPageBreak - GOT IT!

If you want a newline there, that’s fine, of course. But if you don’t, why would you prefer that to using Update, which doesn’t insert an unwanted paragraph break? Assuming Update works there, of course. I make no guarantees.

Or, I wonder whether the rich text item being appended might have some hide attribute on the first paragraph which prevents printing?

Subject: AddPageBreak

In answer to Andre’s question, here’s what I’m doing:

I’m trying to generate a report using data from the db. From one form, a user will complete three fields to indicate what should be included on the report (Office, Year, Quarter). The first page of the report should be high level summary information. The following pages should be one page each for the detail information supporting the high level summary. Because a number of variables are involved, there’s no way of knowing how many detail pages there should be, so creating fields on the print form ahead of time is out of the question.

As I said, the page breaks show up on the document, they just don’t happen when printing. And if I use a single field dedicated to a page break, that works. But since I use one field for all the detail information, I need to insert the page breaks within that.

So?

Subject: RE: AddPageBreak

There’s couple of ways you can do this, which I’ve done before.

Have the report details come back into one field, which is multi-valued, having each line of the report being one of the multivalues. (Or if each line of the report wraps around, then you’ll have to count characters to determine many lines there are for the report)

Then, check the number of elements in the multivalue field. Based on a number of lines per page constant, you will be able to determine how many pagebreaks you will need.

Next, have a print report form, which has multiple sections which all look like a page, complete with Page Breaks, Headers etc.

Depending on the number of elements, copy element 1 - 70 (example), into the first field for the first page, then elements 71 - 140 into the second field for the second page, etc. If the repeating fields on the print form end up being blank, then a hidewhen will stop it from printing…

If you’re not able to have a structured multivalue field for the report details ‘working field’, then you’ll have to count characters, determine how many characters per page, then know how many pages you’ll need, then move from working field to report field(s) a block of data at a time…

This might seem crude, but it has provided me with flexibility in the past. I used it for printing invoices, not know how many items would be on an invoice, and how verbose the salesman might be…

Hope this helps, Tom.

Subject: AddPageBreak

I had a similiar issue when I was coding a capability for the user to control the page break on a document. I had set a number of Page Break fields on the form, and allowed the user to select “Yes” if they wanted to break at that point.Then I had an agent which built the print form, and interpreted the breaks.

Here’s a sample of the code I used.

If Docb.PB_1(0) = "Yes" Then

	

	Set pagebreak = New NotesRichTextItem ( Docb, "pagebreak_1") 

	Call pagebreak.AddPageBreak

	Call docb.Save(True, True)

End If

If I remember correctly, the Save was the key… if I didn’t save the print form before executing the file print… it didn’t get interpreted. My memory might be off on this, but it might be the answer.