C# PDF Convert: How to Convert Jpeg, Png, Bmp, & Gif Raster Images to PDF
Help You to Add High Performance Conversion from Raster Images to PDF in Your C# Application
Raster image files like Jpeg, Png, Bmp, and Gif are supported by XDoc.Converter for .NET. On this C# tutorial, we will depict how to convert all these raster images to Adobe PDF document. And respective C# programming examples are illustrated.
C# DLLs for Converting Images to PDF
Add necessary references to your C# project:
RasterEdge.Imaging.Basic.dll
RasterEdge.Imaging.Basic.Codec.dll
RasterEdge.Imaging.DICOM.dll
RasterEdge.Imaging.Font.dll
RasterEdge.Imaging.Drawing.dll
RasterEdge.Imaging.JBIG2.dll
RasterEdge.Imaging.JPEG2000.dll
RasterEdge.Imaging.Processing.dll
RasterEdge.XDoc.Converter.dll
RasterEdge.XDoc.Excel.dll
RasterEdge.XDoc.Office.Inner.Common.dll
RasterEdge.XDoc.Office.Inner.Office03.dll
RasterEdge.XDoc.PDF.dll
RasterEdge.XDoc.PowerPoint.dll
RasterEdge.XDoc.TIFF.dll
RasterEdge.XDoc.Word.dll
RasterEdge.XImage.AdvancedCleanup.Core.dll
RasterEdge.XImage.OCR.dll
RasterEdge.XImage.OCR.Tesseract.dll
RasterEdge.XImage.Raster.Core.dll
RasterEdge.XImage.Raster.dll
Use the namespaces
using RasterEdge.Imaging.Basic;
using RasterEdge.XDoc.Converter;
Jpeg to PDF Conversion in C#
In the following C# programming demo, we will firstly take Jpeg to PDF conversion as an example.
// Define input and output files path.
String inputFilePath = @"***.jpg";
String outputFilePath = @"***.pdf";
// Convert Jpeg to PDF and show conversion result.
ConvertResult result = DocumentConverter.ToDocument(inputFilePath, outputFilePath, FileType.DOC_PDF);
switch (result)
{
case ConvertResult.NO_ERROR:
Console.WriteLine("Success");
break;
case ConvertResult.FILE_TYPE_UNSUPPORT:
Console.WriteLine("Fail: can not convert to PDF, file type unsupport");
break;
case ConvertResult.FILE_TYPE_UNMATCH:
Console.WriteLine("Fail: input file is not a document");
default:
Console.WriteLine("Fail: unknown error");
break;
}
|
Png to PDF Conversion in C#
You may use this demo code in your C# application to implement rapid conversion from Png image to PDF document.
// Define input and output files path.
String inputFilePath = @"***.png";
String outputFilePath = @"***.pdf";
// Convert Jpeg to PDF and show conversion result.
ConvertResult result = DocumentConverter.ToDocument(inputFilePath, outputFilePath, FileType.DOC_PDF);
switch (result)
{
case ConvertResult.NO_ERROR:
Console.WriteLine("Success");
break;
case ConvertResult.FILE_TYPE_UNSUPPORT:
Console.WriteLine("Fail: can not convert to PDF, file type unsupport");
break;
case ConvertResult.FILE_TYPE_UNMATCH:
Console.WriteLine("Fail: input file is not a document");
default:
Console.WriteLine("Fail: unknown error");
break;
}
|
Bmp to PDF Conversion in C#
For converting Bmp image to PDF file, please refer to this C# programming example.
// Define input and output files path.
String inputFilePath = @"***.bmp";
String outputFilePath = @"***.pdf";
// Convert Jpeg to PDF and show conversion result.
ConvertResult result = DocumentConverter.ToDocument(inputFilePath, outputFilePath, FileType.DOC_PDF);
switch (result)
{
case ConvertResult.NO_ERROR:
Console.WriteLine("Success");
break;
case ConvertResult.FILE_TYPE_UNSUPPORT:
Console.WriteLine("Fail: can not convert to PDF, file type unsupport");
break;
case ConvertResult.FILE_TYPE_UNMATCH:
Console.WriteLine("Fail: input file is not a document");
default:
Console.WriteLine("Fail: unknown error");
break;
}
|
Gif to PDF Conversion in C#
Besides Jpeg, Png, and Bmp, C# developers can also render and convert raster image Gif to Adobe PDF document.
// Define input and output files path.
String inputFilePath = @"***.gif";
String outputFilePath = @"***.pdf";
// Convert Jpeg to PDF and show conversion result.
ConvertResult result = DocumentConverter.ToDocument(inputFilePath, outputFilePath, FileType.DOC_PDF);
switch (result)
{
case ConvertResult.NO_ERROR:
Console.WriteLine("Success");
break;
case ConvertResult.FILE_TYPE_UNSUPPORT:
Console.WriteLine("Fail: can not convert to PDF, file type unsupport");
break;
case ConvertResult.FILE_TYPE_UNMATCH:
Console.WriteLine("Fail: input file is not a document");
default:
Console.WriteLine("Fail: unknown error");
break;
}
|