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);
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