I have 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.
so the local path :
D:\publications\1901\...tif
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....)
I have to write a .net code so that it reads and open the year folder and reads the tif files inside it and change
the multiple .tif files(which have same data) to single pdf file.
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
TIFF to PDF can be done using iTextSharp PDF open C# Library (itextsharp.dll).
i recommend you to do easily this bulk transformation task using SQL Server Integration Services package.
1. Include FileSystem Task and read the TIFF image paths.
2. Include ForEach loop task and loop through each of source image TIFF image path.
3. Create a CONSOLE application project with following code snippet.
4. Include a EXECUTE process Task and point to the CONSOLE application project.
That's it... you are done with all WORKFLOWs with out of the box SSIS ready made toolsets.
Refer the following CONSOLE Application EXE file in SSIS ProcessTask and pass variables (TIF path and ToBePDF fileNamepath) as parameters to the console application.
Following is the code snippet with CONSOLE application taking two commandline arguments...
Arg[0] --> SOURCE TIFF image path and
Arg[1] --> Destination PDF document path
==========
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iTextSharp;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.Drawing;
using System.Drawing.Imaging;
namespace Tiff2Pdf
{
class Program
{
static void Main(string[] args)
{
if (args.Length > 1)
{
//Create document
Document document = new Document();
//load the tiff image and count the total pages
Bitmap bm = new Bitmap(args[0]);
// creation of the different writers
PdfWriter writer = PdfWriter.GetInstance(document,
new System.IO.FileStream(args[1],
System.IO.FileMode.Create));
//Total number of pages
int totalPages = bm.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page);
The code snap you posted works well for A4 size tiff files but not for other tiff files with different dimensions. Please let me know if you have any other code for this.
rajsedhain
Contributor
4181 Points
1041 Posts
Write a code snap to convert .tif to PDF file format.
Jul 09, 2010 08:11 PM|LINK
Hi,
I have 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.
so the local path :
D:\publications\1901\...tif
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....)
I have to write a .net code so that it reads and open the year folder and reads the tif files inside it and change the multiple .tif files(which have same data) to single pdf file.
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
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
......................
and save to local drive. When finish for 1901 and read for 1902 year folder and convert the tif files of it to pdf file....
so, it should do for all the year folders publication images.
Anyone has idea ??
Thanks in Advance.
Raj Sedhain
chintanpshah
All-Star
19058 Points
3273 Posts
Re: Write a code snap to convert .tif to PDF file format.
Jul 10, 2010 05:18 AM|LINK
Refer:
http://atashbahar.com/post/Converting-Multipage-TIFF-image-to-PDF.aspx
http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/fb9c29bd-bb4c-4bb9-b6b9-11fc5a71cfa5
http://stackoverflow.com/questions/1982028/bad-performance-convert-tif-to-pdf-using-itextsharp
http://www.codeproject.com/KB/files/tifftopdf.aspx
http://blog.codebeach.com/2008/02/convert-multipage-tiff-to-pdf-in-net.html
My Software Website
rajsedhain
Contributor
4181 Points
1041 Posts
Re: Write a code snap to convert .tif to PDF file format.
Jul 12, 2010 01:21 PM|LINK
thanks, chintanpshah for your reply.
How can I read the same date files and convert only those to single pdf and again read another same date tiff files and convert to pdf and so on...
How can I do this automatic, so I can give only the local physical path for the input and output ?
Thanks
Raj Sedhain
rajsedhain
Contributor
4181 Points
1041 Posts
Re: Write a code snap to convert .tif to PDF file format.
Sep 16, 2010 02:16 PM|LINK
Thanks, Chintanpshah for your useful post.
The first link is the easy one to implement and I have small problem here:
in this line, he specified the single tif files (
System.Drawing.
Bitmap bm = new System.Drawing.Bitmap(Server.MapPath("~/App_Data/source.tif"))
how can I specify multiple tif files to convert to single pdf.
I did this
/app_code/*.tif but this didn't work.
Thanks
Raj Sedhain
Bharath.P
Member
55 Points
15 Posts
Re: Write a code snap to convert .tif to PDF file format.
Oct 07, 2010 09:19 PM|LINK
TIFF to PDF can be done using iTextSharp PDF open C# Library (itextsharp.dll).
i recommend you to do easily this bulk transformation task using SQL Server Integration Services package.
1. Include FileSystem Task and read the TIFF image paths.
2. Include ForEach loop task and loop through each of source image TIFF image path.
3. Create a CONSOLE application project with following code snippet.
4. Include a EXECUTE process Task and point to the CONSOLE application project.
That's it... you are done with all WORKFLOWs with out of the box SSIS ready made toolsets.
Refer the following CONSOLE Application EXE file in SSIS ProcessTask and pass variables (TIF path and ToBePDF fileNamepath) as parameters to the console application.
Following is the code snippet with CONSOLE application taking two commandline arguments...
Arg[0] --> SOURCE TIFF image path and
Arg[1] --> Destination PDF document path
==========
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iTextSharp;
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.Drawing;
using System.Drawing.Imaging;
namespace Tiff2Pdf
{
class Program
{
static void Main(string[] args)
{
if (args.Length > 1)
{
//Create document
Document document = new Document();
//load the tiff image and count the total pages
Bitmap bm = new Bitmap(args[0]);
// creation of the different writers
PdfWriter writer = PdfWriter.GetInstance(document,
new System.IO.FileStream(args[1],
System.IO.FileMode.Create));
//Total number of pages
int totalPages = bm.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page);
document.Open();
PdfContentByte cb = writer.DirectContent;
for (int pageNumber = 0; pageNumber < totalPages; ++pageNumber)
{
bm.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, pageNumber);
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(bm, ImageFormat.Tiff);
// scale the image to fit in the page
img.ScalePercent(7200f / img.DpiX, 7200f / img.DpiY);
img.SetAbsolutePosition(0, 0);
cb.AddImage(img);
document.NewPage();
}
document.Close();
}
}
}
}
.tif to PDF using SSIS
Srinian
Member
4 Points
4 Posts
Re: Write a code snap to convert .tif to PDF file format.
Oct 26, 2011 02:11 PM|LINK
Hi Bharath,
The code snap you posted works well for A4 size tiff files but not for other tiff files with different dimensions. Please let me know if you have any other code for this.
Thanks!
Srinu.