Skip to content

Instantly share code, notes, and snippets.

@aspose-net
Created June 26, 2025 07:44
Show Gist options
  • Save aspose-net/502177d1330254280980ce663be21fb2 to your computer and use it in GitHub Desktop.
Save aspose-net/502177d1330254280980ce663be21fb2 to your computer and use it in GitHub Desktop.
C# code snippets for blog post: Efficient PDF to Word and Excel Conversion with Aspose.PDF Doc Converter for .NET (Aspose.PDF API)

Aspose.PDF C# Code Snippets for PDF to Word and Excel Conversion

This GitHub Gist contains a collection of C# code snippets demonstrating the efficient conversion of PDF documents to Microsoft Word (DOCX) and Excel (XLSX) files using the Aspose.PDF plugin family. These examples are based on the blog post titled "Efficient PDF to Word and Excel Conversion with Aspose.PDF Doc Converter for .NET".

The code snippets provided here showcase various aspects of working with Aspose.PDF, such as loading a PDF document, configuring conversion options, and saving the resulting Word or Excel file. By using these examples, you can quickly understand how to integrate Aspose.PDF into your own .NET applications for seamless PDF manipulation and conversion tasks.

For more detailed information about Aspose.PDF and its capabilities, please refer to the Aspose Knowledge Base article. If you have any questions or need further assistance, feel free to reach out to our support team. Happy coding!

using Aspose.Pdf;
using Aspose.Pdf.SaveOptions;
using System.IO;
public class BatchPdfToDocxConversion
{
public static void ConvertMultiplePdfsToDocx(string inputDirectory, string outputDirectory)
{
// Directory containing source PDF documents
DirectoryInfo dir = new DirectoryInfo(inputDirectory);
FileInfo[] files = dir.GetFiles("*.pdf");
foreach (FileInfo file in files)
{
// Load the source PDF document
Document pdfDoc = new Document(file.FullName);
// Create an instance of DocSaveOptions for DOCX conversion
DocSaveOptions options = new DocSaveOptions(SaveFormat.Docx);
// Save the converted document as DOCX
string outputFileName = Path.Combine(outputDirectory, file.Name.Replace(".pdf", ".docx"));
pdfDoc.Save(outputFileName, options);
}
Console.WriteLine("Batch conversion completed.");
}
}
using Aspose.Pdf;
using Aspose.Pdf.SaveOptions;
public class ComplexDocumentConversion
{
public static void ConvertComplexPdfToDocx(string inputFilePath, string outputFilePath)
{
// Load the source PDF document
Document pdfDoc = new Document(inputFilePath);
// Create an instance of DocSaveOptions for DOCX conversion
DocSaveOptions options = new DocSaveOptions(SaveFormat.Docx);
// Save the converted document as DOCX
pdfDoc.Save(outputFilePath, options);
Console.WriteLine("Complex document saved successfully.");
}
}
using Aspose.Pdf;
using Aspose.Pdf.SaveOptions;
public class CustomizedDocxConversion
{
public static void ConvertPdfToDocxWithCustomSettings(string inputFilePath, string outputFilePath)
{
// Load the source PDF document
Document pdfDoc = new Document(inputFilePath);
// Create an instance of DocSaveOptions for DOCX conversion with customized settings
DocSaveOptions options = new DocSaveOptions(SaveFormat.Docx);
options.ImageResolution = 300; // Set image resolution to 300 DPI
options.TextAlignment = TextAlignment.Center; // Center-align text in the output document
// Save the converted document as DOCX with customized settings
pdfDoc.Save(outputFilePath, options);
Console.WriteLine("Document saved successfully.");
}
}
using Aspose.Pdf;
public class LicenseSetup
{
public static void SetAsposePdfMeteredLicense()
{
// Set your metered key here
string publicKey = "your-public-key";
string privateKey = "your-private-key";
// Initialize the Metered object with the provided keys
Metered meter = new Metered();
meter.SetMeteredKey(publicKey, privateKey);
Console.WriteLine("License set successfully.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment