How do I convert multipage TIFFs to PDF?

Q:

How do I convert multipage TIFFs to PDF?
---
A:
You can use PDFNet to convert multipage tiffs to PDF.

pdftron.PDF.Image.Create(filename) method will embed only the first
image in the TIFF file (see AddImage sample project
http://www.pdftron.com/net/samplecode.html#AddImage), however you can
use pdftron.PDF.Image.Create(System.Drawing.Bitmap) to import TIFF
images frame by frame.

In this case, Image.SelectActiveFrame() method from DotNet Framework
is useful to select the 'current' image. See
http://msdn2.microsoft.com/en-us/library/ms533838.aspx for more
information and some sample code on how to use this API.

GDI+ does have some limitations when it comes to TIFF support (e.g.
CMYK images etc). As a workaround, you can use any third party TIFF or
image library (such as libtiff - http:// www.libtiff.org/ or freeimage
- http://freeimage.sourceforge.net) that can load TIFF without relying
on GDI+. In this case you would decompress the Tiff file, frame by
frame, in memory and would pass the RAW image data to
pdftron.PDF.Image.Create() method).

The code used to load TIFF using freeimage might be along the
following lines:

// Assuming you are developing in C#:
string img1 = @"C:\image.tif";
Int32 fi =
FreeImageAPI.FreeImage.Load( FreeImageAPI.FREE_IMAGE_FORMAT.FIF_TIFF,
img1,
  (int)FreeImageAPI.LoadSaveFlags.TIFF_RGB |
(int)FreeImageAPI.LoadSaveFlags.TIFF_NONE );
UInt32 hmem = FreeImageAPI.FreeImage.OpenMemory(null,0);

//
FreeImageAPI.FreeImage.SaveToMemory(FreeImageAPI.FREE_IMAGE_FORMAT.FIF_TIFF,
fi,hmem,(int)FreeImageAPI.LoadSaveFlags.TIFF_CMYK |
(int)FreeImageAPI.LoadSaveFlags.TIFF_NONE);

System.IntPtr ptr = IntPtr.Zero;
int size_in_bytes = 0;
FreeImage.AcquireMemory(hmem,ref ptr,ref size_in_bytes);
byte[] content = new byte[size_in_bytes];
Marshal.Copy(ptr ,content,0,(content.Length));
FreeImage.CloseMemory(hmem);
FreeImage.Unload(fi);

// And then embed the raw (and compress) image data using PDFNet API.

pdftron.PDF.Image img = Image.Create(doc.GetSDFDoc(),content,
600,900,8,ColorSpace.CreateDeviceRGB() ,0);
Element element_new = f.CreateImage(img, new Matrix2D(143, 0, 0, 215,
215, 387)); writer.WritePlacedElement(element_new);
writer.End();
reader.End();

Q:
Is there anyway you can send me the VB.Net code to do this?
---
A:

The VB.NET code would be along the following lines:

Dim image As System.Drawing.Bitmap = System.Drawing.Image.FromFile("c:
\my.tif")
Dim index As Guid = image.FrameDimensionsList(0)
Dim dimension As System.Drawing.Imaging.FrameDimension = New
System.Drawing.Imaging.FrameDimension(index)

' The number of frames in the file
Dim totalFrame As Integer = TifImage.GetFrameCount(dimension)
Dim currentFrame As Integer = 0

'select the page you want to process
image.SelectActiveFrame(dimension, currentFrame)

' Add the selected frame to the PDF file
... see AddImage sample project for details (http://www.pdftron.com/
net/samplecode/AddImageTest.vb)...
Dim img As Image = Image.Create(doc.GetSDFDoc(), image)
Dim element As Element = f.CreateImage(img, New Matrix2D(image.Width,
0, 0, image.Height, 50, 350))
writer.WritePlacedElement(element)

Please note that we are not directly supporting GDI+, FreeType or
other third party libraries. For more information and some code
examples related to GDI+, please see http://www.bobpowell.net/addframes.htm).