protected void ParseSecurityType(string content, Secure.DocumentPermissions permissions, PDFTraceLog log) { if (!string.IsNullOrEmpty(content)) { content = content.ToLower(); switch (content) { case ("40bit"): if (log.ShouldLog(TraceLevel.Message)) { log.Add(TraceLevel.Message, "meta", "Set the document encryption to 40 bit standard (v1.2)"); } permissions.Type = Secure.SecurityType.Standard40Bit; break; case ("128bit"): if (log.ShouldLog(TraceLevel.Message)) { log.Add(TraceLevel.Message, "meta", "Set the document encryption to 128 bit standard (v2.3)"); } permissions.Type = Secure.SecurityType.Standard128Bit; break; default: if (log.ShouldLog(TraceLevel.Warning)) { log.Add(TraceLevel.Warning, "meta", "The document encryption " + content + " was not a recognised value, use 40bit or 128bit"); } break; } } }
protected void ParseRestrictions(string content, Secure.DocumentPermissions permissions, PDFTraceLog log) { if (string.IsNullOrEmpty(content)) { return; } content = content.Trim().ToLower(); bool logVerbose = log.ShouldLog(TraceLevel.Verbose); if (content == "none") { if (logVerbose) { log.Add(TraceLevel.Verbose, "meta", "Cleared all restrictions from the document"); } return; } permissions.AllowAccessiblity = false; permissions.AllowAnnotations = false; permissions.AllowCopying = false; permissions.AllowDocumentAssembly = false; permissions.AllowFormFilling = false; permissions.AllowHighQualityPrinting = false; permissions.AllowModification = false; permissions.AllowPrinting = false; if (content == "all") { if (logVerbose) { log.Add(TraceLevel.Verbose, "meta", "Set restrictions to ALL for the document"); } return; } string[] parts = content.Split(_splits, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); foreach (var part in parts) { switch (part) { case ("allow-printing"): case ("printing"): permissions.AllowHighQualityPrinting = true; permissions.AllowPrinting = true; if (logVerbose) { log.Add(TraceLevel.Verbose, "meta", "Allowed printing for the document"); } break; case ("allow-accessibility"): case ("accessibility"): permissions.AllowAccessiblity = true; if (logVerbose) { log.Add(TraceLevel.Verbose, "meta", "Allowed accessibility for the document"); } break; case ("allow-annotations"): case ("annotations"): permissions.AllowAnnotations = true; if (logVerbose) { log.Add(TraceLevel.Verbose, "meta", "Allowed annotations for the document"); } break; case ("allow-copying"): case ("copying"): permissions.AllowCopying = true; if (logVerbose) { log.Add(TraceLevel.Verbose, "meta", "Allowed copying for the document"); } break; case ("allow-modifications"): case ("modifications"): permissions.AllowModification = true; permissions.AllowDocumentAssembly = true; if (logVerbose) { log.Add(TraceLevel.Verbose, "meta", "Allowed modifications for the document"); } break; case ("allow-forms"): case ("forms"): permissions.AllowFormFilling = true; if (logVerbose) { log.Add(TraceLevel.Verbose, "meta", "Allowed form filling for the document"); } break; default: if (log.ShouldLog(TraceLevel.Warning)) { log.Add(TraceLevel.Warning, "meta", "The restrictions part " + part + " was not recognised as a valid restriction"); } break; } } }