PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Mon Jul 15, 2024 2:50 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Tue Sep 02, 2014 3:54 pm 
Offline

Joined: Mon Aug 25, 2014 4:44 pm
Posts: 8
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


Top
 Profile  
Reply with quote  
PostPosted: Wed Sep 03, 2014 11:35 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Wed Sep 03, 2014 1:23 pm 
Offline

Joined: Mon Aug 25, 2014 4:44 pm
Posts: 8
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


Top
 Profile  
Reply with quote  
PostPosted: Thu Sep 04, 2014 5:39 pm 
Offline

Joined: Mon Aug 25, 2014 4:44 pm
Posts: 8
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


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 08, 2014 7:52 am 
Offline
PDFsharp Guru
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 3101
Location: Cologne, Germany
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 08, 2014 2:01 pm 
Offline

Joined: Mon Aug 25, 2014 4:44 pm
Posts: 8
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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 74 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group