Write a code snap to convert .tif to PDF file format.http://forums.asp.net/t/1577541.aspx/1?Write+a+code+snap+to+convert+tif+to+PDF+file+format+Wed, 26 Oct 2011 14:11:05 -040015775413965878http://forums.asp.net/p/1577541/3965878.aspx/1?Write+a+code+snap+to+convert+tif+to+PDF+file+format+Write a code snap to convert .tif to PDF file format. <p>Hi,</p> <p>I have&nbsp;millions of .tif image files in D: drive of my computer. Those files are separeted by Year folders(e.g. 1990, 1991, 1992.....) and each year folders have those tif files.</p> <p>so the local path :</p> <p>D:\publications\1901\...tif</p> <p>Now, inside the year folder(1901), the .tif files have different page for the same date(e.g.1901-09-21-p01.tif,1901-09-21-p02.tif,1901-09-21-p03.tif,1901-09-21-p04.tif,1901-09-21-p05.tif....)</p> <p>&nbsp;</p> <p>I have to write a .net code so that it reads and open the year&nbsp;folder and reads the tif files inside it and change <u><strong>the multiple .tif files</strong></u>(which have same data) <strong><u>to single pdf file.</u></strong></p> <p>e.g. 1901-09-21-p01.tif,1901-09-21-p02.tif,1901-09-21-p03.tif,1901-09-21-p04.tif,1901-09-21-p05.tif............to 1901-09-21.pdf </p> <p>1901-09-22-p01.tif,1901-09-22-p02.tif,1901-09-22-p03.tif,1901-09-22-p04.tif,1901-09-22-p05.tif............to 1901-09-22.pdf</p> <p>......................</p> <p>and save to local drive. When finish for 1901 and read for 1902 year folder and convert the tif files of it&nbsp;to pdf file....</p> <p>so, it should do for all the year folders publication images.</p> <p>Anyone has idea ??</p> <p>Thanks in Advance.</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> 2010-07-09T20:11:26-04:003966232http://forums.asp.net/p/1577541/3966232.aspx/1?Re+Write+a+code+snap+to+convert+tif+to+PDF+file+format+Re: Write a code snap to convert .tif to PDF file format. <p>Refer:</p> <p>http://atashbahar.com/post/Converting-Multipage-TIFF-image-to-PDF.aspx</p> <p>http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/fb9c29bd-bb4c-4bb9-b6b9-11fc5a71cfa5</p> <p>http://stackoverflow.com/questions/1982028/bad-performance-convert-tif-to-pdf-using-itextsharp</p> <p>http://www.codeproject.com/KB/files/tifftopdf.aspx</p> <p>http://blog.codebeach.com/2008/02/convert-multipage-tiff-to-pdf-in-net.html</p> <p><br> </p> <p><br> </p> 2010-07-10T05:18:37-04:003968693http://forums.asp.net/p/1577541/3968693.aspx/1?Re+Write+a+code+snap+to+convert+tif+to+PDF+file+format+Re: Write a code snap to convert .tif to PDF file format. <p>thanks, chintanpshah&nbsp;for your&nbsp;reply.</p> <p>How can&nbsp;I read the same date files&nbsp;and convert only those to single pdf and again read another same date tiff files and convert to pdf and so on...</p> <p>How can I do this automatic, so I can give only the local physical path for the input and output ? </p> <p>Thanks</p> 2010-07-12T13:21:24-04:004082446http://forums.asp.net/p/1577541/4082446.aspx/1?Re+Write+a+code+snap+to+convert+tif+to+PDF+file+format+Re: Write a code snap to convert .tif to PDF file format. <p>Thanks, Chintanpshah for your useful post.</p> <p>The first link is the easy one to implement and I have small problem here:</p> <p>in this line, he specified the single&nbsp;tif files (<font size="2"></p> <p>System.Drawing.</p> </font> <p><font color="#2b91af" size="2"><font color="#2b91af" size="2">Bitmap</font></font><font size="2"> bm = </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">new</font></font><font size="2"> System.Drawing.</font><font color="#2b91af" size="2"><font color="#2b91af" size="2">Bitmap</font></font><font size="2">(Server.MapPath(</font><font color="#a31515" size="2"><font color="#a31515" size="2">&quot;~/App_Data/source.tif&quot;</font></font><font size="2">))</font></p> <p><font size="2"></font>&nbsp;</p> <p><font size="2">how can I specify multiple tif files to convert to single pdf.</font></p> <p><font size="2"></font>&nbsp;</p> <p><font size="2">I did this</font></p> <p><font size="2">&nbsp;/app_code/*.tif but this didn't work.</font></p> <p><font size="2"></font>&nbsp;</p> <p><font size="2">Thanks</font></p> <p></p> 2010-09-16T14:16:51-04:004116401http://forums.asp.net/p/1577541/4116401.aspx/1?Re+Write+a+code+snap+to+convert+tif+to+PDF+file+format+Re: Write a code snap to convert .tif to PDF file format. <p><strong>TIFF to PDF can be done using iTextSharp PDF open C# Library (itextsharp.dll).<br> </strong></p> <p>i recommend you to do easily this bulk transformation&nbsp;task using SQL Server Integration Services package.<br> <br> 1. Include FileSystem Task and read the TIFF image paths.<br> 2. Include ForEach loop task and loop through each of source image TIFF image path.<br> 3. Create a CONSOLE application project with following code snippet.</p> <p>4.&nbsp;Include a&nbsp;EXECUTE process Task and&nbsp;point to the CONSOLE application project.</p> <p>That's it... you are done with all WORKFLOWs with out of the box SSIS ready made toolsets.<br> </p> <p>Refer the following CONSOLE Application EXE file in SSIS ProcessTask and pass variables (TIF path and ToBePDF fileNamepath)&nbsp;as parameters to the console application.</p> <p><br> Following is the code snippet with CONSOLE application taking two commandline arguments... <br> <br> Arg[0] --&gt;&nbsp;SOURCE TIFF image path and <br> Arg[1] --&gt;&nbsp;Destination&nbsp;PDF document path<br> <br> ==========</p> <p>using System;<br> using System.Collections.Generic;<br> using System.Linq;<br> using System.Text;<br> using iTextSharp;<br> using iTextSharp.text;<br> using iTextSharp.text.pdf;<br> using System.Drawing;<br> using System.Drawing.Imaging;</p> <p>namespace Tiff2Pdf<br> {<br> &nbsp;&nbsp;&nbsp; class Program<br> &nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static void Main(string[] args)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (args.Length &gt; 1)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Create document <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Document document = new Document();</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //load the tiff image and count the total pages&nbsp; <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Bitmap bm = new Bitmap(args[0]);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // creation of the different writers<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PdfWriter writer = PdfWriter.GetInstance(document,<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new System.IO.FileStream(args[1],<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.IO.FileMode.Create));</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Total number of pages<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int totalPages = bm.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page);</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Open();</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PdfContentByte cb = writer.DirectContent;</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int pageNumber = 0; pageNumber &lt; totalPages; &#43;&#43;pageNumber)<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bm.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, pageNumber);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(bm, ImageFormat.Tiff);<br> </p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // scale the image to fit in the page&nbsp;&nbsp;<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; img.ScalePercent(7200f / img.DpiX, 7200f / img.DpiY);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; img.SetAbsolutePosition(0, 0);<br> </p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cb.AddImage(img);<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.NewPage();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; document.Close();<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br> &nbsp;&nbsp;&nbsp; }<br> }</p> 2010-10-07T21:19:48-04:004654706http://forums.asp.net/p/1577541/4654706.aspx/1?Re+Write+a+code+snap+to+convert+tif+to+PDF+file+format+Re: Write a code snap to convert .tif to PDF file format. <p>Hi Bharath,</p> <p>The code snap you posted works well for A4 size tiff files but&nbsp;not for other tiff files with different dimensions. Please let me know if you have any other code for this.</p> <p>&nbsp;</p> <p>Thanks!</p> <p>Srinu.</p> 2011-10-26T14:11:05-04:00