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文件中关键字“设计“的坐标,然后根据坐标位置添加文本,而不是绝对位置添加,请问该怎么获取
你看看这篇文章中获取指定字符串坐标的方法,https://blog.csdn.net/Eiceblue/article/details/53129594, 用的spire.pdf for .net,另外,这个文章( https://blog.csdn.net/ssw_jack/article/details/81198636 )里很详细的讲解了在PDF中坐标体系及应用。
有不有用iTextSharp.text.pdf;来获取坐标的方法,我知道spire.pdf for .net可以实现,但是spire.pdf for .net的正版太贵了,所以想换个方法来实现.