[Solved] Remove blank pages & restart page numbering ?

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
cheuschober
Posts: 19
Joined: Mon Aug 17, 2009 5:45 pm

[Solved] Remove blank pages & restart page numbering ?

Post by cheuschober »

Hi,

I'm having two issues with a post-mailmerge document but I have a small suspicion they are related.

The first issue is with page numbering -- after a mailmerge to file, every record restarts its page numbering. For my purposes, however, I need to be able to break that in the output document and get all pages to number sequentially. This is because my mailmerge isn't -really- a mailmerge -- it's a way to get data out of a db in a well-styled report format.

Which brings us to the second bit; automatically inserted pages. Part of a mm operation includes automatically inserted pages so that each record starts on the same right/left side. Since I'm including the output document as part of a larger report I don't really have a need or use for the blank pages. I can suppress them from printing but that's less ideal than solving the root issue of their existence.

I think these two issues are related. Somewhere there's a property (I don't think it's in the page style) that's forcing the first page of a MM to a specific side and restarting it's numbering but what I don't know is how to find that property and change it.

Any and all help is appreciated. It's been quite the 10 day crash course learning OO.o and trying to achieve my document requirements.

Best,
-C
Last edited by cheuschober on Fri Aug 21, 2009 12:42 am, edited 1 time in total.
OpenOffice.org 3.1.0
Fedora 11
JohnV
Volunteer
Posts: 1585
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA

Re: Remove blank pages & restart page numbering ?

Post by JohnV »

This is because my mailmerge isn't -really- a mailmerge -- it's a way to get data out of a db in a well-styled report format.
Perhaps this will solve your problem. Open new Writer document, press F4, open your database then either Queries or Tables, as appropriate, and click the one you want. Select the records you want in the report using the gray boxes to their left, click the Data to Text icon, put the bullet in Fields or Text and move the desired fields from left to right. Note that you can do basic editing in the right widow. Be sure to separate your records by inserting at least one carriage return after the last field.
cheuschober
Posts: 19
Joined: Mon Aug 17, 2009 5:45 pm

Re: Remove blank pages & restart page numbering ?

Post by cheuschober »

Hi JohnV,

Perhaps I'm not understanding you correctly but I don't think I know how to utilize your advice in order to create my document as-required, especially considering how it does need to be dynamic. Here's a screenshot of the template. Almost all content is database-driven including the columns of text and bullets etc.
floating_table.jpg
Page 1 is equivalent to record 1, pages 2 & 3 are record 2, etc.

Unfortunately for me, the Base report writers (both standand and Sun) just don't seem to have that sort of multi-columnar formatting capability -- or at least that's what I've been lead to believe, and since master reports ignore frames anchored to page (like the table at the bottom) I'm pretty much forced to use a MM and renumber the pages after the merge.

At the moment, I'm just trying to discover where exactly post-mm documents receive the marching orders to renumber with each record. If I can find it I should be able to remove that section break (or whatever it is).

Many thanks for your sound advice.
-C
OpenOffice.org 3.1.0
Fedora 11
cheuschober
Posts: 19
Joined: Mon Aug 17, 2009 5:45 pm

Re: Remove blank pages & restart page numbering ?

Post by cheuschober »

So I spent many more hours fiddling with settings and managed to anchor my text frame to a paragraph while still retaining the formatting I need meaning, I can now include this as part of my master document and don't have to worry about page numbering. (score: 1-0, me).

But, and here's the kicker, the automatically inserted blank pages still exist in the document so page numbering is still skewed. (1-1)

So it seems like what I most need is the ability to rid myself of these auto-inserted blank pages.

Thanks to all for your help thus-far.
-C
OpenOffice.org 3.1.0
Fedora 11
JohnV
Volunteer
Posts: 1585
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA

Re: Remove blank pages & restart page numbering ?

Post by JohnV »

But, and here's the kicker, the automatically inserted blank pages still exist in the document so page numbering is still skewed.
OK, now that I see your report maybe we can fix the problem.

