Convert MS Office Files to PDFs in C#

The GdPictureDocumentConverter class is a quick and easy one-step operation for converting Word (DOCX and DOC), Excel (XLSX and XLS), and PowerPoint (PPTX and PPT) files into PDF or PDF/A. You can also choose the PDF conformance level you require.

Here’s the code for converting files to PDF:

// We assume GdPicture has been correctly installed and unlocked.
using (GdPictureDocumentConverter oConverter = new GdPictureDocumentConverter())
{
    // Select your source document and its document format (DOCX, DOC, XLSX, XLS, PPTX, PPT).
    GdPictureStatus status = oConverter.LoadFromFile("input.docx", GdPicture14.DocumentFormat.DocumentFormatDOCX);
    if (status == GdPictureStatus.OK)
    {
        MessageBox.Show("The file has been loaded successfully.", "Conversion to PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Information);
        // Select the conformance of the resulting PDF document.
        status = oConverter.SaveAsPDF("output.pdf", PdfConformance.PDF);
        if (status == GdPictureStatus.OK)
        {
            MessageBox.Show("The file has been saved successfully.", "Conversion to PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        else
        {
            MessageBox.Show("The file has failed to save. Status: " + status.ToString(), "Conversion to PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }
    else
    {
        MessageBox.Show("The file has failed to load. Status: " + status.ToString(), "Conversion to PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
}
'We assume GdPicture has been correctly installed and unlocked.
Using oConverter As GdPictureDocumentConverter = New GdPictureDocumentConverter()
    'Select your source document and its document format (DOCX, DOC, XLSX, XLS, PPTX, PPT).
    Dim status As GdPictureStatus = oConverter.LoadFromFile("input.docx", GdPicture14.DocumentFormat.DocumentFormatDOCX)
    If status = GdPictureStatus.OK Then
        MessageBox.Show("The file has been loaded successfully.", "Conversion to PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Information)
        'Select the conformance of the resulting PDF document.
        status = oConverter.SaveAsPDF("output.pdf", PdfConformance.PDF)
        If status = GdPictureStatus.OK Then
            MessageBox.Show("The file has been saved successfully.", "Conversion to PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Else
            MessageBox.Show("The file has failed to save. Status: " + status.ToString(), "Conversion to PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
    Else
        MessageBox.Show("The file has failed to load. Status: " + status.ToString(), "Conversion to PDF Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End If
End Using