Is it at all possible to convert a document to PDF or edit a PDF in C# using only free software?

一个人想着一个人 提交于 2019-12-06 06:31:21

I have a solution. I'm not saying it's the best solution. LibreOffice (or possibly OpenOffice if you are so inclined) accepts command line arguments that will do the switch.

soffice.exe --headless --convert-to pdf mockup.odt

*note - this is after I added libreoffice to my path (C:\Program Files\LibreOffice\program). idk why it's called soffice.exe instead of libreoffice.exe.

I might have a working solution for you, if you have stuck with the docx-file for the template. I found one free solution for docx to pdf converting, without using microsoft.interop, etc.: See first answer in this stack overflow post

It uses two tools: The open xml power tools and DinkToPdf (Which is essentially a wkhtmltopdf wrapper). The html to pdf part works just fine, but the docx to html part looks like a catastrophe at first. You can fix this with custom css (There are some resources online).

Powertools-.NetStandard

DinkToPdf-GitHub

There are more possibilities for proprietary software, like Asposes.Words and Syncfusion file-formats. Most of the proprietary solutions are pretty expensive...

If you are just working on a Windows Environment, where MS-Office is installed, you can use Microsoft.Interop. It is by far the easiest solution (In this post, Interop is mentioned several time Stackoverflow Word to PDF

If you found another (better) working solution, please let me know. I am still have not decided if I will use a proprietary or the free one. :-)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!