/// <summary> /// Publishes a generic letter on School letterhead. PDF protection options are set via the boolean properties of this object. /// Document is digitally signed using a certificate generated by the local certificate authority in the dublinschool.org domain. /// </summary> /// <param name="bodyHtml">Body of the letter.</param> /// <param name="signerId">Employee id of the Faculty who will put their signature on the document. (automatically adds the signature image to the end of the document.</param> public Document PublishGenericLetter(String bodyHtml, bool digitallySign = false, int signerId = -1) { String html = Template.Replace("{content}", bodyHtml).Replace("{signature}", signerId == -1? "" : SignatureImage(signerId)); Document document = PdfConverter.ConvertHtmlToPdfDocumentObject(html, BaseURL, BaseURL); if (digitallySign) { try { /// digitally sign the document. HtmlElementMapping dsMap = PdfConverter.HtmlElementsMappingOptions.HtmlElementsMappingResult.GetElementByMappingId("digital_signature_element"); if (dsMap != null) { PdfPage page = dsMap.PdfRectangles.Last().PdfPage; RectangleF rectangle = dsMap.PdfRectangles.Last().Rectangle; DigitalCertificate cert = DocumentSigningCertificate; DigitalSignatureElement dse = new DigitalSignatureElement(rectangle, cert); dse.Reason = "Ensure Document Integrity and Protect from unwanted changes."; dse.ContactInfo = "Contact Email: [email protected]"; dse.Location = "Issuing Web Server"; page.AddElement(dse); } } catch (Exception e) { //WebhostEventLog.CommentLog.LogError("Failed to Apply digital signature to document...{0}{1}", Environment.NewLine, e.Message); } } return(document); }