Hi Malcolm,

maybe the macro I just wrote will help you. Please note that it is by no means 'perfect' because I have not tested all possible situations. The problem is that there is no such API function as to recognize whether a page is empty, so you have to check it on your own. Because there are many ways to skip a page it is also not doable in one specific and simple way.

My macro checks the first 'chars' characters on the page, if they are all whitespace or if there is none but a page break it will remove the page. You can set the value to whatever you want (I check for the first 50 characters), depending on how well your document is structured. For example if you don't have messy formatting (messy means i.e. if some pages only have text in the middle and don't start at the top) then you can set it be low, otherwise set this value much higher.

<code>
Private chars as Integer 'specifies the number of characters checked at the beginning of every page

Function emptypage
 Dim i as Integer
 chars = 50

 odoc = thisComponent
 'if you have problems with thisComponent for the new OOo 2.0 builds,
 'use Stardesktop.getCurrentComponent() instead

 otext = odoc.getText()
 cur = otext.createTextCursor()   
 cur.goToStart(False)

 view = odoc.getCurrentController()
 viewcursor = view.getViewCursor()

 'retrieve total page number
 viewcursor.jumpToLastPage()
 npages = viewcursor.getPage()
 viewcursor.jumpToFirstPage()

 For i = 1 to npages
    cur.goRight(chars, True)
    txt = Trim(cur.String)
    If len(txt) = 0 Then
        DeletePage(cur, i)
    Else
        If Asc(txt) <= 32 Then
            DeletePage(cur, i)
        Else
            viewcursor.jumpToNextPage()   
            cur.goToRange(viewcursor.getStart(), False)
        End If
    End If   
   
 Next i

End Function

Function DeletePage(cur, i as Integer)
 cur.goLeft(chars, False)
 cur.goToNextWord(True)
 cur.setString("")
 i =+ 1
End Function</code>

Hope this helps you.

2005/5/14, malcolm cooke <[EMAIL PROTECTED]>:
Hi Paolo,

I would if I could :-)

Unfortunately the adding / removing of text to/from the template document
(which in itself contains a lot of formatted text) is database driven and
dependent upon a whole host of factors based around a particular customers
geographic location. Obviously the template has to cater for all
possibilities and as large amounts of text get added / removed the original
page boundaries fluctuate.

Malcolm

  At 22:21 13/05/2005, you wrote:

>Hi Malcom,
>
>Alle 18:02, venerd́ 13 maggio 2005, malcolm cooke ha scritto:
> > Hi,
> >
> > I wonder if anyone can give me pointers how to do this?
> >
> > Background - a document is created programmatically from a template and in
> > the process text  added / removed. As a result now end up with empty pages
> > because of the way text is now flowing through the document. There is a
> > need to remove the extra blank pages.
> >
> > I have looked at content xml to see if anything obvious to identify the
> > blank page and there isn't (which I suppose is understandable because the
> > blanks pages are a symptom of the 'presentation' of the content)
>[....]
>
>Bingo!
>the pages of a document are the consequence.
>You should act on the cause instead.
>
>empty rows?  wrong page style? wrong paragraph style? or manual page breaks?
>Ask yourself what is the cause of empty pages in your document and remove it
>using API's
>
>ciao
>Paolo Mantovani
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
>
>
>--
>No virus found in this incoming message.
>Checked by AVG Anti-Virus.
>Version: 7.0.308 / Virus Database: 266.11.9 - Release Date: 12/05/2005

--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.11.9 - Release Date: 12/05/2005

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




--
Best Regards
Christian Junker

Reply via email to