Thank you for the options.
They all need installation.
I would like to use something that is already installed.
soffice, which is part of Libreoffice and part of the Manjaro installation, converts txt to pdf fine, I just don’t know how add the font size to the command line. I find it hard to believe that the developers of Libreoffice did not include an option for font size because they believe that anyone who wants to convert to pdf, all want the same font size. There must be a way to do this, but can’t find the answer on the internet.
It is - and so is vim and neovim.
From what I have seen: it would work exactly the same with vi as with nvim - as @Shirshendu posted.
You can use a simple commandline instead of the script as well, but the script is more versatile.
LibreOffice wasn’t built for command line usage for the most part, and the convert flag is primarily there so you can convert odf files (which are rich text, i.e. already have specified font sizes) to pdfs. The fact that it works on plain text files is just a bonus. So no, there are no command line options.
If you really must only use LibreOffice, you can acomplish what you want with a macro which you can just invoke from the command line similar to --convert-to.
The macro basically does this:
Opens the file with the given path
Selects all text
Sets font size to size specified in the argument
Exports file as pdf
Closes the file
e.g.
sub ToPDFWithFont (F as String, FSize as Integer)
rem F = "/tmp/test.txt"
TargetURL = convertToURL(F)
MyDoc = StarDesktop.loadComponentFromURL(TargetURL, "_blank", 0, Array())
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = MyDoc.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:SelectAll", "", 0, Array())
rem ----------------------------------------------------------------------
dim args2(2) as new com.sun.star.beans.PropertyValue
args2(0).Name = "FontHeight.Height"
args2(0).Value = FSize
args2(1).Name = "FontHeight.Prop"
args2(1).Value = 100
args2(2).Name = "FontHeight.Diff"
args2(2).Value = 0
dispatcher.executeDispatch(document, ".uno:FontHeight", "", 0, args2())
docURL=MyDoc.getURL()
docURLsplit = Split(docURL, ".")
docExt = docURLsplit(Ubound(docURLsplit))
pdfURL = Left(docURL, Len(docURL) - Len(docExt) -1) & ".pdf"
Dim storeArgs(0) As New com.sun.star.beans.PropertyValue
storeArgs(0).Name = "FilterName"
storeArgs(0).Value = "writer_pdf_Export"
MyDoc.storeToURL(pdfUrl, storeArgs())
MyDoc.close(True)
end sub
You should be able to just drop the above macro into your macros by going to Tools>Macros>Edit macros and pasting it in Module1 macro file under “My Macros and Dialogs”.
belyash, this is brilliant suggestion.
I followed your instructions and works fine from the terminal creating the .pdf file in the same folder as the .txt file.
Unfortunately, as I am trying to use it in a TCL script as:
exec libreoffice --headless ‘macro:///Standard.Module1.ToPDFWithFont($doc_name.txt, 10)’
Where doc_name evaluates to the text file location with no spaces.
It takes a little while like it was creating the pdf file but the file is not there. No error is produced. I cannot locate the resultant pdf file in any other folder either.
Maybe I need to start another post for this for an expert in tcl programming.
AFAIK my macro only works with an absolute path. I wrote it just for you and didn’t bother figuring out how to make relative paths work in OpenOffice/LibreOffice BASIC
I have a feeling $doc_name is probably not an absolute path and is causing your issue. LibreOffice won’t show any errors if running in headless mode without a GUI.
No, I assumed that absolute paths are required and $doc_name.txt evaluates to the absolute path of the text file. I don’t need relatives paths.
I didn’t know that about the headless mode without the GUI.
Then I’d suggest printing out the command which you are trying to exec in tcl and run it yourself in the command line without --headless and see if LibreOffice gives you any error pop ups with the GUI.
Running the script from inside the tcl script without the --headless gives the error as attached.
The .txt file shown is correct.
Also repeating what I stated before, running this in terminal works fine.
and treating the comma separated 'macro://string, 10' as an array it needs to append to the base path…
Maybe try making sure your Tcl is quoting the path with "? Otherwise, I think this has become more of a Tcl debugging question and you should start a new thread.
P.S.
Please copy text whenever possible instead of posting screenshots on the forum. Rules here: