public MsgShowToolWindow(PDFDocument document) { this.Document = document; }
public WndEnterPasswordViewModel(PDFDocument document) { this._doc = document; }
public MsgShowSecurity(PDFDocument document) : base(document) { }
public MsgShowEnterPassword(PDFDocument document) { this.Document = document; }
public MsgShowRotatePages(PDFDocument document) : base(document) { }
public MsgShowBurst(PDFDocument document) : base(document) { }
public MsgShowInsertPages(PDFDocument document) : base(document) { }
public MsgShowDeletePages(PDFDocument document) : base(document) { }
public MsgShowExtractPages(PDFDocument document) : base(document) { }
/// <summary> /// Encrypt a PDF document with a user or owner password. /// </summary> /// <param name="userPassword">Password to open the document. Set null if not needed.</param> /// <param name="ownerPassword">Password to edit the document. Set null if not needed.</param> /// <returns></returns> public OperationStates Encrypt(PDFDocument document, System.Security.SecureString userPassword, System.Security.SecureString ownerPassword, bool allowPrinting, bool allowDegradatedPrinting, bool allowModifyContents, bool allowAssembly, bool allowCopyContents, bool allowScreenReaders, bool allowModifyAnnotations, bool allowFillIn, bool allowAllFeatures, ref string outputFileName) { OperationStates state = OperationStates.Ok; if ((userPassword == null) && (ownerPassword == null)) return state; string allow = ""; if (allowAllFeatures) { allow = "AllFeatures"; } else { if (allowPrinting) { allow += "Printing "; } if (allowDegradatedPrinting) { allow += "DegradatedPrinting "; } if (allowModifyContents) { allow += "ModifyContents "; allowAssembly = true; } if (allowAssembly) { allow += "Assembly "; } if (allowCopyContents) { allow += "CopyContents "; allowScreenReaders = true; } if (allowScreenReaders) { allow += "ScreenReaders "; } if (allowModifyAnnotations) { allow += "ModifyAnnotations "; allowFillIn = true; } if (allowFillIn) { allow += "FillIn "; } } string passwords = ""; if (userPassword != null) { IntPtr ptr = System.Runtime.InteropServices.Marshal.SecureStringToBSTR(userPassword); passwords += "user_pw " + System.Runtime.InteropServices.Marshal.PtrToStringAuto(ptr); } if (ownerPassword != null) { IntPtr ptr = System.Runtime.InteropServices.Marshal.SecureStringToBSTR(ownerPassword); passwords += " owner_pw " + System.Runtime.InteropServices.Marshal.PtrToStringAuto(ptr); if (allow != "") { passwords += " allow " + allow; } } if (passwords != "") { string inputFileName = document.FullName; GetValidOutputFileName(ref outputFileName, 1); string args = "\"" + inputFileName + "\" output \"" + outputFileName + "\" " + passwords; userPassword = null; ownerPassword = null; RunPdftk(args); } return state; }
/// <summary> /// Rotates pages from a pdf file and saves them into a new file. /// </summary> /// <param name="pageStart">First page to rotate</param> /// <param name="pageEnd">Last page to rotate</param> /// <param name="interval">Page interval (all, even, odd)</param> /// <param name="rotation">Rotation type</param> /// <param name="outputFileName">Path of the new file</param> /// <returns></returns> public OperationStates RotatePages(PDFDocument document, int pageStart, int pageEnd, PageIntervals interval, Rotations rotation, ref string outputFileName) { OperationStates state = OperationStates.Ok; if ((pageStart < 1) || (pageStart > document.NumberOfPages) || (pageEnd < 1) || (pageEnd > document.NumberOfPages)) { state = OperationStates.PageRangeOutOfDocument; return state; } string s_rotation = ""; switch (rotation) { case Rotations.North: s_rotation += "N"; break; case Rotations.South: s_rotation += "S"; break; case Rotations.East: s_rotation += "E"; break; case Rotations.West: s_rotation += "W"; break; case Rotations.Left: s_rotation += "L"; break; case Rotations.Right: s_rotation += "R"; break; case Rotations.Down: s_rotation += "D"; break; } string range = ""; if (pageStart > 1) { range += "1-" + (pageStart - 1).ToString() + " "; } /* pdftk rotates the pages using the "cat" option, which catenates pages from a pdf * into another pdf file. If I specify an odd or even range (e.g. 1-10odd) only odd * or even pages within that range are catenated in the output file, but that's not * what I want. I need ALL pages to be present in the new file and only odd or even * pages be rotated. To achieve this I need to break the interval like below. */ switch (interval) { case PageIntervals.Even: for (int i = pageStart; i <= pageEnd; i++) { range += i.ToString(); range += (i % 2 == 0) ? s_rotation + " " : " "; } break; case PageIntervals.Odd: for (int i = pageStart; i <= pageEnd; i++) { range += i.ToString(); range += (i % 2 != 0) ? s_rotation + " " : " "; } break; case PageIntervals.All: for (int i = pageStart; i <= pageEnd; i++) { range += i.ToString() + s_rotation + " "; } break; } if (pageEnd < document.NumberOfPages) { range += " " + (pageEnd + 1).ToString() + "-" + document.NumberOfPages.ToString(); } GetValidOutputFileName(ref outputFileName, 1); string args = "\"" + document.FullName + "\" cat " + range + " output \"" + outputFileName + "\""; RunPdftk(args); return state; }