C# PDF Image Library
How to create, convert, export PDF file to multiple images using c# in asp.net, winforms
C# Create PDF from Raster Images, .NET Graphics and REImage File with XDoc.PDF Library for C#.NET Class
- Best and professional C# image to PDF converter SDK for Visual Studio .NET
- Batch convert PDF documents from multiple image formats, including Jpg, Png, Bmp, Gif, Tiff, Bitmap, .NET Graphics, and REImage
- Support .NET WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint
- Create PDF from images in both .NET WinForms and ASP.NET application
- .NET converter control for exporting high quality PDF from images in C#.NET
- Component for combining multiple image formats into one or multiple PDF file in C#.NET
- Any piece of area is able to be cropped and pasted to PDF page
- Source codes are available to use in C#.NET class
- Free library is access to downloading and using in .NET framework
If you want to turn PDF file into image file format in C# application, then RasterEdge XDoc.PDF for .NET can also help with this. It enables you to build a PDF file with
one or more images. Various image forms are supported which include Png, Jpeg, Bmp, and Gif raster images, .NET Graphics, as well as REImage (an intermediate class).
Some C# programming demos are illustrated below.
C# convert single Raster Image file to PDF
#region convert single Raster Image file to PDF(file to file)
internal static void image2Pdf()
{
String inputFilePath = @"C:\demo.jpg";
String outputFilePath = @"C:\output.pdf";
Bitmap bmp = new Bitmap(inputFilePath);
List<Bitmap> images = new List<Bitmap>();
images.Add(bmp);
PDFDocument doc = new PDFDocument(images.ToArray());
doc.Save(outputFilePath);
}
#endregion
#region convert single Raster Image file to PDF(Stream to Stream)
internal static void imageStream2PdfStream()
{
String inputFilePath = @"C:\demo.jpg";
byte[] arr = File.ReadAllBytes(inputFilePath);
MemoryStream inputStream = new MemoryStream(arr);
Bitmap bmp = new Bitmap(inputStream);
List<Bitmap> images = new List<Bitmap>();
images.Add(bmp);
PDFDocument doc = new PDFDocument(images.ToArray());
MemoryStream outputStream = new MemoryStream();
doc.SaveToStream(outputStream);
}
#endregion
Convert image file to editable PDF document using C#
If you need get editable PDF document from an image file, you need OCR SDK to extract text from image files.
using RasterEdge.XDoc.Converter;
String inputFilePath = @"C:\1.png";
String outputFilePath = @"C:\output.pdf";
DocumentSaveOption ops = new DocumentSaveOption(FileType.DOC_PDF);
// The folder that contains '.traineddata' files.
ops.OcrSourcePath = @"C:\Source";
// Convert to editable PDF file.
ops.IsSearchable = true;
ImageConverter.ToDocument(inputFilePath, outputFilePath, ops);
C# convert two or multiple Raster Image files to PDF (batch convert)
#region convert two or multiple Raster Image files to PDF (batch convert and sinle thread)
internal static void imageFilesToPdfFiles()
{
String inputDirectory = @"C:\input\";
String outputDirectory = @"C:\output\";
String[] files = Directory.GetFiles(inputDirectory, "*.*");
foreach (String filePath in files)
{
int startIdx = filePath.LastIndexOf("\\");
int endIdx = filePath.LastIndexOf(".");
String docName = filePath.Substring(startIdx + 1, endIdx - startIdx - 1);
Bitmap bmp = new Bitmap(filePath);
List<Bitmap> images = new List<Bitmap>();
images.Add(bmp);
PDFDocument doc = new PDFDocument(images.ToArray());
doc.Save(outputDirectory + docName);
}
}
#endregion
C# combine multiple Raster Image files into PDF
#region combine multiple Raster Image files into PDF
internal static void combineMultipleImagesIntoPdf()
{
String filePath1 = @"C:\demo1.jpg";
String filePath2 = @"C:\demo1.bmp";
String filePath3 = @"C:\demo1.png";
Bitmap image1 = new Bitmap(filePath1);
Bitmap image2 = new Bitmap(filePath2);
Bitmap image3 = new Bitmap(filePath3);
List<Bitmap> images = new List<Bitmap>();
images.Add(image1);
images.Add(image2);
images.Add(image3);
PDFDocument doc = new PDFDocument(images.ToArray());
doc.Save(@"C:\output.pdf");
}
#endregion
C# insert Raster Image file into pdf document, and create a new PDF file
#region insert Raster Image file into pdf document, and create a new PDF file
internal static void insertImageToPdf()
{
String filePath = @"C:\demo.png";
Bitmap bmp = new Bitmap(filePath);
List<Bitmap> images = new List<Bitmap>();
images.Add(bmp);
PDFDocument pdf = new PDFDocument(images.ToArray());
int pageCount = pdf.GetPageCount();
List<BasePage> pages = new List<BasePage>();
for (int i = 0; i < pageCount; i++)
{
pages.Add(pdf.GetPage(i));
}
String outputPdf = @"C:\output.pdf";
PDFDocument desDoc = new PDFDocument(outputPdf);
int insertLocation = 2;
desDoc.InsertPages(pages.ToArray(), insertLocation);
desDoc.Save(@"C:\desDocumcnet.pdf");
}
#endregion