从Access DB提取OLE对象(pdf) [英] Extract OLE Object (pdf) from Access DB

查看:73
本文介绍了从Access DB提取OLE对象(pdf)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在将几个旧的Access数据库升级/转换为MS-SQL.这些数据库中的许多数据库都有存储PDF文件的OLE对象字段.我正在寻找一种提取这些文件并将其存储在我们的SQL数据库中的方法.我见过类似的问题,可以回答您如何使用图像文件(jpg,bmp,gif等),但是我还没有找到一种适用于PDF的方法.

We are upgrading/converting several old Access databases to MS-SQL. Many of these databases have OLE Object fields that store PDF files. I'm looking for a way to extract these files and store them in our SQL database. I've seen similar questions that answer how you might do this with image files (jpg, bmp, gif, etc) but I haven't found a way that works with PDF.

推荐答案

我终于有了一些可以实现我想要的功能的代码.诀窍是确定OLE标头是哪一部分并将其删除.这是对我有用的东西(基于找到的代码

I finally got some code working for what I want it to do. The trick is determining what part is the OLE Header and removing it. Here is what is working for me (based on code found here)

    public static byte[] StripOleHeader(byte[] fileData)
    {
        const string START_BLOCK = "%PDF-1.3";
        int startPos = -1;

        Encoding u8 = Encoding.UTF7;
        string strEncoding = u8.GetString(fileData);

        if (strEncoding.IndexOf(START_BLOCK) != -1)
        {
            startPos = strEncoding.IndexOf(START_BLOCK);
        }

        if (startPos == -1)
        {
            throw new Exception("Could not find PDF Header");
        }

        byte[] retByte = new byte[fileData.LongLength - startPos];

        Array.Copy(fileData, startPos, retByte, 0, fileData.LongLength - startPos);

        return retByte;
    }

请注意,这仅适用于PDF文件.

Note that this only works for PDF files.

这篇关于从Access DB提取OLE对象(pdf)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