Last active
December 18, 2023 06:10
-
-
Save Al-Muhandis/0ac9c8f1c338a9837b254851be9b3f2f to your computer and use it in GitHub Desktop.
simple method to export from odt/doc to pdf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unit odt_2_pdf; | |
{$mode ObjFPC}{$H+} | |
interface | |
uses | |
Classes, SysUtils; | |
function ConvertODT2Pdf(const aSrcODT, aOutDir: String): Boolean; | |
implementation | |
uses | |
process | |
; | |
const | |
_PathToSOffice={$IFDEF MSWINDOWS}'C:\Program Files\LibreOffice\program\soffice.exe'{$ELSE}'soffice'{$ENDIF}; | |
function ConvertODT2Pdf(const aSrcODT, aOutDir: String): Boolean; | |
var | |
aProcess: TProcess; | |
begin | |
Result:=False; | |
aProcess := TProcess.Create(nil); | |
with aProcess do | |
begin | |
try | |
Executable := _PathToSOffice; | |
Parameters.Add('--headless'); | |
Parameters.Add('--convert-to'); | |
Parameters.Add('pdf'); | |
Parameters.Add(aSrcODT); | |
if not aOutDir.IsEmpty then | |
begin | |
Parameters.Add('--outdir'); | |
Parameters.Add(aOutDir); | |
end; | |
Parameters.Add(aSrcODT); | |
Options := Options + [poWaitOnExit]; | |
Execute; | |
Result:=True; | |
finally | |
Free; | |
end; | |
end; | |
end; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment