How do I compress PDF images using JPEG2000?

Q: Is there currently support in PDFNet for re-encoding existing PDF
images with JPEG2000 compression?


A: You can use PDFNet SDK to compress images using JPEG2000
compression or to recompress existing PDF documents using JPEG2000
compression.

In case you are embedding an image (RGB or Gray) you can specify a
compression ‘hint’ in the call to pdftron.PDF.Image.Create(). The
procedure is the same as for JBIG2 compression, except the you would
pass “JP2” or “JPEG2000” as the first hint parameter. For example:


ObjSet hint_set = new ObjSet();
Obj jp2_hint = hint_set.CreateArray();
jp2_hint.PushBackName(“JP2”);


// Embed a JPEG image and compress it using JPEG2000
Image img = Image::Create(doc, “peppers.jpg”, jp2_hint);

For some relevant code, please take a look at AddImage sample project
(http://www.pdftron.com/net/samplecode.html#AddImage).

You can also re-encoding existing PDF images with JPEG2000 compression
using the same approach used in JBIG2 sample project (http://
www.pdftron.com/net/samplecode.html#JBIG2), except that you would be
using JP2 hint and would be recompressing different type of images
(e.g. only images that use RGB or gray color space).

Please note that JPEG2000 compression is a new feature in PDFNet v.
4.0.7 so make sure that you are using the latest version of PDFNet
(http://www.pdftron.com/downloads.html).