OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Create N writer douments from a doument with N pages

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
Shibu_n
General User
General User


Joined: 28 Mar 2006
Posts: 19

PostPosted: Thu Dec 07, 2006 8:24 pm    Post subject: Create N writer douments from a doument with N pages Reply with quote

Hi All

I have a requirement where in I have to create a few new document's by taking out each page of an existing document. The format and style should be that of the existing document. Can any one help me fetch a macro for doing this.

Any one please help..

Thanks in advance

Regards


Shibu
Back to top
View user's profile Send private message Yahoo Messenger
probe1
Moderator
Moderator


Joined: 18 Aug 2004
Posts: 2560
Location: Chonburi Thailand Asia

PostPosted: Fri Dec 08, 2006 1:13 am    Post subject: Reply with quote

Please have a look at the Basic code in this example:
makeDayCopy

Make a copy of actual document.

The name and location of an actual loaded document is retrieved. Both will be expanded with a defined string. Then a SAVE operation to the same location is tried.



Can you start your coding from this?
_________________
Cheers
Winfried
My Macros
DateTime2 extension: insert date, time or timestamp, formatted to your needs
Back to top
View user's profile Send private message Visit poster's website
Shibu_n
General User
General User


Joined: 28 Mar 2006
Posts: 19

PostPosted: Sun Dec 17, 2006 9:34 pm    Post subject: Reply with quote

Hi,

The link was not of much help. I think that creates a copy of the whole document/documents. I want to separate documents into single pages.

Shibu
Back to top
View user's profile Send private message Yahoo Messenger
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

PostPosted: Mon Dec 18, 2006 9:19 am    Post subject: Reply with quote

Here is a very basic macro to do what you want. It does not attempt to match page styles to the original. It does not copy frames, headers, footers (any page number field would be 1 anyway), footnotes and who knows what else. I can only say that it's better than nothing. You will end up with one new file per page in the same directory where the original file is saved named, "OriginalFileNameN".
Code:
Option Explicit
Sub FilePerPage
Dim oDoc,oVC,oUrl,fileName,pages,aPage,oFrame,dispatcher,ps
Dim fileN,aPageVC,aPageTC,aPageFrame,X,oTC,fileNameX,UrlX,ext
oDoc = ThisComponent
oVC = oDoc.currentController.getViewCursor
oUrl = oDoc.getURL : oUrl = Split(oURL,"/")
fileName = oUrl(uBound(oUrl))
oUrl(uBound(oUrl)) = "" : oUrl = join(oUrl,"/")
fileN = Split(fileName,".") : ext = "." & fileN(uBound(fileN())
fileName = fileN(0)
oVC.gotoEnd(false)
pages = oVC.getPage
oFrame = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
aPage = StarDesktop.loadComponentFromURL("private:factory/swriter","_blank",0,Array())
aPageVC = aPage.CurrentController.getViewCursor
aPageFrame = aPage.CurrentController.Frame
For X = 1 to pages
 oVC.jumpToPage(X) : oVC.jumpToEndOfPage
 oTC = oDoc.Text.createTextCursorByRange(oVC)
 oVC.jumpToStartOfPage : oVC.gotoRange(oTC,true)
 dispatcher.executeDispatch(oFrame, ".uno:Copy", "", 0, Array())
 dispatcher.executeDispatch(aPageFrame, ".uno:Paste", "", 0, Array())
 fileNameX = fileName & X & ext
 UrlX = oUrl & fileNameX
 aPage.StoreToUrl(UrlX,Array())
 aPageVC.gotoStart(True)
 aPageVC.String = ""
 oVC.collapseToEnd
Next X
aPage.dispose()
End Sub
Back to top
View user's profile Send private message
Shibu_n
General User
General User


Joined: 28 Mar 2006
Posts: 19

PostPosted: Tue Dec 19, 2006 12:10 am    Post subject: Reply with quote

Hello John

Thankyou very much for the macro you have give. It works well in many cases. But there is an issue when there are numbered lists and the sequence continues in the next page. The numbering starts from 1 in the newly created document. Is there a way to solve this. This is very important for me. The macro is extremely good in other cases.

Thanks Again

Shibu
Back to top
View user's profile Send private message Yahoo Messenger
JohnV
Administrator
Administrator


Joined: 07 Mar 2003
Posts: 9183
Location: Lexinton, Kentucky, USA

PostPosted: Tue Dec 19, 2006 5:48 am    Post subject: Reply with quote

Quote:
there are numbered lists and the sequence continues in the next page. The numbering starts from 1 in the newly created document.
You are using a feature of OOo that numbers a list starting with the number 1. When you split the list to one page then it's going to start with 1 because there are no items before it.

Just as I mentioned that a page number field would always be 1 and included "and who knows what else" you are not going to be able to continue or impliment features that rely on the content of other pages being present.

The only solution that I can think of is to simply type the numbers for your list.
Back to top
View user's profile Send private message
Shibu_n
General User
General User


Joined: 28 Mar 2006
Posts: 19

PostPosted: Wed Dec 20, 2006 1:10 am    Post subject: Reply with quote

Ok Then Gentleman,

I will have to look into some other means to get this done. I'm surprised as to how this can happen. The current page contents are taken into the buffer and then pasted into a new document. I'm not bothered about the text heading or other stuff, but this is behaviour is awkward.

May be this should be taken as a future enhancement/bug

Thanks again for your time,

Regards

Shibu
Back to top
View user's profile Send private message Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group