首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >从选定区域或坐标中的pdf中提取文本和图像

从选定区域或坐标中的pdf中提取文本和图像
EN

Stack Overflow用户
提问于 2010-03-11 20:07:32
回答 1查看 2.2K关注 0票数 2

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

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

如果有人能帮我解决这个问题,那就太好了。你能分享一下你对如何在.net中实现这一点的想法和建议吗?

致敬,Arun.M

EN

回答 1

Stack Overflow用户

发布于 2011-03-23 20:52:41

这段代码从pdf中提取图像

代码语言:javascript
运行
复制
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();
        }
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2424726

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档