Spire.PDFViewer 7.12.6 已发布。本次更新新增支持获取鼠标点击时相对于 PDF 页面内容的坐标。详情请阅读以下内容。
新功能:
- Spire.PdfDocumentViewer控件支持了获取鼠标点击时相对于PDF页面内容的坐标。
private void Form1_Load(object sender, EventArgs e)
{
this.pdfDocumentViewer1.LoadFromFile("1.pdf");
this.pdfDocumentViewer1.MouseDown += new MouseEventHandler(PV_Click);
}
private void PV_Click(object sender, MouseEventArgs e)
{
string outputFile = "out.Pdf";
string outputFile_TXT = "out.txt";
File.Delete(outputFile_TXT);
if (e.Button == MouseButtons.Left)
{
PointF[] controlPositions = new PointF[] { e.Location};
Spire.PdfViewer.Forms.PagePosition[] pagePositions = this.pdfDocumentViewer1.ControlToPage(controlPositions);
string fileName = this.pdfDocumentViewer1.FileName;
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(fileName,FileFormat.PDF);
PdfPageBase page = doc.Pages[pagePositions[0].PageIndex];
RectangleF bounds = new RectangleF(pagePositions[0].Position, new SizeF(100, 100));
PdfTextExtractor textExtractor = new PdfTextExtractor(page);
PdfTextExtractOptions option = new PdfTextExtractOptions();
option.ExtractArea = bounds;
string text = textExtractor.ExtractText(option);
PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 11);
PdfTextWidget pdfTextbox = new PdfTextWidget();
pdfTextbox.Font = font;
pdfTextbox.Brush = PdfBrushes.Red;
pdfTextbox.Text = "stamp";
pdfTextbox.Draw(page, bounds);
doc.Pages[pagePositions[0].PageIndex].Canvas.DrawRectangle(PdfPens.Red, bounds);
doc.SaveToFile(outputFile);
File.AppendAllText(outputFile_TXT, "Position: " + pagePositions[0].Position.ToString() + "\ntext:\r\n " + text);
MessageBox.Show("finish");
doc.Dispose();
}
}
获取Spire.PDFViewer 7.12.6请点击: