How do I convert a bunch of TIFFs to a linearized and JBIG2 compressed PDF?

Q: How do I convert a bunch of TIFFs to a linearized and JBIG2
compressed PDF?

A: As a starting point you may want to take a look at AddImage sample
project:

http://www.pdftron.com/pdfnet/samplecode.html#AddImage

For a full solution please take a look at ‘Tiff2PDF-Jbig2’ in Files
section of this group:

http://pdfnet-sdk.googlegroups.com/web/Tiff2PDF-Jbig2.zip

// Copyright © 2001-2010 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;

// Convert all TIFF files in given folder to a linearized and JBIG2
compressed PDF.

namespace PDFNetSamples
{
class TIFF2PDF
{
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);

Page page = doc.PageCreate(); // Start a new page
w.Begin(page); // Begin writing to this page

// System.Drawing.Bitmap bmp = new
System.Drawing.Bitmap(fileName);
// Image img = Image.Create(doc, bmp, jbig2_hint);
pdftron.PDF.Image img = pdftron.PDF.Image.Create(doc, fileName,
jbig2_hint);
Element element = b.CreateImage(img, new
Matrix2D(page.GetPageWidth(), 0, 0, (page.GetPageWidth() *
img.GetImageHeight()) / img.GetImageWidth(), 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(“D:/Tiffs”, doc, w, b);

w.Dispose();
b.Dispose();
doc.Save(“D:/Test/out.pdf”, 0);
doc.Close();
Console.WriteLine(“Done…”);
}
catch (PDFNetException e)
{
Console.WriteLine(e.Message);
}
}
}
}