This code sample shows how to convert a single or multi-page JBIG2 to PDF.
About JBIG2
JBIG2 is an image compression standard for bi-level images. It is suitable for both lossless and lossy compression. In its lossless mode JBIG2 typically generates files one third to one fifth the size of Fax Group 4 (TIFF).
Code
Document document = new Document();
// get number of pages/frames in JBIG2 file
string path = "in.jbig2";
int frameCount = ImageShape.GetFrameCount(path);
// iterate over frames
for (int frameIndex = 0; frameIndex < frameCount; frameIndex++)
{
// create the image (in full size)
ImageShape image = new ImageShape(path, frameIndex);
image.KeepAspectRatio = false;
// create new page and append to document
Page page = new Page(image.Width, image.Height);
document.Pages.Add(page);
page.VisualOverlay.Add(image);
}
// save
using (FileStream fs = new FileStream("out.pdf", FileMode.Create, FileAccess.Write))
{
document.Write(fs);
} 1 Document document = new Document();
2
3 // get number of pages/frames in JBIG2 file
4 string path = "in.jbig2";
5 int frameCount = ImageShape.GetFrameCount(path);
6
7 // iterate over frames
8 for (int frameIndex = 0; frameIndex < frameCount; frameIndex++)
9 {
10 // create the image (in full size)
11 ImageShape image = new ImageShape(path, frameIndex);
12 image.KeepAspectRatio = false;
13
14 // create new page and append to document
15 Page page = new Page(image.Width, image.Height);
16 document.Pages.Add(page);
17 page.VisualOverlay.Add(image);
18 }
19
20 // save
21 using (FileStream fs = new FileStream("out.pdf", FileMode.Create, FileAccess.Write))
22 {
23 document.Write(fs);
24 }