logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Paul Rayman  
#1 Posted : Wednesday, November 7, 2018 11:31:11 PM(UTC)
Paul Rayman

Rank: Administration

Groups: Administrators
Joined: 1/5/2016(UTC)
Posts: 936

Thanks: 3 times
Was thanked: 112 time(s) in 109 post(s)
Question:
How to insert image at the mouse click position in WPF Pdf Viewer?

Answer
Since 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);
}
Users browsing this topic
Similar Topics
[obsolete]How to insert image at the mouse click position in WPF Pdf Viewer? (FAQ)
by Paul Rayman 9/4/2016 1:21:50 AM(UTC)
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.