iTextSharp jbig2 encoder

string imgfile = @"C:\users\me\desktop\test.jpg";

Bitmap bmp = new Bitmap(imgfile);
Bitmap bw = ConvertTo1Bpp(bmp); //make b+w

Document doc = 
    new Document(new iTextSharp.text.Rectangle(bmp.Width, bmp.Height));

PdfWriter.GetInstance(doc, 
    new System.IO.FileStream(
        @"C:\users\me\desktop\test.pdf", 
        System.IO.FileMode.Create, 
        System.IO.FileAccess.ReadWrite));

iTextSharp.text.ImgJBIG2 i = 
    ((iTextSharp.text.ImgJBIG2)iTextSharp.text.ImgJBIG2.GetInstance(
        bmp, System.Drawing.Imaging.ImageFormat.Bmp));

doc.Open();
doc.Add(i);
doc.Close();

I cant find any good documentation for this with iTextSharp. What I am trying to do is take a Jpeg file and convert it into a pdf embedded as a black and white JBig2 image. The error I get is an InvalidCastException between "iTextSharp.text.ImageRaw" and "iTextSharp.text.ImageJBig2"... is there an alternative to what I have above?

EDIT ImgJBig2 just represents an image already encoded in JBig2 I believe now. What I am looking for is something that will take a Bitmap and encode it into a BW JBig2 Bitmap that I can put into a Pdf.

Answers


As far as I can tell there's not a lot of options for encoding JBig2 and no native free ones.

The last creates a CLI program that you might be able to P/Invoke into or at worst script against so I think that's your best option if you don't want to pay. Does JBIG2 offer such greater compression over other formats?


Need Your Help

WPF: Binding directly to a control

.net wpf binding

I need to bind a property of a UserControl directly to another control, rather than any specific property on that control. What's the best way to achieve this? I've tried various combinations of the

Google Calendar API v3 - authenticate with hardcoded credentials

php google-api google-api-php-client google-oauth2 google-calendar-api

I am writing a PHP application that's supposed to allow users to add certain events to a private Google Calendar. The calendar is owned by me, and I need a way for PHP to communicate with the calen...