Adding .FAX and .TIF image import in PDF

Q: I am trying to see if PDFNet can supprt .fax files. I’m trying to embed a fax file using the following code:


PDFDoc doc = new PDFDoc();

ElementBuilder bld = new ElementBuilder(); // Used to build new Element objects

ElementWriter writer = new ElementWriter(); // Used to write Elements to the page

ObjSet objset = new ObjSet();

Obj jbig2_hint = objset.CreateName(“JBIG2”);

Bitmap bmp = new System.Drawing.Bitmap(MapPath(“Images/PDFTron/03194002.fax”));

pdftron.PDF.Page page = doc.PageCreate(new Rect(0, 0, 612, 794)); // Start a new page

writer.Begin(page); // Begin writing to this page

pdftron.PDF.Image img = pdftron.PDF.Image.Create(doc, bmp, jbig2_hint);

Element element = bld.CreateImage(img, 100, 300, 300, 300);


writer.End(); // save changes to the current page


// Calling Dispose() results in increased performance and lower memory consumption.



doc.Save(PDFloc, SDFDoc.SaveOptions.e_linearized);


But it gets hung up on the line Bitmap bmp = new System.Drawing.Bitmap(MapPath(“Images/PDFTron/03194002.fax”));. The error says parameter not valid. Do you know if PDFnet can handle .fax files? and if so, can you point me to an example?



The images are tiff compressed as CCITT T.6 but I think they are getting saved in the PDF as jpeg as the PDF is about 1MB per image. The original tiff images are about 88KB.

Unfortunately these are multi page tiff images and we need to select a specific page of the image. Another complication is that we are loading the images from a database as a byte array.

I found this sample ( that shows how to specify the compression hit for JBIG2 but how do use CCITT?


In that case you can use the approach shown in JBIG2 sample:

That is:

a) Load the 1 BPP TIFF image frame with the help of Syste.Drawing.Bitmap
b) Extract raw 1 BPP data buffer (a byte array) from the the bitmap
c) Pass the buffer in pdftron.PDF.Image.Create(doc, buf, width, height, 1, ColorSpace.CreateDeviceGray(), _JBIG2_hint);

Btw. JBIG2 compression is up to 10x better than CCITT fax - for monochrome images, so we recommend sticking with JBIG2.

I found a workaround. When we use the bitmap copy constructor it changed the pixel format from 1BPP to 32BPP ARGB. I found a clone method that would preserve the pixel format and it appears to be working in our testing so far.