1、参考https://blog.csdn.net/XinShun/article/details/103902015
2、安装iText7包
3、JBig2Decoder.NET,注意项目需要为.net4.5版本
4、代码如下:
/// <summary>
/// JBIG2头
/// </summary>
private byte[] Header = new byte[] { 0x97, 0x4A, 0x42, 0x32, 0x0D, 0x0A, 0x1A, 0x0A, 0x01, 0x00, 0x00, 0x00, 0x01 };
/// <summary>
/// 导出JBIG2
/// </summary>
/// <param name="dictionary"></param>
public byte[] ExportJBIG2FromPDF(PdfDictionary dictionary)
{
PdfDictionary pdfStream = dictionary;
byte[] b;
try
{
// Get decoded stream bytes.
b = ((PdfStream)pdfStream).GetBytes();
}
catch (PdfException)
{
// Get originally encoded stream bytes
b = ((PdfStream)pdfStream).GetBytes(false);
}
//参考PDFReference_1-5.pdf
//由于JBIG2文件头在PDF中没有使用,
//这个头没有放在JBIG2流对象中,
//并被丢弃
//Since the JBIG2 file header is not used in PDF,
//this header is not placed in the JBIG2 stream object,
//and is discarded
var jbig2 = Header.Concat(b).ToArray();
// 解码
JBIG2StreamDecoder dec = new JBIG2StreamDecoder();
// JPEG格式数据
var jpegData = dec.decodeJBIG2(jbig2, ImageFormat.JPEG);
// 存为文件
//using (var fs = new FileStream(@"F:\test.jpg", FileMode.Create))
//{
// fs.Write(data, 0, data.Length);
// fs.Flush();
// fs.Close();
//}
return jpegData;
}