The automatic insertion of blank page normally only happens when the merge document has an odd number of pages, generally 1. The solution is to have and even number of pages in the merge document. So try this as a test and then see if you can apply it to your reports:
Open new Writer document and do the F4 thing until your table is displayed.
Do Format > Page > Columns tab and set to two.
Insert header and footer and insert the page number field in both.
Use dt followed immediately by F3 to insert dummy text to almost fill both columns then tap enter until reach the end of column 2.
Here you want to insert a field that has enough content that you know it will run over to the next page but don't use the Data to Fields icon to fill it.
Do Ctrl+A and Ctrl+C, click so your cursor is at the end of the field, do Ctrl+Enter and then Ctrl+V to fill the new page.
Go back to page 1, click so your cursor is at the end of the field, do Ctrl+F2 > Database tab, select Next Record and Insert. Do not do this on page 2 because OOo will do it for you.
Click the Print icon and answer 'yes' to the 'form letter' query. Set up to print to File, select a few records and print.

When you review the file you should find no blank pages even though the length of your field forced the insertion of a new page and you will get the same result even if the content of the field is short.

This, of course, is a simplistic example but I hope that you can apply the solution to your much more complex report.
cheuschober
Posts: 19
Joined: Mon Aug 17, 2009 5:45 pm

Re: Remove blank pages & restart page numbering ?

Post by cheuschober »

JohnV wrote:OK, now that I see your report maybe we can fix the problem.

The automatic insertion of blank page normally only happens when the merge document has an odd number of pages, generally 1. The solution is to have and even number of pages in the merge document. So try this as a test and then see if you can apply it to your reports:
Open new Writer document and do the F4 thing until your table is displayed.
Do Format > Page > Columns tab and set to two.
Insert header and footer and insert the page number field in both.
Use dt followed immediately by F3 to insert dummy text to almost fill both columns then tap enter until reach the end of column 2.
Here you want to insert a field that has enough content that you know it will run over to the next page but don't use the Data to Fields icon to fill it.
Do Ctrl+A and Ctrl+C, click so your cursor is at the end of the field, do Ctrl+Enter and then Ctrl+V to fill the new page.
Go back to page 1, click so your cursor is at the end of the field, do Ctrl+F2 > Database tab, select Next Record and Insert. Do not do this on page 2 because OOo will do it for you.
Click the Print icon and answer 'yes' to the 'form letter' query. Set up to print to File, select a few records and print.

When you review the file you should find no blank pages even though the length of your field forced the insertion of a new page and you will get the same result even if the content of the field is short.

This, of course, is a simplistic example but I hope that you can apply the solution to your much more complex report.
Hi JohnV,

Thank you for this excellent advice. I had no idea about the alternate (non-paginating) way of going to the next record and will stick that in my cap for use later. I did try it with my document, however, and it didn't work as-expected. It worked for the first two documents but then restarted at page 1 again. Because I have a variable number of records (repeats) and each record may be either even or odd it's still inserting the blank pages if only because I can't copy/paste this as many times as there are records (because I don't know how many records I will have)

If you can, please tell me if I'm on the right or wrong path here:

Blank pages are inserted because OO.o (writer) has a hard rule that 'page 1' must always be on the right side. That said, since mail merges restart page numbering (by default) with each new record, blank pages are inserted after records with an odd-number of pages. A mail merge to file outputs a standard odf-compliant writer document (eg, it's not aware that it came from a mail merge and has no special attributes attached). Which leads me to believe that somewhere within the paragraph or page-break styles / formatting of a merge-output the page numbering is being continually reset to 1. If that property setting can be located or overwritten then the blank pages would automatically disappear, right?

Best,
-C
OpenOffice.org 3.1.0
Fedora 11
cheuschober
Posts: 19
Joined: Mon Aug 17, 2009 5:45 pm

Re: Remove blank pages & restart page numbering ?

Post by cheuschober »

I feel like I'm closing in on this.

I did this manually and it worked. The next step is whether or not it can be automated.

I'd like to try a test and apply the default style to each page break (or alternately search and replace each page break with one that has the default style applied). Unfortunately for me I don't know how to search for or replace a page break. I haven't exactly spent time googling it, though, so I'm hopeful someone else has come up with a method for it. Since generation of this document is already a BASIC driven process it would be trivial to add another step like that and the report itself doesn't have any special page breaks inserted so I wouldn't be interfering with those.

I'm going to try and knock this out this way. Hopefully I'll have my answer.

Best,
-C

ps. I am aware that there are some really lovely power-macros that find/replace page breaks and about 80 billion other objects but I am specifically hunting for the BASIC behind that because who, honestly, likes to generate documents by any means other than a big giant 'GO' button? ;)
OpenOffice.org 3.1.0
Fedora 11
cheuschober
Posts: 19
Joined: Mon Aug 17, 2009 5:45 pm

