Introduction
Suppose you have a list of image
files in various formats and would like to convert them into single PDF file
for simpler sharing, archiving or whatever needs. A good example of such list
is a list of scanned documents, books, lectures or drawings. For this task you
may use our Apitron PDF Kit .NET component and let it do the work.
The code
public void ConvertImagesToPDF()
{
//
create resource manager for resulting document
ResourceManager resourceManager = new ResourceManager();
//
create resulting document
FixedDocument resultingDocument = new FixedDocument(resourceManager);
// let's
assume that we have a folder with images needed to be packed
foreach (string fileName in Directory.EnumerateFiles("Images", "*.*"))
{
// add
document page from image with basic settings
resultingDocument.Pages.Add(Page.CreateFromImage(fileName,resourceManager,new FromImagePageSettings(Boundaries.A4)));
}
// save
resulting document
using (Stream outputStream = File.Create("resultingDocument.pdf"))
{
resultingDocument.Save(outputStream);
}
}
The code above creates PDF file
from a list of images found in [Current
Directory]\Images folder. This functionality completely replaces the Image2PDF product which was superseded by
Apitron PDF Kit and you can convert images to PDF using the code above getting
the same results. The FromImagePageSettings class can be used to specify
conversion settings e.g. image border and its color, scale mode, page
orientation etc. The library supports all major image formats: bmp, jpeg, tiff,
png, jbig2.
You can also find a complete book
on our website which contains detailed explanation of many PDF related aspects
(see Apitron
PDF Kit in Action). Feel free to ask questions, we are always ready to
help.
Downloadable version of this article can be found by the following link [PDF].
No comments:
Post a Comment