A commonly encountered scenario involves converting an entire PDF document or specific pages into a collection of images. GroupDocs.Conversion for .NET offers the capability to convert PDFs into various image formats, such as TIFF, JPG, PNG, GIF, BMP, and more.
Unlike other conversions, this process requires the declaration of a SavePageStream delegate, which specifies the naming format for the saved images. You can select your preferred image format using the ImageFileType class.
Convert PDF to PNG in C#
using GroupDocs.Conversion;
using GroupDocs.Conversion.FileTypes;
using GroupDocs.Conversion.Options.Convert;
// Load the source PDF file
using (var converter = new Converter("resume.pdf"))
{
var getPageStream = (int page) => File.Create($"resume-page-{page}.png");
// Set the convert options and specify the output image type
var convertOptions = new ImageConvertOptions {
Format = ImageFileType.Png
};
// Convert each page of PDF document to PNG
converter.Convert(getPageStream, convertOptions);
}
With GroupDocs.Conversion for .NET, you can effortlessly convert specific pages from a lengthy document.
You have two methods to accomplish this, depending on your requirements. You can either convert a range of pages or convert specific pages.
Convert DOCX (pages 2-4) to PDF in C#
using GroupDocs.Conversion;
using GroupDocs.Conversion.Options.Convert;
// Load the source DOCX file
using (Converter converter = new Converter("booklet.docx"))
{
// Set the options and specify the range of pages to convert
var convertOptions = new PdfConvertOptions
{
PageNumber = 2,
PagesCount = 3
};
// Convert pages 2-4 to PDF
converter.Convert("pages-2-4.pdf", convertOptions);
}
Fluent syntax offers a concise notation for common actions within the GroupDocs.Conversion for .NET API.
The code samples below demonstrate how to leverage the fluent syntax:
Convert DOCX to PDF in C# using fluent syntax
using GroupDocs.Conversion;
FluentConverter
.Load("schedule.docx")
.ConvertTo("schedule.pdf")
.Convert();