Converting of MS Word reports and Excel spreadsheets to PDF format in C#
Our organization has a legal department that works with a variety of documents: reports in DOC/DOCX, comparative tables in the XLS/XLSX format and various documents in RTF format.
Our lawyers often need to send these documents to our clients and partners around the world! Edit these documents and make changes is not desirable, and in some cases simply not acceptable!
We’ve decided to convert all of the documentation that is sent by e-mail to PDF. That is, all reports, spreadsheets, reports, etc. have to be converted to PDF and emailed to our partners. To convert DOC/DOCX/XLS/XLSX/RTF to PDF our developers found the UseOffice.Net component from the SautinSoft.
Below there is C# code to convert DOCX/XLSX to PDF:
SautinSoft.UseOffice converter = new SautinSoft.UseOffice();
string inputFilePath = @"E:\Web\DOC.docx";
string outputFilePath = @"E:\Web\DOC.pdf";
//Prepare SautinSoft.UseOffice, loads MS Word in memory
int ret = converter.InitWord();
if (ret==1)
return;
ret = converter.ConvertFile(inputFilePath, outputFilePath, SautinSoft.UseOffice.eDirection.DOCX_to_PDF);
//Release MS Word from memory
converter.CloseWord();
This is code snippet to export XLSX to PDF:
SautinSoft.UseOffice u = new SautinSoft.UseOffice();
string inputFilePath = @"E:\Excel1.xls";
string outputFilePath = @"E:\Result.pdf";
//Prepare SautinSoft.UseOffice, loads MS Excel in memory
int ret = u.InitExcel();
if (ret==1)
return;
ret = u.ConvertFile(inputFilePath, outputFilePath, SautinSoft.UseOffice.eDirection.XLS_to_PDF);
//Release MS Excel from memory
u.CloseExcel();
Если вам нужен пример кода или у вас есть вопрос: напишите нам по адресу support@sautinsoft.ru или спросите в онлайн-чате (правый нижний угол этой страницы) или используйте форму ниже: