# Feature Request: Save as Text with line breaks

It should be possible to save a document (Writer; .odt) as Text such that the text file looks (as much as possible) like the document looked on the screen, or would have looked if printed. It may be that the only difference between what I currently get from "Save as..." Text, and what I want, is a hard line break at the end of every line that appears on the screen: I don't want each paragraph to be an arbitrarily long line in the text file, I want it to appear as a sequence of lines, broken exactly as they appeared when I was editing the document.

edit retag close merge delete

And what is your goal? Why not save to PDF?

( 2017-11-08 07:27:51 +0200 )edit

Sort by » oldest newest most voted

Hello @Jay Michael,

you could use the XLineCursor interface for this, for example just run the following method:

Sub Writer_Save_As_Text_With_LineBreaks( Optional oDoc as Object )
REM Exports Writer text lines to a text file.
REM The output file will be located in the same folder as the Writer document, or in the current directory.
REM <oDoc>  : [OPTIONAL] The Writer document whose lines to export; Default = current document.
If IsMissing( oDoc ) Then oDoc = ThisComponent
If oDoc.supportsService( "com.sun.star.text.TextDocument" ) Then

Dim strPath As String
If oDoc.hasLocation() Then
strPath = oDoc.getLocation() & ".txt"
Else
strPath = curDir() & getPathSeparator() & oDoc.getTitle() & ".txt"
End If

Dim iOutputFile As Integer
iOutputFile = Freefile()
Open strPath For Output As #iOutputFile

Dim oViewCursor as Object
oViewCursor = oDoc.CurrentController.getViewCursor()
oViewCursor.gotoStart( False )

Do
oViewCursor.gotoStartOfLine( False )
oViewCursor.gotoEndOfLine( True )
Print #iOutputFile, oViewCursor.getString()
Loop While oViewCursor.goRight( 1, False )

Close #iOutputFile

End If
End Sub

more

I appreciate the effort you put into giving me a solution, but I'm not looking for help post-processing what LibreOffice currently produces. I thought this was the site to post a request for a new feature.

Should I be on another web site?

( 2017-11-12 02:21:45 +0200 )edit
( 2017-11-12 07:02:30 +0200 )edit

In fact you want to go back to your old typewriter. The paragraph end, coded by typing [Enter] seems to give you a carriage return and line feed, but it signals the end of a paragraph, so I would not use it for anything else.

There is a solution though. You can use a 'soft return' by typing [Shift]+[Enter], this generates also a visible carriage return and line feed, but without the function of 'end of paragraph. This method will also work in many other editors.

Main question remains: Why do you want this. Copy send to printer or other editors will be stripped of this extra coding, and it will not be for free.

more