Convert a PDF document to an image
Convert a PDF document into an output image suitable for a specific purpose, such as archiving, digital viewing, or faxing. The conversion profile can be adjusted to suit the specific requirements of the document workflow.
For more information about PDF to image conversion profiles, see Conversion profiles.
Steps to convert a document
- Reading the input document
- Selecting a conversion profile
- Adjusting the conversion profile
- Converting the document to an image
- Full example
You need to initialize the library.
Reading the input document
First you need to read the PDF document you want to convert. To do this, load the input document from the file system into a (read-only) PDF Document
.
This Document
can then later be passed to the Converter
.
- .NET
- Java
// Open image document
using var inStr = File.OpenRead(inPath);
using var inDoc = Document.Open(inStr);
// Open input document
FileStream inStr = new FileStream(inPath, FileStream.Mode.READ_ONLY);
com.pdftools.pdf.Document inDoc = com.pdftools.pdf.Document.open(inStr);
Selecting a conversion profile
You start the conversion process by creating a conversion Profile
object.
The Profile
object defines the parameters that are applied to the conversion process.
This example uses the Archive
profile, which is intended for document workflows that generate an output for archiving in TIFF image format.
- .NET
- Java
// Create a profile that defines the conversion parameters.
// The Archive profile converts PDF documents to TIFF images for archiving.
var profile = new Profiles.Archive();
// Create the profile that defines the conversion parameters.
// The Archive profile converts PDF documents to TIFF images for archiving.
Archive profile = new Archive();
Adjusting the conversion profile
The default conversion Profile
settings are sufficient for most document workflows.
If the document workflow has specific requirements (for example, the use of a specific compression algorithm), you can adjust the properties of the conversion Profile
directly.
For more information about PDF to image conversion profiles, see Conversion profiles.
Converting the document to an image
After creating the Profile
object and adjusting for any workflow-specific properties, the final step is to instantiate a Converter
object and call its ConvertDocument
method.
The output image file is created at the specified path.
- .NET
- Java
// Create output stream
using var outStr = File.Create(outPath);
// Convert the PDF document to an image document
using var outDoc = new Converter().ConvertDocument(inDoc, outStr, profile);
// Create output stream
FileStream outStream = new FileStream(outPath, FileStream.Mode.READ_WRITE_NEW);
// Convert the PDF document to an image document
com.pdftools.image.Document outDoc = new Converter().convertDocument(inDoc, outStream, profile))
Full example
- .NET
- Java
// Open input document
using var inStr = File.OpenRead(inPath);
using var inDoc = Document.Open(inStr);
// Create a profile that defines the initial conversion parameters.
// The Archive profile converts PDF documents to TIFF images for archiving.
var profile = new Profiles.Archive();
// Optionally, the profile's parameters can be changed according to the
// requirements of your conversion process.
// Create output stream
using var outStr = File.Create(outPath);
// Convert the PDF document to an image document
using var outDoc = new Converter().ConvertDocument(inDoc, outStr, profile);
// Create the profile that defines the conversion parameters.
// The Archive profile converts PDF documents to TIFF images for archiving.
Archive profile = new Archive();
// Optionally, the profile's parameters can be changed according to the
// requirements of your conversion process.
try (
// Open input document
FileStream inStr = new FileStream(inPath, FileStream.Mode.READ_ONLY);
com.pdftools.pdf.Document inDoc = com.pdftools.pdf.Document.open(inStr);
// Create output stream
FileStream outStream = new FileStream(outPath, FileStream.Mode.READ_WRITE_NEW);
// Convert the PDF document to an image document
com.pdftools.image.Document outDoc = new Converter().convertDocument(inDoc, outStream, profile))
{
}