Monday 14 May 2012

Hi friends

Here I am placing a code to convert tiff image to pdf file. Some time we need to convert the

tiff image to pdf file according to the client need .There are a few for .NET including
iTextSharp
, PDFsharp and PDF Clown. I used iTextSharp because it has a sample that was
showing how to create a PDF file from a multipage TIFF image
// creation of the document with a certain size and certain margins
iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.

PageSize.A4, 0, 0, 0, 0);
// creation of the different writers
iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(docu

ment, new System.IO.FileStream(Server.MapPath("~/PDF/Output.pdf"), System.IO.Fil

eMode.Create));
// load the tiff image and count the total pages
System.Drawing.Bitmap bm = new System.Drawing.Bitmap(Server.MapPath("~/Folder

Location/file.tif"));

int total = bm.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page);

document.Open();

iTextSharp.text.pdf.PdfContentByte cb = writer.DirectContent;

for (int k = 0; k < total; ++k)

{

bm.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, k);

iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(bm, System.Drawin

g.Imaging.ImageFormat.Bmp);



// scale the image to fit in the page
img.ScalePercent(72f / img.DpiX * 100);

img.SetAbsolutePosition(0, 0);

cb.AddImage(img);

document.NewPage();

}

document.Close();

No comments:

Post a Comment