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.

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

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.

Hello @JayMichael,

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 https://ask.libreoffice.org/t/feature-request-save-as-text-with-line-breaks/28926
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

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?

Enhancement requests can be submitted here: http://www.libreoffice.org/get-help/bug/?enhancement=yes

(Redirects to https://bugs.documentfoundation.org// )