Re: Remove blank pages & restart page numbering ?

Post by cheuschober »

Success!!

My hunch was right. First text portion of each page held a PageNumberOffset property. If I searched for the ones with PageNumberOffset = 1 and reset it to 0 the blank pages disappeared and my master document can properly take over page numbering functions.

JohnV, thank you so much for your help and patience.

Code below the break:

Code: Select all

Sub RenumberPages(document As Object)
Dim oTextEnum As Object
Dim oTextElement As Object
Dim oTextPortionEnum As Object
Dim oTextPortion As Object

oTextEnum = document.Text.createEnumeration

While oTextEnum.hasMoreElements() REM iterate through paragraphs and tables
  	oTextElement = oTextEnum.nextElement()
	If oTextElement.supportsService("com.sun.star.text.Paragraph") Then
		oTextPortionEnum = oTextElement.createEnumeration()
		While oTextPortionEnum.hasMoreElements()
			oTextPortion = oTextPortionEnum.nextElement()
			If oTextPortion.PageNumberOffset = 1 Then
				oTextPortion.PageNumberOffset = 0
			End If
		Wend

	End If
Wend
End sub
Regards,
-C
OpenOffice.org 3.1.0
Fedora 11
JohnV
Volunteer
Posts: 1585
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA

Re: [Solved] Remove blank pages & restart page numbering ?

Post by JohnV »

Congratulations :!:
Safway
Volunteer
Posts: 347
Joined: Thu Apr 24, 2008 4:35 pm

Re: [Solved] Remove blank pages & restart page numbering ?

Post by Safway »

Here is some more information that might be helpful to others with this issue:
http://www.openoffice.org/servlets/Read ... gNo=126764

At least in ODF 1.2 and OOo 3.x this page numbering and page break problems originate in the paragraph style and are because mail merge assumes you want these (and it is a good assumption for letters). If you don't like this assumption and you don't know how to code then you can still remove the page numbering and page break problems. Here is how.

* Build the template as you want to mail merge with.
* Perform the mail merge and send the output to a singe document file.
* Unzip the single document file into its parts (for example, "unzip OutputFile.odt")
* Edit the paragraph properties (where the page numbering/break happens) found in the content.xml file.
* Rezip all the files into one odt file (for example, "zip -r OutputFile.odt *")

As an example, here is part of my content.xml file where it specified the page numbers should always start with page number one and a page break was performed. I changed the paragraph style so my page numbering was set to auto and so as not to force a page break. Something like
THIS WAS THE ORIGINAL

Code: Select all

<style:style style:name="P2" style:family="paragraph" style:parent-style-name="Standard" style:master-page-name="Standard">
<style:paragraph-properties style:page-number="1"/>
</style:style>
WHICH I CHANGED TO THIS

Code: Select all

<style:style style:name="P2" style:family="paragraph" style:parent-style-name="Standard" style:master-page-name="">
<style:paragraph-properties style:page-number="auto" fo:break-before="auto" fo:break-after="auto"/>
</style:style>
If someone posts a fix for your question, then please post a quick thank you and then go to your first post, use the edit button to add [Solved] as the first word of the title so other people can rely on the fix as well.
LibreOffice 3.3.3 on Fedora
AntonyLiquidBronze
Posts: 1
Joined: Fri Mar 30, 2012 3:30 pm

Re: [Solved] Remove blank pages & restart page numbering ?

Post by AntonyLiquidBronze »

I found that once I had created the mailmerge document and saved to a file it kept all the blank pages in on every other page. I struggled for ages with it, and then discovered that there is a setting once I had pressed print, which is marked "Print automatically inserted blank pages"

I unchecked that box and hey presto - it worked!
Using Open Office 3 on my work Mac mini
Post Reply