Hi
I am testing free trial version of Spire.PdfViewer.Wpf. The question is how to get actual x,y coordinate regardless the zoom or the size (similar to pointF=page.FindText(“Text”)) at MouseUp event.
Thanks
Rami
private void ConvertPDFtoImage(string FullFilePath)
{
//pdf file
String file = FullFilePath;
strSourcefile = file;
//open pdf document
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(file);
////save to images
for (int i = 0; i < doc.Pages.Count; i++)
{
String fileName = String.Format("C:\\Temp\\Converted-{0}.tif", i);
using (Image image = doc.SaveAsImage(i,PdfImageType.Bitmap,300,300))
{
image.Save(fileName, System.Drawing.Imaging.ImageFormat.Tiff);
}
}
doc.Close();
doc.Dispose();
}
private void pictureBox1_MouseDoubleClick(object sender, MouseEventArgs e)
{
Console.WriteLine("X: " + e.Location.X.ToString() + " Y: " + e.Location.Y.ToString());
}
private void pictureBox1_MouseDoubleClick(object sender, MouseEventArgs e)
{
int x = e.Location.X - this.pictureBox1.Location.X;
int y = e.Location.Y - this.pictureBox1.Location.Y;
Console.WriteLine("X: " + x.ToString() + " Y: " + y.ToString());
}
// panel1
//
this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panel1.AutoScroll = true;
this.panel1.Controls.Add(this.pictureBox2);
this.panel1.Location = new System.Drawing.Point(577, 68);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(413, 565);
this.panel1.TabIndex = 5;
//
// pictureBox2
//
this.pictureBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.pictureBox2.Cursor = System.Windows.Forms.Cursors.Cross;
this.pictureBox2.Location = new System.Drawing.Point(3, 3);
this.pictureBox2.Name = "pictureBox2";
this.pictureBox2.Size = new System.Drawing.Size(368, 523);
this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBox2.TabIndex = 0;
this.pictureBox2.TabStop = false;
this.pictureBox2.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.pictureBox2_MouseDoubleClick);
this.pictureBox2.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox2_MouseMove);
private void pictureBox2_MouseDoubleClick(object sender, MouseEventArgs e)
{
int x = e.Location.X - this.pictureBox2.Location.X;
int y = e.Location.Y - this.pictureBox2.Location.Y;
string outFilename = @"C:\\Workspace\\Output" + ".pdf";
DrawLines(strSourcefile, outFilename, x, y);
}
private void DrawLines(string strFileIn, string strOutFile, int LineX, int LineY)
{
//Create a pdf document.
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(strFileIn);
PdfPageBase page0 = doc.Pages[0];
PdfMargins margin = doc.PageSettings.Margins;
page0.Canvas.DrawLine(new PdfPen(PdfBrushes.Red, 1), new PointF(LineX, LineY), new PointF(LineX, LineY + 30));
page0.Canvas.DrawLine(new PdfPen(PdfBrushes.Red, 1), new PointF(LineX, LineY), new PointF(LineX + 30, LineY));
doc.SaveToFile(strOutFile, FileFormat.PDF);
doc.Dispose();
System.Diagnostics.Process.Start(strOutFile);
}
private float m_ImageHeight = 0;
private float m_ImageWidth = 0;
private float m_PageHeight = 0;
private float m_PageWidth = 0;
PdfDocument pdf = new PdfDocument();
pdf.LoadFromFile(strSourcefile);
this.m_PageHeight = pdf.Pages[0].ActualSize.Height;
this.m_PageWidth = pdf.Pages[0].ActualSize.Width;
pdf.SaveAsImage(0, PdfImageType.Bitmap,300,300).Save(imagefile, ImageFormat.Tiff);
Image loImage = Image.FromFile(imagefile);
this.m_ImageHeight = loImage.Height;
this.m_ImageWidth = loImage.Width;
private void pictureBox1_MouseDoubleClick(object sender, MouseEventArgs e)
{
int x = e.Location.X ;
int y = e.Location.Y;
this.textBox1.Text = "X: " + x.ToString() + " Y: " + y.ToString();
float lfX = x * m_PageWidth / m_ImageWidth;
float lfY = y * m_PageHeight / m_ImageHeight;
DrawLines(strSourcefile, outFilename, lfX, lfY);
}
public Image ScaleImage(Image imageSource, decimal decPercentage)
{
int intNewWidth = Convert.ToInt32(imageSource.Width * decPercentage);
int intNewHeight = Convert.ToInt32(imageSource.Height * decPercentage);
Image newImage = new Bitmap(intNewWidth, intNewHeight);
using (Graphics graphics = Graphics.FromImage(newImage))
graphics.DrawImage(imageSource, 0, 0, intNewWidth, intNewHeight);
m_ImageHeight = intNewHeight;
m_ImageWidth = intNewWidth;
return newImage;
}