Spire.PDFViewer 7.12.6 supports obtaining the coordinates of a mouse click relative to the PDF page content

Spire.PDFViewer 7.12.6 supports obtaining the coordinates of a mouse click relative to the PDF page content

2024-02-07 07:20:34

We are happy to announce the release of Spire.PDFViewer 7.12.6. This version supports obtaining the coordinates of a mouse click relative to the PDF page content. More details are listed below.

Here is a list of changes made in this release

Category ID Description
New feature SPIREPDFVIEWER-454 Spire.PdfDocumentViewer supports obtaining the coordinates of a mouse click relative to the PDF page content.
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();
		}
	}
Click the link to get Spire.PDFViewer 7.12.6:
More information of Spire.PDFViewer new release or hotfix: