首页 > 解决方案 > 使用 itext7 在 net core 中读取 PDF 返回“\n\n\n\n\n....”

问题描述

我有一个 netcore 3 应用程序来阅读和拆分包含我工作的一些公司的薪水的 PDF。

自上次构建以来,此应用程序运行良好……我的方式是,PDF 阅读器开始无法解析任何 PDF 的内容。

PDF 仅使用意大利语单词构建,没有特殊字符。几张桌子和一个标志。由于隐私,我无法附上它。

    public PaycheckSplitter Read()
    {
        using (var reader = new PdfReader(new MemoryStream(this._stream)))
        {
            var doc = new PdfDocument(reader);


            this.Paycheck = new PaychecksCollection();

            for (int i = 1; i <= doc.GetNumberOfPages(); i++)
            {
                PdfPage page = doc.GetPage(i);

                string text = PdfTextExtractor.GetTextFromPage(page, new LocationTextExtractionStrategy());
                if (text.Contains(Consts.BpEnd)) break;

                // trying to find something by regex... btw text contains only a sequence of \n\n\n\n...
                string cf = Consts.CodFiscale.Match(text).Value;                     
                this.Paychecks.Add(new Paycheck(cf), i);
            }
            doc.Close();
        }

        return this;
    }

有什么我能做的吗?据我所知......免费阅读PDF文本的唯一也是最好的方法是iText7......

标签: c#pdfitext7

解决方案


推荐阅读