zoukankan      html  css  js  c++  java
  • Acrobat 转换pdf到png的另一种方法

    此方法效率较低,大概2秒转3页pdf成png图片,但是可以保证图片质量很高,分辨率很高。有优化的地方,但没时间研究。先放代码吧。

     前提是安装 acrobat 11(即acrobat xi)

      CAcroApp mApp = new AcroApp();
                mApp.Hide();
                String szPdfPathConst = AppDomain.CurrentDomain.BaseDirectory + @"深入浅出WPF.pdf";
                AcroAVDoc g_AVDoc = new AcroAVDoc();
                //open the PDF
                if (g_AVDoc.Open(szPdfPathConst, ""))
                {
                    int currentIndex = 0;
                    bool formDataExists = true;
    
    
                    Object newDoc = null;
    
    
                    if (g_AVDoc.IsValid())
                    {
    
                        CAcroPDDoc pdDoc = (CAcroPDDoc)g_AVDoc.GetPDDoc();
                        int iNum = pdDoc.GetNumPages();
                        Object jsObj = pdDoc.GetJSObject();
                        if (formDataExists)
                        {
                            Type T = jsObj.GetType();
    
                            object[] extractPagesParam = { currentIndex,iNum-1 };
                            newDoc = T.InvokeMember(
                                "extractPages",
                                BindingFlags.InvokeMethod |
                                BindingFlags.Public |
                                BindingFlags.Instance,
                                null, jsObj, extractPagesParam); 
    
                            String newFileName = AppDomain.CurrentDomain.BaseDirectory + "data\" + currentIndex + ".png";
                            Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "data");
    
    
                            object[] saveAsParam = { newFileName, "com.adobe.acrobat.png" };
                            T.InvokeMember(
                            "saveAs",
                            BindingFlags.InvokeMethod |
                            BindingFlags.Public |
                            BindingFlags.Instance,
                            null, newDoc, saveAsParam);
                            formDataExists = currentIndex != iNum - 1;
    
    
                            object[] closeDocParam = { true };
                            T.InvokeMember(
                                    "closeDoc",
                                    BindingFlags.InvokeMethod |
                                    BindingFlags.Public |
                                    BindingFlags.Instance,
                                    null, newDoc, closeDocParam);
    
                            currentIndex++;
                        }
                    }
                }
                mApp.CloseAllDocs();
                mApp.Exit();
    

      感谢阅读的人,希望可以帮到你。 

  • 相关阅读:
    Invalid command 'RewriteEngine'解决办法
    JEZ reCAPTCHA 谷歌验证码插件及使用方法
    一段图片预加载的代码
    Fancybox
    Silverlight4 beta 中的.net ria service自定义用户身份验证之改变
    .net ria service 数据验证(7)
    .net ria services 自定义函数(9)
    C#开发ActiveX控件及制作CAB包
    Silverlight 3.0 中的 Local Connection
    Silverlight3端操作数据库(5)
  • 原文地址:https://www.cnblogs.com/congqiandehoulai/p/6429357.html
Copyright © 2011-2022 走看看