Wednesday, December 1, 2010

Creating pdf From single Tiff image with itextSharp

//This is the program explain to us that how to create a pdf file form a tiff image


using iTextSharp.text;
using iTextSharp.text.pdf;


private void ImageToPdfConverter(string ImageP, string pdfP)
    {
        //FileStream fs = File.Open(@"D:\Tiff.pdf", FileMode.Create, FileAccess.Write);
        string ImagePath = ImageP;// Server.MapPath("image/");
        string PdfPath = pdfP;// Server.MapPath("pdf");
        //PdfPath = "D:/";
        //ImagePath = @"D:\Crop\01\163011410.tif";
        Document doc = new Document();
        PdfWriter.GetInstance(doc, new FileStream(PdfPath, FileMode.Create));
        doc.Open();
        // doc.Add(new Paragraph("TIF Scaled to 300dpi"));
        iTextSharp.text.Image tif = iTextSharp.text.Image.GetInstance(ImagePath );
        tif.ScalePercent(24f);
        tif.ScaleToFit(doc.PageSize.Width - 50, doc.PageSize.Height - 50);
        doc.Add(tif);
        doc.Close();


    }

4 comments:

  1. Man that's mean that the pdf will be created with a 300dpi resolution?

    ReplyDelete
  2. Dear @Anonymous

    Man that's mean that the pdf will be created with a 300dpi resolution?

    // doc.Add(new Paragraph("TIF Scaled to 300dpi"));

    This line indicated that you can add the scale in doc what ever you want.

    ReplyDelete
  3. thank you for the quick answer Praveen, I have other doubt,Do you have a example to read the pdf properties? Do you know How can I know if the pdf created has a resolution of 300 dpi? I'm trying using the PDFReader class but I can't get that property

    Best Regards

    ReplyDelete
  4. Hey, How can I show tiff with two frames in it.

    ReplyDelete