Converting of MS Word reports and Excel spreadsheets to PDF format in C#

Article from our customer

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 UseOffice .Net, 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 UseOffice .Net, 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();

Get other details you may at SautinSoft company website: http://www.sautinsoft.com

James Omveri


Share on Facebook

Leave a Comment

Your email address will not be published.