Products
PDFKit.NET 4.0
Created
11/10/2011
Tags
Images

This c# 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).

C# code sample // get number of pages/frames in JBIG2 file string path = @"....\multipage.jb2"; 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); } ]]>

VB.NET code sample ' get number of pages/frames in JBIG2 file Dim path As String = "....\multipage.jb2" Dim frameCount As Integer = ImageShape.GetFrameCount(path)

' iterate over frames For frameIndex As Integer = 0 To frameCount - 1 ' create the image (in full size) Dim image As New ImageShape(path, frameIndex) image.KeepAspectRatio = False

' create new page and append to document
Dim page As New Page(image.Width, image.Height)
document.Pages.Add(page)
page.VisualOverlay.Add(image)

Next

' save Using fs As New FileStream("....\out.pdf", FileMode.Create, FileAccess.Write) document.Write(fs) End Using ]]>