[Solved] How to remove all empty pages with a macro
-
- Posts: 33
- Joined: Wed Jul 19, 2017 2:53 am
[Solved] How to remove all empty pages with a macro
Paragraphs is broken into pages based on the page margins automatically.
Because I am using a latex like program to generate odt files, I don't know the
page break before I export the document. I insert pagebreaks at the place where
I only want one pagebreak. Accidentally, the manually inserted pagebreak is
coincide with the automatical one result in an empty page. I have to go back to my
source and delete the manually inserted pagebreak. I really hope there is a
macro that will delete empty pages.
I also created a feature request on the home site of the org mode odt exporter.
https://github.com/kjambunathan/org-mod ... /issues/46
Because I am using a latex like program to generate odt files, I don't know the
page break before I export the document. I insert pagebreaks at the place where
I only want one pagebreak. Accidentally, the manually inserted pagebreak is
coincide with the automatical one result in an empty page. I have to go back to my
source and delete the manually inserted pagebreak. I really hope there is a
macro that will delete empty pages.
I also created a feature request on the home site of the org mode odt exporter.
https://github.com/kjambunathan/org-mod ... /issues/46
Last edited by godblessfq on Thu Aug 09, 2018 9:00 am, edited 13 times in total.
LibreOffice 7.2.3.2 on Debian, emacs org-odt exporter (topic 106686)
-
- Posts: 33
- Joined: Wed Jul 19, 2017 2:53 am
Re: How to remove all empty pages with a macro
The code below looks stupid, and I can't get it to work.
Code: Select all
sub DeleteEmptyPages
emptyPages = ""
noneEmptyPageNumber = 0
foundEmptyObj = False
sTextContent = "com.sun.star.text.TextContent"
oText = ThisComponent.Text
oViewCursor = ThisComponent.CurrentController.getViewCursor()
REM find empty pages
oParEnum1 = ThisComponent.getText().createEnumeration()
Do While oParEnum1.hasMoreElements()
oPar = oParEnum1.nextElement()
oViewCursor.gotoRange(oPar,false)
oViewCursor.gotoendofline(false)
curPageNumber = oViewCursor.page
REM an empty page is an empty object on a single page
If (curpagenumber <> emptyObjPageNumber) And foundEmptyObj Then
emptyPages = emptyPages & "," & CStr(emptyObjPageNumber)
End If
If len(oPar.getString()) <> 0 Or oPar.supportsService("com.sun.star.text.TextTable") Then
noneEmptyPageNumber = oViewCursor.page
foundEmptyObj = False
Else
REM If there is an image anchored to an empty paragraph, getSring will return 0
REM so need to test if the paragraph contains other objects.
If (curPageNumber <> noneEmptyPageNumber) Then
REM Obtain the view cursor, and then select the paragraph containing the view cursor.
oTextCursor = oText.createTextCursorByRange(oViewCursor)
REM Move to the start of the paragraph as a single point.
oTextCursor.gotoStartOfParagraph(False)
REM Move to the end of the current paragraph and expand the selection so that the entire paragraph is selected.
oTextCursor.gotoEndOfParagraph(True)
REM Enumerate the text content contained by this text cursor, including inserted drawing objects, such as the shape used by a button
oEnum = oTextCursor.createContentEnumeration(sTextContent)
If Not oEnum.hasMoreElements() Then
REM an empty paragraph on a new page has been found
REM if the next object is on another page, go back and delete the empty paragraph
emptyObjPageNumber = oViewCursor.page
foundEmptyObj = True
End If
End If
End If
Loop
REM delete empty pages
emptyPagesArray = Split(emptyPages,",")
oParEnum2 = ThisComponent.getText().createEnumeration()
i = 0
Do While oParEnum2.hasMoreElements() And (emptyPagesArray.Length - i > 0) ' I got "basic runtime error. Object variable not set on this line"
oPar = oParEnum2.nextElement()
oViewCursor.gotoRange(oPar,false)
oViewCursor.gotoendofline(false)
curPageNumber = oViewCursor.page
emptyObjPageNumber = CULng(emptyPagesArray(i))
If (curPageNumber = emptyObjPageNumber) Then
oPar.dispose
i = i+1
End If
Loop
end sub
LibreOffice 7.2.3.2 on Debian, emacs org-odt exporter (topic 106686)
-
- Posts: 145
- Joined: Mon Jun 13, 2016 10:50 am
Re: How to remove all empty pages with a macro
Hello,
I'm not absolutely sure, but a manual page break will never follow a soft page break. In your case, I suspect that an empty paragraph exists between those, giving you the wrong idea of an "empty page".
Could these blank paragraphs be avoided when building the odt?
For tuning spaces between paragraphs, you should always prefer paragraph properties and styles to blank paragraphs.
If I'm wrong about empty paragraphs, could you please upload a sample document?
Regards.
I just see that a file was uploaded in the link you give.
The following macro deletes all empty paragraphs where there's no anchored object:
I'm not absolutely sure, but a manual page break will never follow a soft page break. In your case, I suspect that an empty paragraph exists between those, giving you the wrong idea of an "empty page".
Could these blank paragraphs be avoided when building the odt?
For tuning spaces between paragraphs, you should always prefer paragraph properties and styles to blank paragraphs.
If I'm wrong about empty paragraphs, could you please upload a sample document?
Regards.
Edit: |
The following macro deletes all empty paragraphs where there's no anchored object:
Code: Select all
sub delete_empty_paragraph
doc = thiscomponent
paragraphs = doc.Text
for each para in paragraphs
if para.String = "" then
for each portion in para
if portion.TextPortionType <> "Text" then
goto continue
end if
next portion
para.dispose()
end if
continue:
next para
end sub
- Attachments
-
- test.odt
- (27.67 KiB) Downloaded 222 times
AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
-
- Posts: 33
- Joined: Wed Jul 19, 2017 2:53 am
Re: How to remove all empty pages with a macro
Thank you for the example. Actually the problem is not deleting all empty
paragraphs. The problem is to delete empty pages generated by my specific method
of producing odt file.
I am not editing the odt file with openoffice. Instead I use emacs org mode to
do that. It has tremendous benifit execept for an apparent drawback: I don't
know how the document looks like when I am writing.
I inseart a #+pagebreak: command at the place I want a pagebreak, and sometimes
the manual pagebreak is not needed because the document flows naturally to the
next page. But I didn't know, so the actuall document has a blank page due to my
#+pagebreak command.
So I need to remove the empty paragraph (and the only object) that on a single
page, empty paragraphs on other pages doesn't need to be removed.
My failed attempty is to find the empty paragraph that on a single page.
My english is really limited. But I think everyone should have a look at the
amazing emacs org mode.
paragraphs. The problem is to delete empty pages generated by my specific method
of producing odt file.
I am not editing the odt file with openoffice. Instead I use emacs org mode to
do that. It has tremendous benifit execept for an apparent drawback: I don't
know how the document looks like when I am writing.
I inseart a #+pagebreak: command at the place I want a pagebreak, and sometimes
the manual pagebreak is not needed because the document flows naturally to the
next page. But I didn't know, so the actuall document has a blank page due to my
#+pagebreak command.
So I need to remove the empty paragraph (and the only object) that on a single
page, empty paragraphs on other pages doesn't need to be removed.
My failed attempty is to find the empty paragraph that on a single page.
My english is really limited. But I think everyone should have a look at the
amazing emacs org mode.
LibreOffice 7.2.3.2 on Debian, emacs org-odt exporter (topic 106686)
-
- Posts: 33
- Joined: Wed Jul 19, 2017 2:53 am
Re: How to remove all empty pages with a macro
I have uploaded example here
http://s000.tinyupload.com/?file_id=716 ... 5008127655
http://s000.tinyupload.com/?file_id=716 ... 5008127655
LibreOffice 7.2.3.2 on Debian, emacs org-odt exporter (topic 106686)
-
- Posts: 145
- Joined: Mon Jun 13, 2016 10:50 am
Re: How to remove all empty pages with a macro
1. Have you tried the macro above?
2. Could you give us an example file showing the attended result?
2. Could you give us an example file showing the attended result?
AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
-
- Posts: 33
- Joined: Wed Jul 19, 2017 2:53 am
Re: How to remove all empty pages with a macro
Removed due to misleading content.
Last edited by godblessfq on Tue Aug 07, 2018 2:53 pm, edited 1 time in total.
LibreOffice 7.2.3.2 on Debian, emacs org-odt exporter (topic 106686)
-
- Posts: 33
- Joined: Wed Jul 19, 2017 2:53 am
Re: [solved] How to remove all empty pages with a macro
Removed due to misleading content.
Last edited by godblessfq on Tue Aug 07, 2018 2:51 pm, edited 1 time in total.
LibreOffice 7.2.3.2 on Debian, emacs org-odt exporter (topic 106686)
-
- Posts: 33
- Joined: Wed Jul 19, 2017 2:53 am
Re: How to remove all empty pages with a macro
Removed due to misleading content.
Last edited by godblessfq on Tue Aug 07, 2018 2:52 pm, edited 1 time in total.
LibreOffice 7.2.3.2 on Debian, emacs org-odt exporter (topic 106686)
Re: How to remove all empty pages with a macro
You can launch macros outside of the AOO/LO:Is there a way to run the macro through a command line interface?
I tried this :
soffice --norestore macro:///OrgMode.Utilities.DeleteEmptyParagraph(file_path)
viewtopic.php?f=20&p=98460
https://superuser.com/questions/1135850 ... ut-the-gui
https://www.linuxquestions.org/question ... 175445266/
BUT:
The "Thiscomponent" - located in your macro code - refers to the document where the macro was launched from. You must modify your macro if you want to launch it outside of the Open/LibreOffice. You can use the "LoadComponentFromURL..." function to get a specific document - instead of the "Thiscomponent" function.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
-
- Posts: 33
- Joined: Wed Jul 19, 2017 2:53 am
Re: [Solved] How to remove all empty pages with a macro
Removed due to misleading content.
Last edited by godblessfq on Tue Aug 07, 2018 2:54 pm, edited 1 time in total.
LibreOffice 7.2.3.2 on Debian, emacs org-odt exporter (topic 106686)
-
- Posts: 33
- Joined: Wed Jul 19, 2017 2:53 am
Re: [Solved] How to remove all empty pages with a macro
OK. It's not working on all files. Perhaps is better to illustrate the problem
with an illustration (a description of the document) like this:
1. Making odt file by org-mode is not what you see is what you get.
2. It is more like latex, and the final document needs to be compiled.
3. In the source code, eg. I have a very large image, with a very big height (it can be serveral images piled up).
4. Suppose I don't know the image size, because I can't see it during editing.
5. I want a pagebreak after the image (or images), so I insert a pagebreak command.
6. But as you see, the previous image(s) is too long to fit on a sinlge page. So the pagebreak following the image is not needed (I don't know'), all it do is creating a blank page.
7. So I need a macro to remove the blank/empty page as in the attached file.
with an illustration (a description of the document) like this:
1. Making odt file by org-mode is not what you see is what you get.
2. It is more like latex, and the final document needs to be compiled.
3. In the source code, eg. I have a very large image, with a very big height (it can be serveral images piled up).
4. Suppose I don't know the image size, because I can't see it during editing.
5. I want a pagebreak after the image (or images), so I insert a pagebreak command.
6. But as you see, the previous image(s) is too long to fit on a sinlge page. So the pagebreak following the image is not needed (I don't know'), all it do is creating a blank page.
7. So I need a macro to remove the blank/empty page as in the attached file.
- Attachments
-
- test.odt
- (25.81 KiB) Downloaded 221 times
Last edited by robleyd on Sat Aug 04, 2018 4:39 am, edited 1 time in total.
Reason: Remove Known Issues icon [robleyd, Moderator]
Reason: Remove Known Issues icon [robleyd, Moderator]
LibreOffice 7.2.3.2 on Debian, emacs org-odt exporter (topic 106686)
Re: How to remove all empty pages with a macro
I still don't feel sure. But it may be that there never was the intention to insert manual breaks. To do it "blind" in emacs in connection with empty paragraphs may not be a good idea.
You can manipulate the page breaks in a macro like "hubert lambert" provided it by (conditionally?) set the .BreakType property for the inspected paragraphs conditionally as needed. This with or without deleting paragraphs.
The following "reworked" macro would simply remove all manual breaks without removing the paragraphs e.g:
The UndoManager is used for your testin. You can run the macro and then undo everything by one Ctrl+Z.
Concerning the .Breaktype you may consult https://api.libreoffice.org/docs/idl/re ... 4600b2b925 . It should be the same in AOO.
The enumerated names stand for the ascending integers starting with 0 (NONE = 0).
You can manipulate the page breaks in a macro like "hubert lambert" provided it by (conditionally?) set the .BreakType property for the inspected paragraphs conditionally as needed. This with or without deleting paragraphs.
The following "reworked" macro would simply remove all manual breaks without removing the paragraphs e.g:
Code: Select all
Sub removeHardPageBreaks
doc = ThisComponent
doc.UndoManager.EnterUndoContext("Remove hard PageBreaks")
paragraphs = doc.Text
for each para in paragraphs
para.BreakType = 0
next para
doc.UndoManager.LeaveUndoContext
End Sub
Concerning the .Breaktype you may consult https://api.libreoffice.org/docs/idl/re ... 4600b2b925 . It should be the same in AOO.
The enumerated names stand for the ascending integers starting with 0 (NONE = 0).
- Attachments
-
- RemoveManPgBreaksTest.odt
- (27.84 KiB) Downloaded 219 times
On Windows 10: LibreOffice 24.8.2 and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
---
Lupp from München
-
- Posts: 145
- Joined: Mon Jun 13, 2016 10:50 am
Re: [Solved] How to remove all empty pages with a macro
Therein lies the problem.godblessfq wrote:4. Suppose I don't know the image size, because I can't see it during editing.
5. I want a pagebreak after the image (or images), so I insert a pagebreak command.
A page break is a property of the paragraph style. So, when you need a "page break after the image", you need actually that image to be anchored in a paragraph which style contains a page break "after".
Instead of that, you are adding an empty paragraph after that image, that contains the page break. It's a wrong design, if not an error.
That being said, you may try this code. It will only work with the second document you post, which contains a real paragraph with soft break before and hard break after" :
Code: Select all
sub delete_empty_paragraph
doc = thiscomponent
paragraphs = doc.Text
deletepara = False
for each para in paragraphs
if para.String = "" and para.BreakType = 5 then
for each portion in para
if portion.TextPortionType = "SoftPageBreak" then
deletepara = True
elseif portion.TextPortionType <> "Text" then
deletepara = False
exit for
end if
next portion
if deletepara then
para.dispose()
end if
end if
next para
end sub
AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
-
- Posts: 33
- Joined: Wed Jul 19, 2017 2:53 am
Re: How to remove all empty pages with a macro
OK. All your macros are not working as expected. I have one that should be working if the errors are removed.
The idea is simple, I think an empty page is an empty object on a single page, when an empty paragraph on a new page has been found, if the next object is on another page, go back and delete the empty paragraph. Maybe it is more complicated, one case could be an empty page is cause by a page after break followed by a page before break, the just remove one pagebreak; another case is there is a long image taking a whole page and a page before break on the next paragraph, then just remove the page before break. (If I understood it correctly, making the pagebreak an attribute instead of an object is really making things complicated here)
The test file has 4 pages, I need to just remove page 2 and keep all other pages unchanged.
Please help me debug the macro I am working on:
The idea is simple, I think an empty page is an empty object on a single page, when an empty paragraph on a new page has been found, if the next object is on another page, go back and delete the empty paragraph. Maybe it is more complicated, one case could be an empty page is cause by a page after break followed by a page before break, the just remove one pagebreak; another case is there is a long image taking a whole page and a page before break on the next paragraph, then just remove the page before break. (If I understood it correctly, making the pagebreak an attribute instead of an object is really making things complicated here)
The test file has 4 pages, I need to just remove page 2 and keep all other pages unchanged.
Please help me debug the macro I am working on:
Code: Select all
sub DeleteEmptyParagraph(Optional inFileURL)
Dim inDoc
Dim interactive
emptyPages = ""
noneEmptyPageNumber = 0
foundEmptyObj = False
If IsMissing(inFileURL) Then
interactive = True
' Most likely, the Macro is run interactively. Act on
' the current document
If ThisComponent.HasLocation() Then
inDoc = ThisComponent
inFileURL = inDoc.GetLocation()
End If
Else
interactive = False
Dim oProps(0) as New com.sun.star.beans.PropertyValue
oProps(0).Name = "Hidden"
oProps(0).Value = True
inDoc = StarDesktop.loadComponentFromURL(inFileURL, "_blank", 0, oProps())
End If
paragraphs = inDoc.Text
for each oPar in paragraphs
oViewCursor.gotoRange(oPar,false)
oViewCursor.gotoendofline(false)
curPageNumber = oViewCursor.page
REM an empty page is an empty object on a single page
If (curpagenumber <> emptyObjPageNumber) And foundEmptyObj Then
REM save empty page number in a string
emptyPages = emptyPages & "," & CStr(emptyObjPageNumber)
End If
If oPar.String <> "" then
noneEmptyPageNumber = oViewCursor.page
foundEmptyObj = False
goto continue
Else
for each portion in oPar
if portion.TextPortionType <> "Text" then
noneEmptyPageNumber = oViewCursor.page
foundEmptyObj = False
goto continue
else
REM an empty paragraph on a new page has been found
REM if the next object is on another page, go back and delete the empty paragraph
emptyObjPageNumber = oViewCursor.page
foundEmptyObj = True
end if
next portion
end if
continue:
next oPar
REM delete empty pages
emptyPagesArray = Split(emptyPages,",")
paragraphs = inDoc.Text
for each oPar in paragraphs
paragraphs = inDoc.Text
i = 0
for each oPar in paragraphs
oViewCursor.gotoRange(oPar,false)
oViewCursor.gotoendofline(false)
curPageNumber = oViewCursor.page
emptyObjPageNumber = CULng(emptyPagesArray(i))
If (curPageNumber = emptyObjPageNumber) Then
oPar.dispose
i = i+1
End If
next oPar
If (inDoc.isModified() AND inDoc.hasLocation() AND (Not inDoc.isReadOnly())) Then
inDoc.store()
End If
If Not interactive Then
inDoc.Close(True)
End If
end sub
- Attachments
-
- test.odt
- The test file has 4 pages, I need to just remove page 2 and keep all other pages unchanged.
- (21.29 KiB) Downloaded 217 times
Last edited by robleyd on Wed Aug 08, 2018 4:21 am, edited 1 time in total.
Reason: Remove Known Issues icon [robleyd, Moderator]
Reason: Remove Known Issues icon [robleyd, Moderator]
LibreOffice 7.2.3.2 on Debian, emacs org-odt exporter (topic 106686)
-
- Posts: 145
- Joined: Mon Jun 13, 2016 10:50 am
Re: How to remove all empty pages with a mac
Try this one (slighty modified version of the last proposition):
Regarding the paragraph styles: you create a style "OrgParagraph1" with a page break after, but apply it to an empty paragraph. You need actually to avoid that empty paragraph and to apply that style to the paragraph where the image is anchored.
Code: Select all
sub delete_empty_paragraph
doc = thiscomponent
paragraphs = doc.Text
for each para in paragraphs
deletepara = False
if para.String = "" and para.BreakType = 5 then
for each portion in para
if portion.TextPortionType = "SoftPageBreak" then
deletepara = True
elseif portion.TextPortionType <> "Text" then
exit for
end if
next portion
if deletepara then
para.dispose()
end if
end if
next para
end sub
- Attachments
-
- godblessfq.odt
- (42.02 KiB) Downloaded 227 times
AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
-
- Posts: 33
- Joined: Wed Jul 19, 2017 2:53 am
Re: How to remove all empty pages with a mac
That's the problem, I remember the author of org-mode odt exporter used to apply the pagebreak to the previous paragraph instead of creating a empty paragraph, which causes an extra empty line in the next page. Your comment confirms my idea that if we can find an empty paragraph on one page, and the empty paragraph is the only paragraph on that page, then we can delete the empty paragraph, that will solve the problem.hubert lambert wrote: You need actually to avoid that empty paragraph and to apply that style to the paragraph where the image is anchored.
LibreOffice 7.2.3.2 on Debian, emacs org-odt exporter (topic 106686)
-
- Posts: 33
- Joined: Wed Jul 19, 2017 2:53 am
Re: How to remove all empty pages with a Mac
My macro works like this:
1. find empty pages, that is, page with one and only one empty paragraph, save the page numbers to a sting
2. convert the string to array
3. loop over all paragraphs, is its page number is the same with the next saved empty page number, then remove the paragraph
4. since we have removed a page, fix all remaining page numbers
Should this work?
1. find empty pages, that is, page with one and only one empty paragraph, save the page numbers to a sting
2. convert the string to array
3. loop over all paragraphs, is its page number is the same with the next saved empty page number, then remove the paragraph
4. since we have removed a page, fix all remaining page numbers
Should this work?
Code: Select all
sub DeleteEmptyParagraph
Dim inDoc
Dim interactive
emptyPages = ""
noneEmptyPageNumber = 0
foundEmptyObj = False
inDoc = ThisComponent
REM find empty pages
paragraphs = inDoc.Text
for each oPar in paragraphs
oViewCursor.gotoRange(oPar,false)
oViewCursor.gotoendofline(false)
curPageNumber = oViewCursor.page
REM an empty page is an empty object on a single page
If foundEmptyObj And (curpagenumber <> emptyObjPageNumber) Then
REM save empty page number in a string
emptyPages = emptyPages & "," & CStr(emptyObjPageNumber)
End If
If oPar.String <> "" then
noneEmptyPageNumber = oViewCursor.page
foundEmptyObj = False
goto continue
Else
for each portion in oPar
if portion.TextPortionType <> "Text" then
noneEmptyPageNumber = oViewCursor.page
foundEmptyObj = False
goto continue
else
REM an empty paragraph on a new page has been found
REM if the next object is on another page, go back and delete the empty paragraph
emptyObjPageNumber = oViewCursor.page
foundEmptyObj = True
end if
next portion
end if
continue:
next oPar
REM delete empty pages
emptyPagesArray = Split(emptyPages,",")
paragraphs = inDoc.Text
i = 0
j = 0
for each oPar in paragraphs
oViewCursor.gotoRange(oPar,false)
oViewCursor.gotoendofline(false)
curPageNumber = oViewCursor.page
emptyObjPageNumber = CULng(emptyPagesArray(i)) - j
If (curPageNumber = emptyObjPageNumber) Then
oPar.dispose
i = i+1
j = j+1
End If
next oPar
end sub
LibreOffice 7.2.3.2 on Debian, emacs org-odt exporter (topic 106686)
-
- Posts: 145
- Joined: Mon Jun 13, 2016 10:50 am
Re: How to remove all empty pages with a Mac
Did you even try the macro I propose in my last post?godblessfq wrote:My macro works like this: [...]
Should this work?
This macro search for all empty paragraphs (really empty: no text or text content) that contains both a soft break page before and a manually break page after. It's exactly what you describe.
There is no reason why this should happen, unless the orgmode code inserts it on the quiet, which is a bug.godblessfq wrote:That's the problem, I remember the author of org-mode odt exporter used to apply the pagebreak to the previous paragraph instead of creating a empty paragraph, which causes an extra empty line in the next page
And how replacing an unintentional superfluous empty line with an intentional superfluous empty line could be a solution?
Last edited by hubert lambert on Wed Aug 08, 2018 4:40 pm, edited 2 times in total.
AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
-
- Posts: 33
- Joined: Wed Jul 19, 2017 2:53 am
Re: How to remove all empty pages with a Mac
Unbelievable! I have made it!
Code: Select all
sub DeleteEmptyParagraph(Optional inFileURL)
myNoneEmptyPageNumber = 0
myFoundEmptyObj = False
myParToBeDeleted = ""
If IsMissing(inFileURL) Then
interactive = True
' Most likely, the Macro is run interactively. Act on
' the current document
If ThisComponent.HasLocation() Then
inDoc = ThisComponent
inFileURL = inDoc.GetLocation()
End If
Else
interactive = False
Dim oProps(0) as New com.sun.star.beans.PropertyValue
oProps(0).Name = "Hidden"
oProps(0).Value = True
inDoc = StarDesktop.loadComponentFromURL(inFileURL, "_blank", 0, oProps())
End If
REM find empty pages
paragraphs = inDoc.Text
oViewCursor = inDoc.CurrentController.getViewCursor()
restart:
for each oPar in paragraphs
oViewCursor.gotoRange(oPar,false)
oViewCursor.gotoendofline(false)
myCurrentPageNumber = oViewCursor.page
If myFoundEmptyObj And (myCurrentPageNumber <> emptyObjPageNumber) Then
REM an empty page is an empty object on a single page
REM save empty page number in a string
If myParToBeDeleted <> "" then
parToBeDeleted.dispose
myParToBeDeleted = ""
goto restart
End If
myParToBeDeleted = ""
End If
myStr = oPar.String
If myStr <> "" then
myNoneEmptyPageNumber = oViewCursor.page
myFoundEmptyObj = False
goto continue
Else
for each portion in oPar
myTextProp = portion.TextPortionType
if (myTextProp <> "Text" And portion.TextPortionType <> "SoftPageBreak") then
myNoneEmptyPageNumber = oViewCursor.page
myFoundEmptyObj = False
myParToBeDeleted = ""
goto continue
else
if myCurrentPageNumber <> myNoneEmptyPageNumber then
REM an empty paragraph on a new page has been found
REM if the next object is on another page, go back and delete the empty paragraph
emptyObjPageNumber = oViewCursor.page
myFoundEmptyObj = True
myParToBeDeleted = "1"
parToBeDeleted = oPar
end if
end if
next portion
end if
continue:
next oPar
If (inDoc.isModified() AND inDoc.hasLocation() AND (Not inDoc.isReadOnly())) Then
inDoc.store()
End If
If Not interactive Then
inDoc.Close(True)
End If
end sub
LibreOffice 7.2.3.2 on Debian, emacs org-odt exporter (topic 106686)
-
- Posts: 33
- Joined: Wed Jul 19, 2017 2:53 am
Re: How to remove all empty pages with a Mac
On some files there is an error!
Last edited by robleyd on Wed Aug 08, 2018 2:41 pm, edited 1 time in total.
Reason: Remove Known Issues icon [robleyd, Moderator]
Reason: Remove Known Issues icon [robleyd, Moderator]
LibreOffice 7.2.3.2 on Debian, emacs org-odt exporter (topic 106686)
-
- Posts: 145
- Joined: Mon Jun 13, 2016 10:50 am
Re: How to remove all empty pages with a Mac
Bis repetita... :
If you prefer talking to yourself, please let us know.hubert lambert wrote:Did you even try the macro I propose in my last post?
This macro search for all empty paragraphs (really empty: no text or text content) that contains both a soft break page before and a manually break page after. It's exactly what you describe.
AOOo 4.1.2 on Win7 | LibreOffice on various Linux systems
-
- Posts: 33
- Joined: Wed Jul 19, 2017 2:53 am
Re: How to remove all empty pages with a Mac
Sorry Mr Lambert, I have got an issue with the paste daemon gpaste, I tried the wrong macro.
Your macro seems to be working!
Thank you for your patience.
Your macro seems to be working!
Thank you for your patience.
LibreOffice 7.2.3.2 on Debian, emacs org-odt exporter (topic 106686)