国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

ITEXTSHARP學(xué)習(xí)整理

2019-11-17 02:22:57
字體:
供稿:網(wǎng)友

ITEXTSHARP學(xué)習(xí)整理

  學(xué)習(xí)的版本iTextSharp.5.5.5。

關(guān)于獲取PDF中的圖片資源

  

        /// <summary>        /// 將PDF中的圖片資源轉(zhuǎn)換成二進(jìn)制        /// </summary>        /// <param name="filePath"></param>        /// <returns></returns>        public List<byte[]> ConvertImageData(string filePath)        {            List<byte[]> lst = new List<byte[]>();            using (PdfReader pdf = new PdfReader(filePath))            {                for (int i = 1; i <= pdf.NumberOfPages; i++)                {                   byte[] result = null;                PdfDictionary page = pdf.GetPageN(pageNum);                PdfObject obj = FindImageInPDFDictionary(page);                if (obj != null)                {                 PdfImageObject imageObj = null;                  int XrefIndex = Convert.ToInt32(((PRIndirectReference)obj).Number.ToString(System.Globalization.CultureInfo.InvariantCulture));                   PdfObject pdfObj = pdf.GetPdfObject(XrefIndex);                   PRStream pdfStrem = (PRStream)pdfObj;                   imageObj = new PdfImageObject(pdfStrem);                   result = imageObj.GetImageAsBytes();                }                  lst.Add(result);                }            }            return lst;        }

       /// <summary>       /// 提取圖片元素       /// </summary>       /// <param name="pg"></param>       /// <returns></returns>        private static PdfObject FindImageInPDFDictionary(PdfDictionary pg)        {             PdfDictionary res = pg.GetAsDict(PdfName.RESOURCES);            PdfDictionary xobj = res.GetAsDict(PdfName.XOBJECT);            if (xobj != null)            {                foreach (PdfName name in xobj.Keys)                {                    PdfObject obj = xobj.Get(name);                    if (obj.IsIndirect())                    {                        PdfDictionary tg = (PdfDictionary)PdfReader.GetPdfObject(obj);                        PdfName type = (PdfName)PdfReader.GetPdfObject(tg.Get(PdfName.SUBTYPE));                                              if (PdfName.IMAGE.Equals(type))                        {                            return obj;                        }// image inside a form                        else if (PdfName.FORM.Equals(type) || PdfName.GROUP.Equals(type))                        {                            return FindImageInPDFDictionary(tg);                        }                    }                }            }            return null;        }

  

  


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 福建省| 新泰市| 波密县| 锦屏县| 红河县| 咸丰县| 上杭县| 米脂县| 西峡县| 信宜市| 绥滨县| 嘉义市| 南漳县| 台中市| 喜德县| 台湾省| 大悟县| 玉山县| 怀化市| 湘乡市| 郯城县| 墨竹工卡县| 仁怀市| 文成县| 林西县| 五台县| 论坛| 盘山县| 砀山县| 四川省| 彭州市| 乐至县| 荃湾区| 台南市| 河西区| 呼图壁县| 睢宁县| 梅河口市| 永年县| 潮州市| 邮箱|