转换使用iTextSharp c#格式化的PDF tp文本 [英] Convert PDF tp text formatted using iTextSharp c#

查看:116
本文介绍了转换使用iTextSharp c#格式化的PDF tp文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好



使用此代码,我可以从PDF文档中获取纯文本。



我会想知道如何使用点数和换行符等格式化文本?





非常感谢。



对不起我的英语





Hello

With this code I get plain text from a PDF document.

I would like to know how to get the text formatted with the points, and line break, etc.?


Thanks a lot.

Sorry for my English


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using iTextSharp.text.pdf;
using iTextSharp.text.pdf.parser;
using System.Text;
namespace Sample_2012_Web_App

{
    public partial class WebForm1 : System.Web.UI.Page

    {
        protected void Page_Load(object sender, EventArgs e)

        {

        }

        protected void btnShowContent_Click(object sender, EventArgs e)

        {

            if (PDFFileUpload.HasFile)

            {

                string strPDFFile = PDFFileUpload.FileName;

                PDFFileUpload.SaveAs(Server.MapPath(strPDFFile));

                StringBuilder strPdfContent = new StringBuilder();

                PdfReader reader = new PdfReader(Server.MapPath(strPDFFile));

                for (int i = 1; i <= reader.NumberOfPages; i++)

                {

                    ITextExtractionStrategy objExtractStrategy = new SimpleTextExtractionStrategy();

                    string strLineText = PdfTextExtractor.GetTextFromPage(reader, i, objExtractStrategy);

                    strLineText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(strLineText)));

				
					
                    strPdfContent.Append(strLineText);

                    reader.Close();

                    strPdfContent.Append("<br/>");
                     

                }
				
                lblPdfContent.Text = strPdfContent.ToString();
                

            }

        }

    }

}

推荐答案

这篇关于转换使用iTextSharp c#格式化的PDF tp文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