PDF Format Converter via Python for .NET

Export PDF to Word, Excel, PowerPoint, Images, HTML and fixed-layout formats using Python for .NET

Overview

There are few cases when there is need to manipulate documents other then PDF while having the parsing data available in PDF formats. So for such applications there will be two scenarios either they add functionality of PDF parsing within their own solution or add the PDF conversion functionality to manipulate data as of supported formats. For the second scenario to convert PDF to Word, Excel, HTML, Images or any required format, implementing C# PDF reader and converter code within .NET based is simple. We are discussing here few cases so that programmers can modify these conversion code snippets as of their requirements.

PDF to Microsoft Word 2003-2019 Conversion

Example: C# Code for PDF to Word Conversion

import aspose.pdf as ap

input_pdf = DIR_INPUT + "sample.pdf"
output_pdf = DIR_OUTPUT + "convert_pdf_to_doc.doc"

// Load the source PDF File
document = ap.Document(input_pdf)

// Save using save options
// Create DocSaveOptions object
 save_options = ap.DocSaveOptions()
save_options.format = ap.DocSaveOptions.DocFormat.DOCX

// Set the recognition mode as Flow means Full recognition mode
save_options.mode = ap.DocSaveOptions.RecognitionMode.FLOW

// Other two modes are RecognitionMode.Textbox and RecognitionMode.EnhancedFlow

// Set the Horizontal proximity as 2.5
save_options.relative_horizontal_proximity = 2.5

// Enable the value to recognize bullets during conversion process
save_options.recognize_bullets = True

// Save the resultant DOC file
document.save(output_pdf, save_options)

Aspose.PDF for .NET library supports all PDF to Word conversions. In case we are just converting Microsoft Word documents without any special settings, we just load the PDF file using the Save method from the Document class and will use with output Word document path and SaveFormat as parameters. For the special cases where there is a need to enhance the lines distance, image resolution, and more settings, API has DocSaveOptions class that exposes all such settings.

Save PDF as Excel Files

Save PDF as Excel Files

import aspose.pdf as ap

input_pdf = DIR_INPUT + "sample.pdf"
output_pdf = DIR_OUTPUT + "convert_pdf_to_excel.xlsx"
// Load PDF document
document = ap.Document(input_pdf)
// Initialize ExcelSaveOptions
save_option = ap.ExcelSaveOptions()
// Set output Excel XLSX format
save_option.format = ap.ExcelSaveOptions.ExcelFormat.XLSX
// Minimize number of Worksheets
save_option.minimize_the_number_of_worksheets = True
// Convert PDF to Excel output file
document.save(output_pdf, save_option)

Specialized SaveFormat.Excel Enumeration available for saving PDF to specific Microsoft Excel XLS XLSX output formats. Moreover, .NET PDF Library also have a speicific ExcelSaveOptions class that not only deals saving to Excel formats but also provides different functions and properties for setting different attributes like exact output format, minimize number of worksheets and more.

Convert PDF to PowerPoint Presentations

Example: C# Code PDF to PowerPoint Conversion

import aspose.pdf as ap

input_pdf = DIR_INPUT + "sample.pdf"
output_pdf = DIR_OUTPUT + "convert_pdf_to_pptx.pptx
// Load PDF document
document = ap.Document(input_pdf)
save_option = ap.PptxSaveOptions()
save_option.slides_as_images = True
// Save output file
document.save(output_pdf, save_option)

.NET PDF API supports converting PDF pages to PowerPoint Presentation Slides with selectable text or images by rendering slides as images. Pattern of saving Portable Document Format to PowerPoint is almost same, Loading the file using Document class and then calling the Save method with output file path and SaveFormat as parameters. In case of rendering with special presentation options, Programmers can use PptxSaveOptions class with any relevant specific rendering options. Calling the save method and passing the options as parameter.

Portable Document Format PDF to HTML Conversion

Example: C# Code for PDF to HTML Conversion

import aspose.pdf as ap

input_pdf = DIR_INPUT + "sample.pdf"
output_pdf = DIR_OUTPUT + "convert_pdf_to_html.html"

// Load source PDF document
document = ap.Document(input_pdf)

// Instantiate HTML Save options object
save_options = ap.HtmlSaveOptions()

// Enabling option to embed all resources inside the HTML
save_options.parts_embedding_mode = ap.HtmlSaveOptions.PartsEmbeddingModes.EMBED_ALL_INTO_HTML

// Specifying the separate folder for PDF to HTML with Images
save_options.special_folder_for_all_images = "ImagesFolder"

// Specifying the splitting option for the resultant HTML into multiple pages
save_options.split_into_pages = True

document.save(output_pdf, save_options)

PDF Parsing Library supports saving PDF to HTML as whole as well as with embedded resources including images. Procedure of conversion is same as PDF to other formats for generic cases, like loading the source document and calling the Save method with output HTML file path and SaveFormat.Html as parameters. In case of saving with embedded resources, there is a HtmlSaveOptions class having multiple options like saving images to a specific folder during the conversion, splitting the resultant HTML into multiple pages and more.

Convert PDF to Images

Example: C# Code for PDF to Images conversion

import aspose.pdf as ap

input_pdf = DIR_INPUT + "many_pages.pdf"
output_pdf = DIR_OUTPUT + "convert_pdf_to_jpeg"
imageStream = io.FileIO(output_pdf + "_page_1_out.jpeg", "x")

// Load document
document = ap.Document(input_pdf)

// Create Resolution object
resolution = ap.devices.Resolution(300)

// Create Image device with specified attributes
// Width, Height, Resolution
device = ap.devices.JpegDevice(resolution)
// For BMP, PNG, TIFF it will be BmpDevice, PngDevice, TiffDevice respectively

// Convert a particular page and save the image to stream
device.process(document.pages[i + 1], imageStream)

// Close stream
imageStream.close()

Converting PDF pages into images including PNG, JPEG, TIFF, BMP etc is easy within .NET based applications using code snippets listed below. Developers can loop through PDF pages after loading the file and convert Page by Page to required image format. Developers can set the horizental and vertical resolution of images using Resolution class