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);
}
现在我只想排除那些不相关的图片。我只想要那些有数据的图片。