Orisa
Posts: 1,999
Karma: 1035571
Join Date: Feb 2010
Location: Ireland
Device: Onyx Poke 5
|
I can do the sentences part in German, if it's small, and check your English sentences. They can't be so awful :P
By the Way, I have had an error while working with an odt file.
I have received this error:
I will put here the generated code, I hope it helps:
Spoiler:
Code:
REM ***** BASIC *****
'______________________________________________________________________________
'
' Writer to ePub export by Luca Calcinai
'
' This extension is free software; you can redistribute it and/or
' modify it under the terms of the GNU Lesser General Public
' License as published by the Free Software Foundation.
'
' This library is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
' Lesser General Public License for more details.
'
' Please email me with any bug reports, questions or comments:
' luca.calcinai@simplicissimus.it
'
' Many thanks to (in no particular order):
' Paolo Mantovani, for his code, support and patience
' Juda, for his constant support and his hawk's eye
' Shinken, my ePub Master
' Sbin, for her CSS
' Roby, my xhtml consultant
' Poxi1023, for his odt2pml code portions, widely used in this work
' Andrew Pitonyak, for his "teachership"
'
'
'______________________________________________________________________________
'
'
' Declarations:
Option Explicit
Public sDocURL As String '
Public sDocDir As String '
Public sFileExt As String '
Public sFileN As String
Public MyEpub As String
Public oDoc, fenDoc, oText as object
Public myUUIDv4 as String
Public iSplitCount as integer
Public bDevelopment as Boolean
Public sVersion as String
'==================================================================
'========================== MAIN ROUTINE ==========================
'==================================================================
Sub writer2epubMain
Dim StartTime, EndTime As Long
Dim oBar As Object
bDevelopment = true
sVersion = "0.1.10"
oDoc = ThisComponent
if bDevelopment=false then
On Error GoTo ErrorHand
end if
If NOT GlobalScope.BasicLibraries.isLibraryLoaded( "Tools" ) Then GlobalScope.BasicLibraries.loadLibrary( "Tools" )
myUUIDv4 = UUIDv4()
FilePrimer
StartTime = Timer
oBar = oDoc.CurrentController.getStatusIndicator()
oBar.start ("Work in progress : ", 100)
fenDoc = oDoc.CurrentController.Frame.ContainerWindow
oDoc.lockControllers
fenDoc.Enable = False
CreateFolderStructure(MyEpub)
oBar.value = 20
iterateGraphics (MyEpub)
XSLTransform (MyEpub)
oBar.value = 30
CreateMimeTypeFile(MyEpub)
oBar.value = 40
CreateContainerFile(MyEpub)
oBar.value = 50
' CreateContentFile(MyEpub)
oBar.value = 60
CreateContentOpfFile(MyEpub)
oBar.value = 70
CreateTocFile(MyEpub)
oBar.value = 80
CreateCSSFile(MyEpub)
oBar.value = 100
oBar.end
fenDoc.Enable = True
oDoc.unlockControllers
oDoc.Close (True)
' CleanFiles (MyEpub)
CreateEpub(MyEpub)
EndTime = Timer
oDoc = starDesktop.loadComponentFromUrl (sDocURL, "_blank", 0, Array())
' oDoc = starDesktop.loadComponentFromUrl (sFileN & ".odt", "_blank", 0, Array())
Beep
Msgbox "Epub Export Complete" & Chr(13) & Chr(13) & "(Time: " & EndTime - StartTime & " Second)"
'---- remove temp folder -----
if bDevelopment =false then
If FileExists(MyEpub) Then
RmDir MyEpub
End If
end if
Exit Sub
ErrorHand:
ErrorHandler
End Sub
'==================================================================
'============================ END MAIN ============================
'==================================================================
Sub FilePrimer
dim Args1(1) as new com.sun.star.beans.PropertyValue
'Before processing check save status
If oDoc.hasLocation=False Then
MsgBox ("Please save your text before processing!",16,"Writer2ePub")
End
End If
'save before processing!
If (oDoc.isModified) Then
MsgBox ("Please save your text before processing!",16,"Writer2ePub")
End
' oDoc.store()
End If
sDocURL = oDoc.getURL()
sDocDir=DirectoryNameoutofPath(sDocURL, "/")
sFileExt=GetFileNameExtension(sDocURL)
sFileN=GetFileNamewithoutExtension(sDocURL) 'with path!
MyEpub = sFileN
'REMOVE PREVIOSLY GENERATED FILE AND FOLDER
If FileExists(MyEpub & ".epub") Then
Kill (MyEpub & ".epub")
End If
If FileExists(MyEpub) Then
RmDir MyEpub
End If
End Sub
Sub CreateFolderStructure (MyEpub as string)
MkDir (MyEpub & "/META-INF")
MkDir (MyEpub & "/OEBPS/text")
End Sub
Sub CreateMimeTypeFile (MyEpub as string)
'---- Create MIMETYPE file ----
Dim content as string
Dim fileAccessService, textOutputStream, outputStream as Object
content = "application/epub+zip"
fileAccessService = createUnoService("com.sun.star.ucb.SimpleFileAccess")
textOutputStream = createUnoService("com.sun.star.io.TextOutputStream")
outputStream = fileAccessService.openFileWrite(MyEpub + "/mimetype")
outputStream.truncate()
textOutputStream.setOutputStream(outputStream)
textOutputStream.writeString(content)
textOutputStream.flush()
textOutputStream.closeOutput()
End Sub
Sub CreateContainerFile (MyEpub as string)
'---- Create CONTAINER.XML file ----
Open MyEpub + "/META-INF/container.xml" For Output As #1
Print #1, "<?xml version=""1.0""?>"
Print #1, "<container version=""1.0"" xmlns=""urn:oasis:names:tc:opendocument:xmlns:container"">"
Print #1, " <rootfiles>"
Print #1, " <rootfile full-path=""OEBPS/content.opf"" media-type=""application/oebps-package+xml""/>"
Print #1, " </rootfiles>"
Print #1, "</container>"
Close #1
End Sub
Sub CreateContentFile (MyEpub as string)
'---- Create CONTENT.XML file ----
TextTagger
' ExtractWriterGraphics(MyEpub)
sbTraverseText
XhtmlHeader
dim document as object
dim dispatcher as object
Dim sXfer as string
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "URL"
args1(0).Value = MyEpub + "/OEBPS/text/content.temp"
args1(1).Name = "FilterName"
args1(1).Value = "Text"
dispatcher.executeDispatch(document, ".uno:SaveAs", "", 0, args1())
'------------ Split Content File in sections -------------
'----- The page break are marked by fnExportParaStyle ----
iSplitCount=0 'Sequential number of contentxxx.xhtml files
Open MyEpub + "/OEBPS/text/content.temp" For Input As #1
Open MyEpub + "/OEBPS/text/content" & right("000" & cStr(iSplitCount),3) & ".xhtml" For Output As #2
Do While not EOF (1)
Line Input #1, sXfer
Print #2, sXfer
if sXfer = "</html>" then '</html> is the magic word to split
Close #2
iSplitCount = iSplitCount + 1
Open MyEpub + "/OEBPS/text/content" & right("000" & cStr(iSplitCount),3) & ".xhtml" For Output As #2
end if
Loop
Close #1
Close #2
iSplitCount = iSplitCount - 1
End Sub
Sub CreateTocFile (MyEpub as string)
Open MyEpub + "/OEBPS/toc.ncx" For Output As #1
Print #1, "<?xml version=""1.0""?>"
Print #1, "<!DOCTYPE ncx PUBLIC ""-//NISO//DTD ncx 2005-1//EN"""
Print #1, " ""http://www.daisy.org/z3986/2005/ncx-2005-1.dtd"">"
Print #1, "<ncx xmlns=""http://www.daisy.org/z3986/2005/ncx/"" version=""2005-1"">"
Print #1, " <head>"
Print #1, " <meta name=""dtb:uid"" content=""" & MyUUIDv4 & """/>"
Print #1, " <meta name=""dtb:depth"" content=""1""/>"
Print #1, " <meta name=""dtb:totalPageCount"" content=""0""/>"
Print #1, " <meta name=""dtb:maxPageNumber"" content=""0""/>"
Print #1, " </head>"
Print #1, " <docTitle>"
Print #1, " <text>Unknown</text>"
Print #1, " </docTitle>"
Print #1, " <navMap>"
Print #1, " </navMap>"
Print #1, "</ncx>"
Close #1
End Sub
Sub CreateCSSFile (MyEpub as string)
'---- Create STYLESHEET.CSS file ----
Open MyEpub + "/OEBPS/styles/style001.css" For Output As #1
Print #1, " @namespace h ""http://www.w3.org/1999/xhtml"";"
Print #1, " @page { margin: 0.8em }"
' Print #1, " body"
' Print #1, " {margin-right: 3%;"
' Print #1, " margin-left: 3%;"
' Print #1, " }"
Print #1, " h1"
Print #1, " {margin-top:4em;"
Print #1, " margin-bottom:1.5em;"
Print #1, " page-break-after:avoid;"
Print #1, " font-size:1.2em;"
Print #1, " font-family: Georgia, Garamond, serif;"
Print #1, " text-align: center;"
Print #1, " color:#000000;"
Print #1, " }"
Print #1, " h2"
Print #1, " {margin-top:3em;"
Print #1, " margin-right:0em;"
Print #1, " margin-bottom:2em;"
Print #1, " margin-left:0em;"
Print #1, " page-break-after:avoid;"
Print #1, " font-size:1em;"
Print #1, " font-family: Georgia, Garamond, serif;"
Print #1, " text-align: center;"
Print #1, " color:#000000;"
Print #1, " }"
Print #1, " h3"
Print #1, " {margin-top:2em;"
Print #1, " margin-bottom:2em;"
Print #1, " line-height:normal;"
Print #1, " page-break-after:avoid;"
Print #1, " font-size:0.9em;"
Print #1, " font-family: Georgia, Garamond, serif;"
Print #1, " text-align: center;"
Print #1, " color:#000000;"
Print #1, " }"
Print #1, " p"
Print #1, " {margin:0pt;"
Print #1, " text-indent:1em;"
Print #1, " font-family: Georgia, Garamond, serif;"
Print #1, " text-align: justify;"
Print #1, " color:#000000;"
Print #1, " }"
Print #1, " div.center"
Print #1, " {text-align: center"
Print #1, " }"
Print #1, " div.right"
Print #1, " {text-align: right"
Print #1, " }"
Print #1, " a"
Print #1, " {color:#000000;"
Print #1, " text-decoration: underline"
Print #1, " }"
Print #1, " span.normal {font-style: normal;}"
Print #1, " span.linet {text-decoration: line-through}"
Print #1, " span.underline {text-decoration: underline}"
Close #1
End Sub
Sub CreateContentOpfFile (MyEpub as string)
'---- Create CONTENT.OPF file ----
Dim i as Integer
Dim FileName, FileType as String
Dim oDeskTop as object
oDeskTop=CreateUnoService("com.sun.star.frame.Desktop")
Open MyEpub + "/OEBPS/content.opf" For Output As #1
Print #1, "<?xml version=""1.0"" encoding=""UTF-8""?>"
Print #1, "<package xmlns=""http://www.idpf.org/2007/opf"" unique-identifier=""BookID"" version=""2.0"">"
Print #1, " <metadata xmlns:dc=""http://purl.org/dc/elements/1.1/"" xmlns:opf=""http://www.idpf.org/2007/opf"">"
Print #1, " <dc:identifier id=""BookID"" opf:scheme=""UUID"">" & myUUIDv4 & "</dc:identifier>"
Print #1, " <meta name=""writer2epub"" content=""" & sVersion & """/>"
Print #1, " </metadata>"
Print #1, " <manifest>"
Print #1, " <item id=""ncx"" href=""toc.ncx"" media-type=""application/x-dtbncx+xml""/>"
For i=1 to iSplitCount
Print #1, " <item id=""content" & right("000" & cStr(i),3) & ".xhtml"" href=""text/content" & right("000" & cStr(i),3) & ".xhtml"" media-type=""application/xhtml+xml""/>"
Next i
Print #1, " <item id=""style001.css"" href=""styles/style001.css"" media-type=""text/css""/>"
Print #1, " </manifest>"
Print #1, " <spine toc=""ncx"">"
For i=1 to iSplitCount
Print #1, " <itemref idref=""content" & right("000" & cStr(i),3) & ".xhtml""/>"
Next i
If FileExists(MyEpub & "/OEBPS/images/") Then
FileName=Dir(MyEpub & "/OEBPS/images/")
Do While FileName <> ""
Select Case right (FileName, 4)
Case ".png"
FileType = "png"
Case ".gif"
FileType = "gif"
Case ".jpg"
FileType = "jpeg"
Case "jpeg"
FileType = "jpeg"
Case "svg"
FileType = "svg+html"
Case else
msgbox "image file " & FileName & " NOT SUPPORT BY EPUB!" & chr(13) & "Only .jpeg, .png, .gif and .svg allowed"
End Select
Print #1, " <item id=""" & FileName & """ href=""images/" & FileName & """ media-type=""image/" & FileType & """/>"
FileName=dir()
Loop
End If
Print #1, " </spine>"
Print #1, " <guide>"
Print #1, " <reference type=""cover"" title=""Cover Page"" href=""text/content001.xhtml""/>"
Print #1, " </guide>"
Print #1, "</package>"
Close #1
End Sub
Sub CleanFiles (MyEpub as string)
'------- this routine is requested to remove the extra unwantend split at the beginning and the end -----
If FileExists(MyEpub & "/OEBPS/text/content000.xhtml") Then
Kill (MyEpub & "/OEBPS/text/content000.xhtml")
End If
If FileExists(MyEpub & "/OEBPS/text/content" & right("000" & cStr(iSplitCount+1),3) & ".xhtml") Then
Kill (MyEpub & "/OEBPS/text/content" & right("000" & cStr(iSplitCount+1),3) & ".xhtml")
End If
'------------------------------------------------------------------------
If FileExists(MyEpub & "/OEBPS/text/content.temp") Then
Kill (MyEpub & "/OEBPS/text/content.temp") ' remove temporary file
End If
End Sub
Sub CreateEpub(MyEpub as String)
Dim sFileToZipUrl As String
Dim sZipPackageUrl As String
sFileToZipUrl = ConvertToUrl( MyEpub)
sZipPackageUrl = ConvertToUrl( MyEpub & ".epub" )
ZipFolder(sFileToZipUrl, sZipPackageUrl )
'RmDir sFileToZipUrl
End sub
Sub EditMacros 'Opens the macro editor ###### DEVELOPER USE ONLY! #######
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(document, ".uno:MacroDialog", "", 0, Array())
End Sub
Sub ErrorHandler
msgbox ("Error # " & err & " at line " & erl & chr(13) & error, 16, "Writer to ePub")
fenDoc.Enable = True
oDoc.unlockControllers
End Sub
Sub XSLTransform (MyEpub)
rem -------------------------------------------------------
rem - Get access to the document
dim document as object
document = ThisComponent
rem -------------------------------------------------------
rem - Init export URL
dim xmlurl as string
xmlurl = MyEpub & "/OEBPS/text/content001.xhtml"
iSplitCount=1
rem -------------------------------------------------------
rem - Export payments
dim properties(5) as new com.sun.star.beans.PropertyValue
properties(0).Name = "FilterName"
properties(0).Value = "XHTML Writer File"'"epub_export"
'properties(1).Name = "URL"
'properties(1).Value = "2008-01-01;hol.sten"
properties(1).Value = xmlurl
'msgbox xmlurl
document.storeToURL(xmlurl, properties())
End Sub
|