【问题标题】:Extract images from pdf in asp.net在asp.net中从pdf中提取图像
【发布时间】:2017-04-03 13:05:30
【问题描述】:

我想在我的网络表单中从 pdf 中提取文本。 以下是完美运行的代码,但它也拍摄了不相关的图片,如幻灯片的框架图片或没有数据的图片意味着黑色或白色的空白图片,我认为它也需要图片的背景。

PdfReader reader = new PdfReader(@"E:\Uni_Stuff\waleed 8th semester\DWDM\dwdm011.pdf");
        PRStream pst;
        PdfImageObject pio;
        PdfObject po;
        int n = reader.XrefSize; //number of objects in pdf document
        try
        {
            for (int i = 0; i < n; i++)
            {
                po = reader.GetPdfObject(i); //get the object at the index i in the objects collection
                if (po == null || !po.IsStream()) //object not found so continue
                    continue;
                pst = (PRStream)po; //cast object to stream
                PdfObject type = pst.Get(PdfName.SUBTYPE); //get the object type
                                                           //check if the object is the image type object
                if (type != null && type.ToString().Equals(PdfName.IMAGE.ToString()))
                {

                    pio = new PdfImageObject(pst); //get the image
                    byte[] imgdata = pio.GetImageAsBytes();
                    Image img = new Image();
                    img.ImageUrl = "data:image/jpeg;base64," + Convert.ToBase64String(imgdata);
                    PlaceHolder1.Controls.Add(img);
                }
            }
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }

现在我只想排除那些不相关的图片。我只想要那些有数据的图片。

【问题讨论】:

    标签: c# asp.net c#-4.0 c#-3.0


    【解决方案1】:

    我已经使用过这个库,我相信它可以满足你的所有需求。请尝试一下。

    http://www.winnovative-software.com/PdfImgExtractor.aspx

    【讨论】:

      猜你喜欢
      • 2011-01-29
      • 2020-04-04
      • 2019-11-14
      • 2012-10-21
      • 1970-01-01
      • 2012-02-01
      • 2013-12-22
      • 2015-07-01
      相关资源
      最近更新 更多