PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

freehand drawing (rectangle)
https://forum.pdfsharp.net/viewtopic.php?f=2&t=2916
Page 1 of 1

Author:  campagnolo_1 [ Tue Sep 02, 2014 3:54 pm ]
Post subject:  freehand drawing (rectangle)

Hi all,

still fairly new to PDFsharp and working on my first project. I made a windows form project that will display a PDF and so far that is working nicely. :D
Now what I want to do is to enable the user to draw a recangle on the PDF (which is a scanned fax) in order to block out certain information. Unfortunately I can't figure out the freehand part of the drawing. I know how to draw a rectangle by giving specific coordinates, but since the faxes are not always the same and may vary in length, I need the user to be able to draw the rectangle wherever it is needed (freehand, on the fly).
Is this possible with PDFsharp? If so, I would be grateful for any suggestions you may have.

Thanks,

Chris

Author:  Thomas Hoevel [ Wed Sep 03, 2014 11:35 am ]
Post subject:  Re: freehand drawing (rectangle)

Hi!
campagnolo_1 wrote:
Now what I want to do is to enable the user to draw a recangle on the PDF (which is a scanned fax) in order to block out certain information.
Users will then be able to remove the rectangles from the PDF and will see the original information.

Better approach: obtain the scanned faxes as image files (e.g. TIFF), display those to the user and add the rectangles.
Then create the PDF from a modified image where the blackened information is irreversibly lost.

Author:  campagnolo_1 [ Wed Sep 03, 2014 1:23 pm ]
Post subject:  Re: freehand drawing (rectangle)

Thomas,

thank you for the reply. As you realized, I'm trying to do a "redaction" here. I know that just putting a black box over something isn't really redacting, but the final step is to password protect the PDF with a random password generator. So the PDF theoretically couldn't be tampered with.
But I like your suggestion to remove certain parts completely. Unfortunately I have no idea how I would go about implementing your idea. Do you by any chance have an example I could look at and use as a starting point?

Thanks,

Chris

Author:  campagnolo_1 [ Thu Sep 04, 2014 5:39 pm ]
Post subject:  Re: freehand drawing (rectangle)

Thomas,

I looked into the tiff conversion, and even though I found some code that I was able to get to work for me, it simply isn't an option in terms of workflow. It would make a currently simple (albeit slightly flawed) process extremely convoluted.

So I looked some more into trying to draw a simple box onto the PDF but don't think I've made much headway.
I put in a delegate for a mouse event like this:
Code:
        //mouseevent
            this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.acroviewer_MouseDown);


Then I created the event handler. I just did a simple message box to identify the different mouse events:
Code:
private void acroviewer_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
switch (e.Button)
{
case MouseButtons.Left:
MessageBox.Show(this,"Left Button Click");
break;
case MouseButtons.Right:
MessageBox.Show(this,"Right Button Click" );
break;
case MouseButtons.Middle:
break;
default:
break;
}
 
}


The events trigger accordingly, but only if I clicked on the frame of my PDF Viewer. Nothing happened when I clicked inside the actual viewing area. I have no idea why that is.
So I tried to come with some code for drawing, but since the mouse event is only working on the frame, I'm not sure if the code would work or not. On top of that I'm not sure how to declare the gfx in my code context:
Code:
 bool draw = false;

       
       private void acroviewer_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            draw = true;
            XPen pen = new XPen(XColors.Black, Math.PI);
            gfx.DrawRectangle(pen, e.X, e.Y, 2, 2);
            gfx.DrawRectangle(XBrushes.Black, e.X, e.Y, 2, 2);
            gfx.Save();
         }


That's where I'm at right now and I surely could use some help!

Thanks,

Chris

Author:  Thomas Hoevel [ Mon Sep 08, 2014 7:52 am ]
Post subject:  Re: freehand drawing (rectangle)

You're actual viewing area is a window drawn by Adobe Reader. Adobe Reader loaded a copy of your PDF file.

It should be possible to subclass that viewer window to get the mouse clicks, but it will still be difficult to get the zoom factor, the page, the scroll bar positions etc.
You can then change the PDF file to come to the next hurdle: how to get Adobe Reader to refresh the PDF file?

IMHO you are going in the wrong direction.

Author:  campagnolo_1 [ Mon Sep 08, 2014 2:01 pm ]
Post subject:  Re: freehand drawing (rectangle)

Thomas,

that's good insight. Thanks for pointing out the concerns. I guess I'll have to get back to the drawing board and see if I can't come up with a better way, maybe even make the tiff conversion a viable solution.

Chris

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/