2017-04-03 11 views
0

私のWebフォームでpdfからテキストを抽出したいと思います。 以下は完璧に動作するコードですが、スライドのフレーム画像やデータがない画像は無関係です。黒い白や白の空白の画像を意味します。画像の背景も同じだと思います。asp.netの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); 
     } 

ここで、無関係な画像のみを除外したいだけです。私はデータを持っている写真だけを欲しい。

答えて

関連する問題