get deflate stream 的代码
来源:互联网 发布:mac 看不到隐藏文件夹 编辑:程序博客网 时间:2024/04/28 20:27
最近忙别的,没空关心pdf了。既然有人需要;找了找,大概是这块了
//定义一个识别stream 的正则表达式;自己定义的,未必通用
Regex streamRegex = new Regex(@"<<[^>]*//FlateDecode[^>]*>>/s*stream/s*/n(.*?)/s*endstream", RegexOptions.Singleline);
。。。。。
match = streamRegex.Match(pdfContent);
if (match.Length > 0)
{
pdfContent = match.Groups[1].Value;
documentContentStart += (match.Groups[1].Index + 2);
strLen = match.Groups[1].Length;
if (strLen < 2) {
strContent = "";
}
byte[] bufTemp = new byte[strLen - 2];
try
{
for (int i =0; i < strLen - 2; i++)
{
bufTemp[i] = pdfBuf[documentContentStart + i];
}
MemoryStream ms = new MemoryStream();
ms.Write(bufTemp, 0, bufTemp.Length);
ms.Position = 0;
//解压缩
DeflateStream deStream = new DeflateStream(ms, CompressionMode.Decompress, true);
//GZipStream deStream = new GZipStream(ms, CompressionMode.Decompress);
deStream.Flush();
int nSize = 16 * 1024;
byte[] decompressedBuffer = new byte[nSize]; //16*1024 + 256 Maxium
int totalCount = deStream.Read(decompressedBuffer, 0, nSize);
//int totalCount = ReadAllBytesFromStream(deStream, decompressedBuffer);
deStream.Close();
pdfContent = Encoding.Default.GetString(decompressedBuffer, 0, totalCount);
File.WriteAllText("c:/tmp/pdftxt.txt", pdfContent);
//strContent = strContent + "<P>" + pdfContent + "</P>";
}
catch (Exception ex)
{
throw new Exception("error inflate string", ex);
}
}
}
解压出来的文本是要继续分析的;算法比较复杂,需要用到矩阵的计算用来判断各段文本的位置。暂时没空搞了。
- get deflate stream 的代码
- -2 internal error : deflate stream corrupt
- httpClient的get请求 请求头gzip和deflate的乱码解决方案
- apache的deflate模块
- IE下的deflate模式
- 抓取网页的gzip/deflate
- 简单的理解deflate算法
- asp.net获取Post和Get数据的方法(Stream)
- Zlib的deflate, z_stream结构的使用
- 使用DEFLATE的IP有效载荷压缩
- apcache的gzip与deflate对比
- POST、GET的测试代码
- Program Stream 解析代码
- 找不到前几天的stream解压部分代码了
- Java 8 stream: 让你的代码更简洁
- Get the image stream use liferay API
- Get stream replication state from standby
- FMS代码实现PULL STREAM
- 用多种方案设计1位全减器电路
- 解决升级U910_64后不能看SOPCAST等无法正常运行某些32位程序的方法
- java字节流、字符流
- JavaScript实现光标离开时弹出对话框
- 《问说》原文及翻译
- get deflate stream 的代码
- Java持久化框架(MYSQL Annotation JPA)添加记录,出现表格不存在异常的解决方法?
- c#的3des加密解密算法备忘
- tomcat中设置新路径的方法
- Windows错误代码大全
- asp.net中 数据绑定 里用的三目运算符
- 理想化的计算机科学知识体系
- Symbian 应用程序中的UID
- 程序员"说书"--杂侃一