Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Fri Apr 06, 2018 4:25 pm

is there a catch all office file converter to pdf? say I have users that will upload ms word, excel and powerpoint files, is there existing functionality to automatically pass that into a document object which then converts and saves it into a pdf?

right now from what I can understand, I would need to download each Spire.Doc, Spire.XLS, and Spire.Presentation. Reference each in my project, then check file type on upload, and call the document.SaveToFile(fileName, FileFormat.auto) for the appropriate Spirce.Doc, Spire.XLS, or Sprire.Presentation. Is this correct? Or is there an existing easier way?

lle
 
Posts: 2
Joined: Thu Apr 05, 2018 8:27 pm

Mon Apr 09, 2018 5:47 am

Hello,

Thank you for contacting us,
When using two or more products in a same project, you need to reference the corresponding dlls (for your case, please add Spire.Doc.dll Spire.Xls.dll Spire.Presentation.dll Spire.Pdf.dll Spire.Common.dll Spire.License.dll) from Spire.Office package (Spire.Office Platinum (DLL Only) Version:2.16.27). And as for your task, there is no easier way, you need to check uploaded file type and then pass corresponding object to save to PDF file. Example code shown as below.
Code: Select all
string OutPDF = "Result.Pdf";
switch(Path.GetExtension(fileName))
{
        case ".docx":
        case ".doc":
             Document doc = new Document();
             doc.LoadFromFile(fileName);
             doc.SaveToFile(OutPDF, Spire.Doc.FileFormat.PDF);
             break;
        case ".xlsx":
        case ".xls":
             Workbook wb = new Workbook();
             wb.LoadFromFile(fileName);
             wb.SaveToFile(OutPDF, Spire.Xls.FileFormat.PDF);
             break;
        case ".pptx":
        case ".ppt":
             Presentation ppt = new Presentation();
             ppt.LoadFromFile(fileName);
             ppt.SaveToFile(OutPDF, Spire.Presentation.FileFormat.PDF);
             break;
}


Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1385
Joined: Tue Sep 27, 2016 1:06 am

Mon Apr 09, 2018 6:16 pm

Thank you Nina

lle
 
Posts: 2
Joined: Thu Apr 05, 2018 8:27 pm

Tue Apr 10, 2018 1:28 am

Hi,

You're welcome.
If you need further assistance, please feel free to contact us. We will be happy to help you.

Sincerely,
Nina
E-iceblue support team
User avatar

Nina.Tang
 
Posts: 1385
Joined: Tue Sep 27, 2016 1:06 am

Return to Spire.PDF