Patagames Software Support Forum
»
Pdfium.Net SDK
»
FAQ
»
How to insert image at the mouse click position in WPF Pdf Viewer?
Rank: Administration
Groups: Administrators
Joined: 1/5/2016(UTC) Posts: 1,104
Thanks: 7 times Was thanked: 129 time(s) in 126 post(s)
|
Question:How to insert image at the mouse click position in WPF Pdf Viewer? AnswerSince v3.40.2704 you can use the following code Code:private void pdfViewer1_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
//Determine the page where the mouse was clicked
int pageNum = pdfViewer1.PointInPage(e.GetPosition(pdfViewer1));
var page = pdfViewer1.Document.Pages[pageNum];
//Translate the mouse coordinates to the page's coordinate system
var pointOnPage = pdfViewer1.ClientToPage(pageNum, e.GetPosition(pdfViewer1));
//Load bitmap from file, create image object and insert it into page
var bmp = PdfBitmap.FromFile(@"d:\0\img1.png");
var imageObj = PdfImageObject.Create(pdfViewer1.Document, bmp, (float)pointOnPage.X, (float)pointOnPage.Y);
page.PageObjects.Add(imageObj);
//Generate page content
page.GenerateContent();
//And invalidate
pdfViewer1.ClearRenderBuffer();
pdfViewer1.InvalidateVisual();
//Save document
pdfViewer1.Document.Save(@"d:\0\6\test.pdf", SaveFlags.NoIncremental);
}
|
|
|
|
Patagames Software Support Forum
»
Pdfium.Net SDK
»
FAQ
»
How to insert image at the mouse click position in WPF Pdf Viewer?
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.
Important Information:
The Patagames Software Support Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close