【问题标题】:Extract text and image from a pdf in a selected area or coordinates从选定区域或坐标中的 pdf 中提取文本和图像
【发布时间】:2023-03-23 08:52:01
【问题描述】:

我有从 pdf 文件中的特定区域提取文本和图像的特定要求。该区域可能是选定的或突出显示的,或者来自给定的一组坐标。

当我经历时,所有方法都是从不在指定位置的 PDF 中完全提取图像和文本。 我尝试了 iTextSharp、Syncfussion、Apose,但找不到更好的方法。

如果有人能在这方面帮助我,那就太好了。您能否分享您对如何在 .net 中实现此功能的想法和建议。

问候, 阿伦.M

【问题讨论】:

    标签: asp.net pdf acrobat


    【解决方案1】:

    这段代码从pdf中提取图像

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Drawing.Imaging;
    using System.IO;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using Bytescout.PDFExtractor;
    
    namespace ExtractAllImages
    {
        public partial class _Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                // This test file will be copied to the project directory on the pre-build event (see the project properties).
                String inputFile = Server.MapPath("sample1.pdf");
    
                // Create Bytescout.PDFExtractor.ImageExtractor instance
                ImageExtractor extractor = new ImageExtractor();
                extractor.RegistrationName = "demo";
                extractor.RegistrationKey = "demo";
    
                // Load sample PDF document
                extractor.LoadDocumentFromFile("sample1.pdf");
    
                Response.Clear();
    
                int i = 0;
    
                // Initialize image enumeration
                if (extractor.GetFirstImage())
                {
                    do
                    {
                        if (i == 0) // Write the fist image to the Response stream
                        {
                            string imageFileName = "image" + i + ".png";
    
                            Response.Write("<b>" + imageFileName + "</b>");
    
                            Response.ContentType = "image/png";
                            Response.AddHeader("Content-Disposition", "inline;filename=" + imageFileName);
    
                            // Write the image bytes into the Response output stream
                            Response.BinaryWrite(extractor.GetCurrentImageAsArrayOfBytes());
                        }
    
                        i++;
    
                    } while (extractor.GetNextImage()); // Advance image enumeration
                }
    
                Response.End();
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-05
      • 1970-01-01
      • 2012-01-04
      • 2022-10-15
      • 1970-01-01
      • 2014-05-18
      • 1970-01-01
      相关资源
      最近更新 更多