@@ -23,7 +23,7 @@ function windows(inputPath, outputPath, keepActive) {
2323 execSync ( command ) ;
2424 }
2525
26- // New PDF to DOCX conversion functions for Windows and macOS hell yeahhh
26+ // New PDF to DOCX conversion functions for Windows hell yeahhh
2727function windowsPdfToDocx ( inputPath , outputPath , keepActive = false ) {
2828 if ( ! inputPath ) {
2929 console . error ( 'Input path is not provided.' ) ;
@@ -40,6 +40,23 @@ function windowsPdfToDocx(inputPath, outputPath, keepActive = false) {
4040}
4141
4242
43+ /*
44+ Linux specific function
45+ */
46+
47+ function linux ( inputPath , outputPath , keepActive ) {
48+ if ( ! inputPath ) {
49+ console . error ( 'Input path is not provided.' ) ;
50+ return ;
51+ }
52+
53+ const inputFilePath = path . resolve ( inputPath ) ;
54+ const outputFilePath = outputPath ? path . resolve ( outputPath ) : `${ inputFilePath } .pdf` ;
55+ const command = `libreoffice --headless --convert-to pdf "${ inputFilePath } " --outdir "${ path . dirname ( outputFilePath ) } "` ;
56+ execSync ( command ) ;
57+
58+ }
59+
4360/**
4461 * Resolve input and output paths
4562 */
@@ -117,9 +134,13 @@ function macos(inputPath, outputPath, keepActive) {
117134 */
118135function convert ( inputPath , outputPath , keepActive = false ) {
119136 if ( process . platform === 'darwin' ) {
120- macos ( inputPath , outputPath , keepActive ) ;
137+ macos ( inputPath , outputPath , keepActive ) ;
138+ } else if ( process . platform === 'win32' ) {
139+ windows ( inputPath , outputPath , keepActive ) ;
140+ } else if ( process . platform === 'linux' ) {
141+ linux ( inputPath , outputPath , keepActive ) ;
121142 } else {
122- windows ( inputPath , outputPath , keepActive ) ;
143+ console . error ( 'Unsupported platform:' , process . platform ) ;
123144 }
124145}
125146
@@ -129,6 +150,7 @@ module.exports = {
129150 windows,
130151 windowsPdfToDocx,
131152 macos,
153+ linux,
132154 packageVersion,
133155 } ;
134156
0 commit comments