简体   繁体   中英

How to convert doc to pdf using LibreOffice and C#

The string that I'm using to convert the documents is as below. I'm not sure if it's a problem with the parameters passed to soffice.

soffice --convert-to pdf --outdir C:\\test\\NPP\\LOTestOutputs\\ C:\\test\\NPP\\MBI_CONVERSION_PRESETS.docx

Also tried:

soffice --convert-to pdf C:\\test\\NPP\\MBI_CONVERSION_PRESETS.docx --outdir C:\\test\\NPP\\LOTestOutputs\\

And this is passed to a code in c# which starts a process and executes the arguments passed to it. The problem is that the process waits endlessly at proc.WaitForExit() . I was able to execute a simpler command [soffice --convert-to pdf MBI_CONVERSION_PRESETS.docx] from the cmd prompt

..some more code above related to process init
proc.Start();
proc.BeginOutputReadLine();
proc.BeginErrorReadLine();
proc.WaitForExit();

I referred to a similar problem on Stackoverflow And I checked that my user account has administrator rights. And I am not sure why I cannot convert the document using libreoffice.

The libreoffice version : 5.4

Hoping to get some tips on stackoverflow. Please let me know if you need any info regarding my tests.

EDIT 2: the error read from the stream

{Error: Please verify input parameters... (SfxBaseModel::impl_store <C:\test\NPP\LOTestOutputs" -env:OOO_CWD=2C:\\Users\\dev\\source\\repos\\Converstion\\TestClass\\bin\\Debug/MBI_CONVERSION_PRESETS.pdf> failed: 0x81a)}

The output path was the main culprit here. The directory shouldn't contain the trailing backslash. I posted the same question on a different website and got the answer. The dev team might come up with a fix for the trailing backslash.

Link to the answer shared here for more reference.

Thanks everyone!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM