I'm trying to break up an .odt in multiple .pdfs by specifying with markers where one pdf should end and the next one should start. The trouble is, I can't seem to make them to start and end at the correct locations. The first pdf exports just fine, but the second one overshoots and exports some of the text after the marker. Tried searching for similar macros to no avail.
I suspect the reason is somewhere in this part of the code:
Code: Select all
Sub exportSectionToPDF(startMarker, endMarker, suffix, doctextarg)
if len(ThisComponent.getURL())=0 then
msgbox "Please save first"
exit sub
end if
If (Not GlobalScope.BasicLibraries.isLibraryLoaded("Tools")) Then GlobalScope.BasicLibraries.LoadLibrary("Tools")
sPath = convertfromurl(DirectoryNameoutofPath(ThisComponent.getURL(),"/"))
sName = convertfromurl(GetFileNameWithoutExtension(ThisComponent.getURL(),"/"))
dim oVC as Object
oVC = ThisComponent.CurrentController.getViewCursor()
dim startpdf, endpdf
startpdf = InStr(doctextarg, startMarker) - 1
endpdf = InStr(doctextarg, endMarker) '- len(endMarker)
oVC.JumpToFirstPage(false)
oVC.gotoStart(false)
oVC.goRight(startpdf, false)
oVC.goRight(endpdf - startpdf, true)
doctext = oVC.String
msgbox("3 first page, start " & doctext)
saveaspdf(sPath,sName & suffix)
End Sub
Code: Select all
Sub testExport
dim oVC as Object
dim doctext
oVC = ThisComponent.CurrentController.getViewCursor()
oVC.JumpToFirstPage(false)
oVC.JumpToStartOfPage(false)
oVC.gotoStart(false)
oVC.gotoEnd(true)
doctext = oVC.String
exportSectionToPDF("@p1m", "@p2m", " - first part", doctext)
exportSectionToPDF("@p2m", "@p3m", " - second part", doctext)
End Sub
Sub exportSectionToPDF(startMarker, endMarker, suffix, doctextarg)
if len(ThisComponent.getURL())=0 then
msgbox "Please save first"
exit sub
end if
If (Not GlobalScope.BasicLibraries.isLibraryLoaded("Tools")) Then GlobalScope.BasicLibraries.LoadLibrary("Tools")
sPath = convertfromurl(DirectoryNameoutofPath(ThisComponent.getURL(),"/"))
sName = convertfromurl(GetFileNameWithoutExtension(ThisComponent.getURL(),"/"))
dim oVC as Object
oVC = ThisComponent.CurrentController.getViewCursor()
dim startpdf, endpdf
startpdf = InStr(doctextarg, startMarker) - 1
endpdf = InStr(doctextarg, endMarker) '- len(endMarker)
oVC.JumpToFirstPage(false)
oVC.gotoStart(false)
oVC.goRight(startpdf, false)
oVC.goRight(endpdf - startpdf, true)
doctext = oVC.String
msgbox("3 first page, start " & doctext)
saveaspdf(sPath,sName & suffix)
End Sub
Sub saveaspdf(sPath,sName)
oselection=thiscomponent.getcurrentselection
Dim aFilterData(0) as new com.sun.star.beans.PropertyValue
aFilterData(0).Name = "Selection"
aFilterData(0).Value = oselection
Dim args3(1) as new com.sun.star.beans.PropertyValue
args3(0).Name = "FilterName"
args3(0).Value = "writer_pdf_Export"
args3(1).Name = "FilterData"
args3(1).Value = aFilterData
thiscomponent.storeToURL(converttourl(sPath & getpathseparator & sName & ".pdf"),args3())
End Sub
Code: Select all
OpenOffice 4.1.5
AOO415m1(Build:9789) - Rev. 1817496
2017-12-11 15:46 - Linux x86_64
Ubuntu 16.04 LTS