none
Convert ppt,pptx,xls,doc to pdf RRS feed

  • Question

  • How to convert ppt,doc ,xls or etc. to pdf.

    Please provide one sample regarding this which contains all logic about this

    • Moved by Fred Bao Friday, May 29, 2015 5:04 AM Office Develop Related
    Thursday, May 28, 2015 12:38 PM

Answers

  • Hi,
    >>How to convert ppt,doc ,xls or etc. to pdf.
    Please provide one sample regarding this which contains all logic about this.

    You may convert the files to pdf file by judging the format of the file and convert the file to PDF format which is selected in an Application.FileDialog(msoFileDialogFilePicker) box. While the file is open, then convert the file to PDF files by different API .The following code provide a sample to convert files(dox, xls, ppt) to PDF,while you click the button on the worksheet and select files, it will convert the file to PDF by the judging the file format, it could be a reference that you can refer to and adapt it. You can download the sample file here. http://1drv.ms/1dbcU8Y

    Sub Button1_Click()
    Dim fd As FileDialog
    Dim app As Object
    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    fd.Title = "Please choose a file"
    fd.Filters.Clear
    fd.Filters.Add "Office file", "*.doc;*.xls;*.ppt"
    fd.Show
    'path of the file
    Filename = fd.SelectedItems(1)
    'filename
    strFileName = Right$(Filename, Len(Filename) - InStrRev(Filename, "\"))
    Dim str() As String
     str = Split(strFileName, ".")
    ExtendFormat = str(1)
    'pdf filename
    PDFName = "D:\PDF\" & str(0) & ".pdf"
    Select Case ExtendFormat
    Case "xls"
    
    Workbooks.Open (Filename)
    Workbooks(strFileName).ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDFName
    
    Case "doc"
    Set app = CreateObject("Word.Application")
    app.Documents.Open (Filename)
    app.Documents(strFileName).ExportAsFixedFormat OutputFileName:=PDFName, ExportFormat:=wdExportFormatPDF
    
    Case "ppt"
     Set app = CreateObject("PowerPoint.Application")
     app.Visible = True
     app.Presentations.Open Filename, msoFalse
     Dim ppt As PowerPoint.Presentation
     Set ppt = app.Presentations(strFileName)
     ppt.ExportAsFixedFormat PDFName, ppFixedFormatTypePDF
    
    Case Else
    End Select
     MsgBox "done"
    
    End Sub

    Hope this could help you

    Best Regards

    Lan


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, June 2, 2015 5:30 AM
    Moderator

All replies

    • Edited by Zorro14 Thursday, May 28, 2015 12:50 PM
    Thursday, May 28, 2015 12:46 PM
  • Hi,
    >>How to convert ppt,doc ,xls or etc. to pdf.
    Please provide one sample regarding this which contains all logic about this.

    You may convert the files to pdf file by judging the format of the file and convert the file to PDF format which is selected in an Application.FileDialog(msoFileDialogFilePicker) box. While the file is open, then convert the file to PDF files by different API .The following code provide a sample to convert files(dox, xls, ppt) to PDF,while you click the button on the worksheet and select files, it will convert the file to PDF by the judging the file format, it could be a reference that you can refer to and adapt it. You can download the sample file here. http://1drv.ms/1dbcU8Y

    Sub Button1_Click()
    Dim fd As FileDialog
    Dim app As Object
    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    fd.Title = "Please choose a file"
    fd.Filters.Clear
    fd.Filters.Add "Office file", "*.doc;*.xls;*.ppt"
    fd.Show
    'path of the file
    Filename = fd.SelectedItems(1)
    'filename
    strFileName = Right$(Filename, Len(Filename) - InStrRev(Filename, "\"))
    Dim str() As String
     str = Split(strFileName, ".")
    ExtendFormat = str(1)
    'pdf filename
    PDFName = "D:\PDF\" & str(0) & ".pdf"
    Select Case ExtendFormat
    Case "xls"
    
    Workbooks.Open (Filename)
    Workbooks(strFileName).ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDFName
    
    Case "doc"
    Set app = CreateObject("Word.Application")
    app.Documents.Open (Filename)
    app.Documents(strFileName).ExportAsFixedFormat OutputFileName:=PDFName, ExportFormat:=wdExportFormatPDF
    
    Case "ppt"
     Set app = CreateObject("PowerPoint.Application")
     app.Visible = True
     app.Presentations.Open Filename, msoFalse
     Dim ppt As PowerPoint.Presentation
     Set ppt = app.Presentations(strFileName)
     ppt.ExportAsFixedFormat PDFName, ppFixedFormatTypePDF
    
    Case Else
    End Select
     MsgBox "done"
    
    End Sub

    Hope this could help you

    Best Regards

    Lan


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, June 2, 2015 5:30 AM
    Moderator
  • Hi, you could use a .NET Office library (https://officeapi.codeplex.com/) to achieve this kind of task easily, which does not require MS Office to be installed.

    PPT to PDF

    Presentation presentation = new Presentation();
    presentation.LoadFromFile("ppt.ppt");
    
    //save the PPT to PDF file format
    presentation.SaveToFile("ToPdf.pdf", FileFormat.PDF);
    

    Doc to PDF

    Document document = new Document();

    document.LoadFromFile(@"E:\work\documents\TestSample.docx"); //Convert Word to PDF document.SaveToFile("toPDF.PDF", FileFormat.PDF);

    Excel to PDF

    // load Excel file
    Workbook workbook = new Workbook();
    workbook.LoadFromFile("D:\\test.xlsx");
     
    // Set PDF template
    PdfDocument pdfDocument = new PdfDocument();
    pdfDocument.PageSettings.Orientation = PdfPageOrientation.Landscape;
    pdfDocument.PageSettings.Width = 970;
    pdfDocument.PageSettings.Height = 850;
    
    //Convert Excel to PDF using the template above
    PdfConverter pdfConverter = new PdfConverter(workbook);
    PdfConverterSettings settings = new PdfConverterSettings();
    settings.TemplateDocument = pdfDocument;
    pdfDocument = pdfConverter.Convert(settings);
    
    // Save and preview PDF
    pdfDocument.SaveToFile("sample.pdf");

    Tuesday, December 29, 2015 3:05 AM
  • The following articles demonstrate a straightforward convertion, you just load and save them:

    Wednesday, May 4, 2016 11:20 AM