Convert MS Office Files to PDFs in C#

GdPicture.NET SDK offers Office-to-PDF conversion that relies entirely on its own technology. The conversion doesn’t rely on third-party tools such as LibreOffice.

PSPDFKit SDKs are deployed in some of the world’s most popular applications, such as those made by Autodesk, Disney, UBS, Dropbox, IBM, and Lufthansa.

Key Capabilities

  • Word to PDF — Convert to PDF from Word

  • Excel to PDF — Convert to PDF from Excel

  • PowerPoint to PDF — Convert to PDF from PowerPoint

Guides for Office-to-PDF Conversion

Convert from Word to PDF
How to convert to PDF from Word

Convert from Excel to PDF
How to convert to PDF from Excel

Convert from PowerPoint to PDF
How to convert to PDF from PowerPoint

Free Trial

Enjoy unlimited trial usage of all our products. Get guidance and tech support from developers who built the product, and get started within minutes.

GdPicture.NET SDK offers Office-to-PDF conversion that relies entirely on its own technology. The conversion doesn’t rely on third-party tools such as LibreOffice.

This article explains how to convert Word files such as DOC or DOCX to PDF.

Creating a PDF from a Word File

To create a PDF from a Word file, follow these steps:

  1. Create a GdPictureDocumentConverter object.

  2. Load the source document by passing its path to the LoadFromFile method. Recommended: Specify the source document format with a member of the DocumentFormat enumeration.

  3. Save the output in a new PDF document with the SaveAsPDF method.

The example below creates a PDF document from a Word file:

using GdPictureDocumentConverter gdpictureDocumentConverter = new GdPictureDocumentConverter();
// Load the source document.
gdpictureDocumentConverter.LoadFromFile(@"C:\temp\source.docx", GdPicture14.DocumentFormat.DocumentFormatDOCX);
// Save the output in a new PDF document.
gdpictureDocumentConverter.SaveAsPDF(@"C:\temp\output.pdf");
Using gdpictureDocumentConverter As GdPictureDocumentConverter = New GdPictureDocumentConverter()
    ' Load the source document.
    gdpictureDocumentConverter.LoadFromFile("C:\temp\source.docx", GdPicture14.DocumentFormat.DocumentFormatDOCX)
    ' Save the output in a new PDF document.
    gdpictureDocumentConverter.SaveAsPDF("C:\temp\output.pdf")
End Using
Used Methods

Related Topics

Optional Configuration Properties

Optionally, configure the conversion with the following properties of the GdPictureDocumentConverter object:

  • PageRange specifies the pages included in the conversion. Use commas and hyphens to define the pattern. For example, "1,5,9-12" specifies pages 1, 5, 9, 10, 11, and 12.

  • TrackOfficeDocumentRevisions is a Boolean value that specifies whether to display Track Changes revisions in the output PDF file.

The example below creates a PDF document from a Word file with a custom configuration:

using GdPictureDocumentConverter gdpictureDocumentConverter = new GdPictureDocumentConverter();
// Load the source document.
gdpictureDocumentConverter.LoadFromFile(@"C:\temp\source.docx", GdPicture14.DocumentFormat.DocumentFormatDOCX);
// Configure the conversion.
gdpictureDocumentConverter.PageRange = "1,5,9-12";
// Save the output in a new PDF document.
gdpictureDocumentConverter.SaveAsPDF(@"C:\temp\output.pdf");
Using gdpictureDocumentConverter As GdPictureDocumentConverter = New GdPictureDocumentConverter()
    ' Load the source document.
    gdpictureDocumentConverter.LoadFromFile("C:\temp\source.docx", GdPicture14.DocumentFormat.DocumentFormatDOCX)
    ' Configure the conversion.
    gdpictureDocumentConverter.PageRange = "1,5,9-12"
    ' Save the output in a new PDF document.
    gdpictureDocumentConverter.SaveAsPDF("C:\temp\output.pdf")
End Using
Used Methods and Properties

Related Topics

GdPicture.NET SDK offers Office-to-PDF conversion that relies entirely on its own technology. The conversion doesn’t rely on third-party tools such as LibreOffice.

This article explains how to convert Excel files such as XLS or XLSX to PDF.

Creating a PDF from an Excel File

