PDFsharp & MigraDoc Forum https://forum.pdfsharp.net/ |
|
Existing Password Protection Disappearing on Save https://forum.pdfsharp.net/viewtopic.php?f=2&t=2003 |
Page 1 of 1 |
Author: | joshy [ Wed May 02, 2012 1:06 am ] |
Post subject: | Existing Password Protection Disappearing on Save |
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 |
Author: | joshy [ Thu May 03, 2012 1:52 am ] |
Post subject: | Re: Existing Password Protection Disappearing on Save |
Anyone Help?! |
Author: | eks [ Mon May 07, 2012 5:48 pm ] |
Post subject: | Re: Existing Password Protection Disappearing on Save |
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? |
Author: | joshy [ Tue May 08, 2012 12:39 am ] |
Post subject: | Re: Existing Password Protection Disappearing on Save |
ended up solving the problem myself.... http://stackoverflow.com/questions/1044 ... 7#10491007 |
Page 1 of 1 | All times are UTC |
Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |