How do I convert scanned TIF images to linearized and JBIG2 compressed PDF?

Q: I have a folder containing thousands of scanned monochrome TIFF
images and would like to convert them to an optimized PDF. To keep the
file size down the monochrome images must be comressed using JBIG2
compression and the ourput PDF must be linearized to provide fast web-
based access.

Could you please show how PDFNet SDK can be used to implement this
functionality:

A: The following code snippet shows how to convert all TIF images from
a given folder to a linearized and JBIG2 compressed PDF:

// Copyright © 2001-2008 by PDFTron Systems Inc. All Rights
Reserved.
using System;
using System.IO;
using pdftron;
using pdftron.Common;
using pdftron.Filters;
using pdftron.SDF;
using pdftron.PDF;

namespace PDFNetSamples
{
class AddImage
{
static int counter = 0;
static Obj jbig2_hint = null;

public static void ProcessDir(string sourceDir, PDFDoc doc,
ElementWriter w, ElementBuilder b)
{
// Process the list of files found in the directory.
string [] fileEntries = Directory.GetFiles(sourceDir);
foreach(string fileName in fileEntries)
{
Console.WriteLine(fileName);

System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(fileName);
Page page = doc.PageCreate();
w.Begin(page);
Image img = Image.Create(doc, bmp, jbig2_hint);
Element element = b.CreateImage(img, new
Matrix2D(page.GetPageWidth(), 0, 0, (page.GetPageWidth()*bmp.Height)/
bmp.Width, 0, 0));
bmp.Dispose();

w.WritePlacedElement(element);
w.End();

doc.PagePushBack(page);
}

// Recurse into subdirectories of this directory.
string [] subdirEntries = Directory.GetDirectories(sourceDir);
foreach(string subdir in subdirEntries)
// Do not iterate through reparse points
if ((File.GetAttributes(subdir) & FileAttributes.ReparsePoint)
!= FileAttributes.ReparsePoint)
ProcessDir(subdir, doc, w, b);
}

static void Main(string[] args)
{
try
{
PDFNet.Initialize();

// Setup JBIG2 hint
ObjSet objset = new ObjSet();
jbig2_hint = objset.CreateArray();
jbig2_hint.PushBackName(“JBIG2”);

PDFDoc doc = new PDFDoc();
ElementBuilder b = new ElementBuilder(); // Used to build new
Element objects
ElementWriter w = new ElementWriter(); // Used to write Elements
to the page

ProcessDir(“c:/tiffs”, doc, w, b);

w.Dispose();
b.Dispose();
doc.Save(“c:/out.pdf”, SDFDoc.SaveOptions.e_linearized);
doc.Close();
Console.WriteLine(“Done…”);
}
catch (PDFNetException e)
{
Console.WriteLine(e.Message);
}

PDFNet.Terminate();
}
}
}