To create a PDF from an Excel file, follow these steps:

  1. Create a GdPictureDocumentConverter object.

  2. Load the source document by passing its path to the LoadFromFile method. Recommended: Specify the source document format with a member of the DocumentFormat enumeration.

  3. Save the output in a new PDF document with the SaveAsPDF method.

The example below creates a PDF document from an Excel file:

using GdPictureDocumentConverter gdpictureDocumentConverter = new GdPictureDocumentConverter();
// Load the source document.
gdpictureDocumentConverter.LoadFromFile(@"C:\temp\source.xlsx", GdPicture14.DocumentFormat.DocumentFormatXLSX);
// Save the output in a new PDF document.
gdpictureDocumentConverter.SaveAsPDF(@"C:\temp\output.pdf");
Using gdpictureDocumentConverter As GdPictureDocumentConverter = New GdPictureDocumentConverter()
    ' Load the source document.
    gdpictureDocumentConverter.LoadFromFile("C:\temp\source.xlsx", GdPicture14.DocumentFormat.DocumentFormatXLSX)
    ' Save the output in a new PDF document.
    gdpictureDocumentConverter.SaveAsPDF("C:\temp\output.pdf")
End Using
Used Methods

Related Topics

Optional Configuration Properties

Optionally, configure the conversion with the following properties of the GdPictureDocumentConverter object:

  • RenderSheetHeadersAndFooters is a Boolean value that specifies whether to display headers and footers in the output PDF file.

  • SplitExcelSheetsIntoPages is a Boolean value that specifies whether to display each sheet of the source Excel file on a separate page in the output PDF file.

The example below creates a PDF document from an Excel file with a custom configuration:

using GdPictureDocumentConverter gdpictureDocumentConverter = new GdPictureDocumentConverter();
// Load the source document.
gdpictureDocumentConverter.LoadFromFile(@"C:\temp\source.xlsx", GdPicture14.DocumentFormat.DocumentFormatXLSX);
// Configure the conversion.
gdpictureDocumentConverter.RenderSheetHeadersAndFooters = true;
gdpictureDocumentConverter.SplitExcelSheetsIntoPages = true;
// Save the output in a new PDF document.
gdpictureDocumentConverter.SaveAsPDF(@"C:\temp\output.pdf");
Using gdpictureDocumentConverter As GdPictureDocumentConverter = New GdPictureDocumentConverter()
    ' Load the source document.
    gdpictureDocumentConverter.LoadFromFile("C:\temp\source.xlsx", GdPicture14.DocumentFormat.DocumentFormatXLSX)
    ' Configure the conversion.
    gdpictureDocumentConverter.RenderSheetHeadersAndFooters = True
    gdpictureDocumentConverter.SplitExcelSheetsIntoPages = True
    ' Save the output in a new PDF document.
    gdpictureDocumentConverter.SaveAsPDF("C:\temp\output.pdf")
End Using
Used Methods and Properties

Related Topics

GdPicture.NET SDK offers Office-to-PDF conversion that relies entirely on its own technology. The conversion doesn’t rely on third-party tools such as LibreOffice.

This article explains how to convert PowerPoint files such as PPT or PPTX to PDF.

Creating a PDF from a PowerPoint File

To create a PDF from a PowerPoint file, follow these steps:

  1. Create a GdPictureDocumentConverter object.

  2. Load the source document by passing its path to the LoadFromFile method. Recommended: Specify the source document format with a member of the DocumentFormat enumeration.

  3. Save the output in a new PDF document with the SaveAsPDF method.

The example below creates a PDF document from a PowerPoint file:

using GdPictureDocumentConverter gdpictureDocumentConverter = new GdPictureDocumentConverter();
// Load the source document.
gdpictureDocumentConverter.LoadFromFile(@"C:\temp\source.pptx", GdPicture14.DocumentFormat.DocumentFormatPPTX);
// Save the output in a new PDF document.
gdpictureDocumentConverter.SaveAsPDF(@"C:\temp\output.pdf");
Using gdpictureDocumentConverter As GdPictureDocumentConverter = New GdPictureDocumentConverter()
    ' Load the source document.
    gdpictureDocumentConverter.LoadFromFile("C:\temp\source.pptx", GdPicture14.DocumentFormat.DocumentFormatPPTX)
    ' Save the output in a new PDF document.
    gdpictureDocumentConverter.SaveAsPDF("C:\temp\output.pdf")
End Using
Used Methods

Related Topics