PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Apr 26, 2024 11:49 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Wed May 02, 2012 1:06 am 
Offline

Joined: Wed May 02, 2012 12:54 am
Posts: 3
Hi Guys,

I am using PDFSharp in 2 different applications for 2 different reasons. The first is password protect a document and the second is to watermark the document. These processes both work individually in there own applications however the problem is that application 1 only knows about the password and application 2 only knows about the watermark, application 1 uses a default owner password and a dynamic user password, application 2 opens the document with the owner password to apply the watermark but can not reapply the passwords (ie the doc is saved without a password) is there a way of keeping the security settings when applying the watermark?

This is the watermarking code i am using
Code:
 private void CreateWatermark(string file, string watermark)
        {
            log.Write(string.Format("Invoking CreateWatermark"), Category.General, Priority.Low, 2, TraceEventType.Verbose);
            const int emSize = 150;
            var font = new XFont("Times New Roman", emSize, XFontStyle.BoldItalic);

            PdfDocument document = PdfReader.Open(file, "<password>");

            if (document.Version < 14)
                document.Version = 14;

            for (int idx = 0; idx < document.Pages.Count; idx++)
            {
                PdfPage page = document.Pages[idx];

                XGraphics gfx = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Append);

                // Get the size (in point) of the text
                XSize size = gfx.MeasureString(watermark, font);

                // Define a rotation transformation at the canter of the page
                gfx.TranslateTransform(page.Width/2, page.Height/2);
                gfx.RotateTransform(-Math.Atan(page.Height/page.Width)*180/Math.PI);
                gfx.TranslateTransform(-page.Width/2, -page.Height/2);

                // Create a graphical path
                var path = new XGraphicsPath();

                // Add the text to the path
                path.AddString(watermark, font.FontFamily, XFontStyle.BoldItalic, 150,
                               new XPoint((page.Width - size.Width)/2, (page.Height - size.Height)/2),
                               XStringFormats.Default);

                // Create a dimmed red pen and brush
                var pen = new XPen(XColor.FromArgb(50, 75, 0, 130), 3);
                XBrush brush = new XSolidBrush(XColor.FromArgb(50, 106, 90, 205));

                // Stroke the outline of the path
                gfx.DrawPath(pen, brush, path);
            }


            log.Write(string.Format("Saving File with watermark '" + watermark + "'"), Category.General, Priority.Low);
            document.Save(file);
}


Thanks for your help,
Josh


Top
 Profile  
Reply with quote  
PostPosted: Thu May 03, 2012 1:52 am 
Offline

Joined: Wed May 02, 2012 12:54 am
Posts: 3
Anyone Help?!


Top
 Profile  
Reply with quote  
PostPosted: Mon May 07, 2012 5:48 pm 
Offline

Joined: Fri May 04, 2012 6:59 pm
Posts: 4
Hi Josh

I didn't work with password nor watermark yet, but I'm wondering:
1) if you can apply watermark to the document and after that protect it.
2) if you need to protect the document and then apply the watermark... Is there a posibility to recieve the security object on the 2nd app?


Top
 Profile  
Reply with quote  
PostPosted: Tue May 08, 2012 12:39 am 
Offline

Joined: Wed May 02, 2012 12:54 am
Posts: 3
ended up solving the problem myself....

http://stackoverflow.com/questions/1044 ... 7#10491007


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 354 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