首页 新闻 会员 周边

iTextSharp获取pdf文件中指定关键字的坐标位置信息

0
悬赏园豆:20 [已解决问题] 解决于 2019-09-18 14:12

using iTextSharp.text;
using iTextSharp.text.pdf;
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

namespace Test1
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{

        //Document document = new Document();
        //document.AddKeywords("设计");
        //读pdf
        PdfReader pdfReader = new PdfReader(@"C:/Users/Administrator/Desktop/电气箱门.pdf");
        //保存新的pdf
        PdfStamper pdfStamper = new PdfStamper(pdfReader, new FileStream("C:/Users/Administrator/Desktop/output1.pdf",
                                                   FileMode.Create, FileAccess.Write, FileShare.None));
        //获取系统的字体
        BaseFont baseFont = BaseFont.CreateFont("C:\\Windows\\Fonts\\simhei.ttf", BaseFont.IDENTITY_H, 
                                           BaseFont.NOT_EMBEDDED);
        iTextSharp.text.Font font = new iTextSharp.text.Font(baseFont, 8);
        Phrase p = new Phrase("孤儿风", font);
        Phrase b = new Phrase("托儿索", font);
        PdfContentByte over = pdfStamper.GetOverContent(1);//PdfContentBye类,用来设置图像和文本的绝对位置
        ColumnText.ShowTextAligned(over, Element.ALIGN_CENTER, p, 516, 42,0);
        ColumnText.ShowTextAligned(over, Element.ALIGN_CENTER, b, 516, 12, 0);
        pdfStamper.Close();
        this.pdfViewer1.DocumentFilePath = "C:/Users/Administrator/Desktop/output1.pdf";
    }
}

}
我想获取pdf文件中关键字“设计“的坐标,然后根据坐标位置添加文本,而不是绝对位置添加,请问该怎么获取

午夜与鬼共舞丶的主页 午夜与鬼共舞丶 | 初学一级 | 园豆:134
提问于:2019-08-21 09:42
< >
分享
最佳答案
0

你看看这篇文章中获取指定字符串坐标的方法,https://blog.csdn.net/Eiceblue/article/details/53129594, 用的spire.pdf for .net,另外,这个文章( https://blog.csdn.net/ssw_jack/article/details/81198636 )里很详细的讲解了在PDF中坐标体系及应用。

收获园豆:20
E-iceblue | 菜鸟二级 |园豆:431 | 2019-08-21 13:53

有不有用iTextSharp.text.pdf;来获取坐标的方法,我知道spire.pdf for .net可以实现,但是spire.pdf for .net的正版太贵了,所以想换个方法来实现.

午夜与鬼共舞丶 | 园豆:134 (初学一级) | 2019-08-21 13:59
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册