CorelDRAW files use the CDR format to store vector artwork, illustrations, page layouts, and other graphic content. While CDR is useful for working with CorelDRAW documents, PDF is a more widely supported format for sharing, printing, archiving, and distributing documents. In this tutorial, you will learn how to convert CDR to PDF in C# programmatically using Aspose.Imaging for .NET. You will also learn how to configure CDR rasterization options to preserve the original page dimensions, positioning, and background when generating the PDF.
Why Convert CDR to PDF?
CDR files are commonly used for professional graphic design and publishing workflows. However, recipients may not have CorelDRAW or another application capable of opening CDR files. PDF provides a convenient alternative because it is widely supported across operating systems, browsers, document viewers, and printing workflows.
Converting CDR to PDF can be useful when you need to:
- Share CorelDRAW artwork with users who do not have CorelDRAW installed.
- Prepare CDR artwork for printing and distribution.
- Archive CorelDRAW documents in a widely supported format.
- Generate PDF documents automatically from CDR files.
- Integrate CDR to PDF conversion into .NET applications.
- Process CorelDRAW files as part of an automated document workflow.
Aspose.Imaging for .NET allows you to load CDR files and save them as PDF programmatically without requiring CorelDRAW.
CDR to PDF Converter for .NET
Aspose.Imaging for .NET is an image-processing library that supports working with various raster and vector image formats.
For CDR to PDF conversion, the library provides PdfOptions for PDF output and CdrRasterizationOptions for controlling how the CDR vector content is rendered.
The rasterization settings allow you to control aspects such as:
- Page size
- Page positioning
- Background color
- Scaling
- Rendering behavior
These settings are particularly important when you need the generated PDF to preserve the appearance and dimensions of the original CDR document.
Install Aspose.Imaging for .NET
Before converting CDR to PDF, install Aspose.Imaging in your .NET project.
You can install the package from NuGet using the following command:
Install-Package Aspose.Imaging
After installing the package, you can use the Aspose.Imaging APIs to load the CDR file and export it as PDF.
Convert CDR to PDF in C# Programmatically
The process of converting CDR to PDF can be summarized in the following steps:
- Load the source CDR file using the
Image.Loadmethod. - Create an instance of the
PdfOptionsclass. - Create and configure
CdrRasterizationOptions. - Set the page size to match the source CDR image.
- Set the positioning mode to preserve the document’s coordinate system.
- Set the background color when a specific PDF background is required.
- Assign the rasterization options to
PdfOptions.VectorRasterizationOptions. - Save the CDR file as a PDF using the
Image.Savemethod.
Convert CDR to PDF Without Black Pages
When converting vector artwork from CDR to PDF, the rasterization settings can affect how the resulting document is rendered.
Explicitly configuring CdrRasterizationOptions gives you control over the page dimensions, positioning, and background used during conversion.
For example, you can configure the rasterization options as follows:
using Aspose.Imaging;
using Aspose.Imaging.ImageOptions;
using (var image = Image.Load("input.cdr"))
{
var pdfOptions = new PdfOptions
{
VectorRasterizationOptions = new CdrRasterizationOptions
{
PageSize = image.Size,
Positioning = PositioningTypes.DefinedByDocument,
BackgroundColor = Color.White
}
};
image.Save("output.pdf", pdfOptions);
}
In this example, Image.Load loads the source CDR file, while PdfOptions specifies that the output should be generated as a PDF.
The CdrRasterizationOptions object controls how the CDR vector content is rendered. PageSize uses the source image dimensions, Positioning preserves the positioning defined by the document, and BackgroundColor sets a white background for the rendered content.
Configure CDR Rasterization Options
CDR is a vector format, whereas the rendering process used to generate the PDF requires the vector content to be rasterized according to the configured output options.
CdrRasterizationOptions provides settings that control this process.
Preserve the Original Page Size
To preserve the dimensions of the source CDR image, set PageSize to the source image size:
PageSize = image.Size
This allows the generated PDF page to correspond to the dimensions of the source CDR image.
Preserve Document Positioning
You can use PositioningTypes.DefinedByDocument to preserve the coordinate system and positioning defined by the CDR document:
Positioning = PositioningTypes.DefinedByDocument
This can help maintain the intended placement of the artwork within the generated PDF.
Set the PDF Background Color
You can explicitly define the background color using the BackgroundColor property:
BackgroundColor = Color.White
Setting a white background can be useful when the source CDR document does not provide an opaque background and the generated PDF requires a visible white canvas.
Complete CDR to PDF C# Example
The following example demonstrates the complete CDR to PDF conversion process:
using Aspose.Imaging;
using Aspose.Imaging.ImageOptions;
namespace CSharp.ModifyingAndConvertingImages.CDR
{
class CdrToPdfExample
{
static void Main()
{
// Load the source CDR file.
using (var image = Image.Load("input.cdr"))
{
// Create PDF options.
var pdfOptions = new PdfOptions
{
// Configure CDR rasterization options.
VectorRasterizationOptions = new CdrRasterizationOptions
{
// Preserve the source image dimensions.
PageSize = image.Size,
// Preserve document positioning.
Positioning = PositioningTypes.DefinedByDocument,
// Set a white background.
BackgroundColor = Color.White
}
};
// Save the CDR file as PDF.
image.Save("output.pdf", pdfOptions);
}
}
}
}
Code Explanation
The code performs the conversion in four main stages:
Image.Loadloads the CDR file.PdfOptionsdefines PDF-specific output settings.CdrRasterizationOptionscontrols how the CDR vector content is rendered.Image.Savewrites the resulting document to a PDF file.
The PageSize setting preserves the source dimensions, while PositioningTypes.DefinedByDocument preserves the document’s positioning. The BackgroundColor property is used to specify a white background.
Convert Multi-Page CDR to PDF
CDR documents can contain multiple pages. When converting a multi-page CDR document to PDF, the pages can be processed as part of the image conversion workflow.
The appropriate page-handling approach depends on the structure of the source CDR document and the required PDF output.
For applications that need to process individual pages, you can work with the pages exposed by the loaded image and configure the appropriate output options for the conversion.
Customize CDR to PDF Conversion
You can further customize the rasterization process depending on the requirements of your application.
CdrRasterizationOptions provides properties that can be used to control rendering and output behavior, including:
PageSize— defines the output page size.PageWidthandPageHeight— define individual page dimensions.Positioning— controls how the content is positioned.BackgroundColor— specifies the background color.ScaleXandScaleY— control horizontal and vertical scaling.SmoothingMode— controls smoothing during rasterization.TextRenderingHint— controls text rendering.
These options allow you to customize the PDF generated from CDR files according to your application’s requirements.
Get a Free Temporary License
Aspose.Imaging is a commercial image-processing library. You can obtain a free temporary license for development and testing to evaluate the API without the limitations of the evaluation version.
Conclusion
Converting CDR to PDF in .NET provides a convenient way to make CorelDRAW artwork available in a widely supported document format. With Aspose.Imaging for .NET, you can load a CDR file, configure CdrRasterizationOptions, and save the result as PDF. By setting the page size, positioning, and background color, you can control how the CDR content is rendered during conversion. This provides a programmatic CDR to PDF converter in C# that can be integrated into .NET applications and automated document-processing workflows.
FAQs
What is CDR to PDF conversion? CDR to PDF conversion is the process of converting a CorelDRAW CDR document into the PDF format. PDF is widely supported and is commonly used for sharing, printing, and archiving documents.
How can I convert CDR to PDF in C#? You can use Aspose.Imaging for .NET. Load the CDR file with
Image.Load, createPdfOptions, configureCdrRasterizationOptions, and save the result usingImage.Save.Can I convert CDR to PDF without CorelDRAW? Yes. Aspose.Imaging for .NET provides APIs for loading and converting CDR files programmatically, so your .NET application does not need to automate CorelDRAW for the conversion.
Can I convert CDR to other image formats using Aspose.Imaging? Yes. Aspose.Imaging supports CDR conversion to multiple output formats. For example, you can also convert CDR files to PNG and other supported formats programmatically.
