public async Task <IActionResult> FillExamFormAsync(ExamListViewModel vm) { var examsDTO = await _examService.GetExamsAsync(vm.FacultyName, vm.CourseNumber); var listviewmodel = _examViewModelMapper.MapFrom(examsDTO); var model = new ExamListViewModel { CourseNumber = vm.CourseNumber, Exams = listviewmodel, FacultyName = vm.FacultyName, Session = vm.Session, Year = vm.Year, NextYear = vm.Year + 1 }; var html = PdfUtility.GetHTMLString(model); var Renderer = new HtmlToPdf(); var PDF = Renderer.RenderHtmlAsPdf(html); var pdfname = vm.Shortfaculty + "_" + vm.CourseNumber.ToString() + ".pdf"; var OutputPath = "HtmlToPDF.pdf"; PDF.SaveAs(OutputPath); byte[] fileBytes = System.IO.File.ReadAllBytes(@"HtmlToPDF.pdf"); string fileName = pdfname; return(File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName)); }
/// <summary> /// Uses parallel processing to perform OCR on the mailing address region of the pdf files. /// Calls other methods to update the pdf files with that OCR information and builds a /// dictionary for file paths with associated page counts. /// </summary> /// <param name="inputFiles">List of files to be processed.</param> /// <param name="currentFolder">Active input directory.</param> /// <returns>Dictionary of file paths and associated page counts.</returns> internal static Dictionary <string, int> Process(List <string> inputFiles, KeyValuePair <string, string> currentFolder) { var filePageCounts = new ConcurrentDictionary <string, int>(); SetupOcrWorkingDirectory(); Parallel.ForEach(inputFiles, file => { string returnedText = null; using (var document = new PDFDocument(file)) { filePageCounts.TryAdd(file.ToString(), document.Pages.Count); using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false)) { ocrEngine.Startup(null, null, ocrWorkingDir, ocrAdvantageRuntimeDir); ocrEngine.SpellCheckManager.SpellCheckEngine = OcrSpellCheckEngine.None; returnedText = GetAddressBlockText(ocrEngine, document); ocrEngine.Shutdown(); } } PdfUtility.OverlayOcrText(returnedText, file, currentFolder); } ); var returnDictionary = filePageCounts.ToDictionary(kvp => kvp.Key, kvp => kvp.Value); return(returnDictionary); }
public void Constructor_FileWithWrongFormat_FileNotFoundException() { byte[] file = File.ReadAllBytes(FILE_NO_PDF); PdfUtility doc = new PdfUtility(file, null); //Disposing the element doc.Dispose(); }
public void Constructor_FileExists_NoExceptions() { byte[] file = File.ReadAllBytes(FILE_WITH_NO_FIELDS); PdfUtility doc = new PdfUtility(file, null); //Disposing the element doc.Dispose(); }
protected void Page_Load(object sender, EventArgs e) { string key = Session["PdfToSignKey"] as string; PdfUtility pdfUtil = null; if (string.IsNullOrEmpty(key) || Cache[key] == null) { //Create a stream of the pdf to be signed WebClient wc = new WebClient(); var pdfBytes = wc.DownloadData("http://api.bizdoc.dk/pdf/getpdf/1481D4D3-001D-4A79-BC65-36659C733619"); //byte[] pdfBytes = File.ReadAllBytes(Server.MapPath(ResourceLoader.ResourcesPrefix + "docs/Brugeraftale_for_medarbejdere.pdf")); MemoryStream ms = new MemoryStream(pdfBytes); //Create an instance of Signaturgruppen's PdfUtility //from this you can read the required properties, checksums etc. pdfUtil = new PdfUtility(ms); //Generate some kind of session/otp url and make the pdf available. //The applet will not inherit the current session, so it is required that we make and url getting //the pdf directly, yet we need to protect the pdf from general download //In this demo, we store the pdf using a hard-to-guess key string pwd = Membership.GeneratePassword(18, 0); Encoding encoding = new UTF8Encoding(); key = Convert.ToBase64String(encoding.GetBytes(pwd)); Session["PdfToSignKey"] = key; Cache.Insert(key, pdfUtil.BytesFromPdf, null, DateTime.Now.AddMinutes(10), System.Web.Caching.Cache.NoSlidingExpiration); } if (pdfUtil == null) { pdfUtil = new PdfUtility(new MemoryStream((byte[])Cache[key])); } //pdfPath = pdfUtil.PdfUri; pdfPath = VirtualPathUtility.ToAbsolute("~/Sign/PdfGetByOtp.aspx") + "?PdfToSignKey=" + key; //pdfPath = "url"; pdfHash = pdfUtil.SignTextUriHashValue; algorithm = pdfUtil.HashAlgorithmOpenSign1AppletParam; Session["SIGNTEXT"] = pdfUtil.Base64Pdf; dnFilter = ConfigurationManager.AppSettings.Get("OcesDNFilter"); issuerFilter = ConfigurationManager.AppSettings.Get("OcesIssuerFilter"); challenge = Convert.ToBase64String( Encoding.ASCII.GetBytes(DateTime.Now.ToBinary().ToString(CultureInfo.InvariantCulture))); if (Session["SIGNCHALLENGE"] != null) { challenge = Session["SIGNCHALLENGE"].ToString(); } Session.Add("SIGNCHALLENGE", challenge); dnFilter = Convert.ToBase64String(Encoding.ASCII.GetBytes(dnFilter)); issuerFilter = Convert.ToBase64String(Encoding.ASCII.GetBytes(issuerFilter)); }
public void FlagCheckbox_CheckboxDoesntExist_FieldNotFoundException() { //Arrange byte[] file = File.ReadAllBytes(FILE_WITH_CHECKBOX); using (PdfUtility doc = new PdfUtility(file, null)) { //Act doc.FlagCheckbox("Pluto"); } }
public void SelectRadiobutton_ValueArgumentNull_ArgumentNullException() { //Arrange byte[] file = File.ReadAllBytes(FILE_WITH_CHECKBOX); using (PdfUtility doc = new PdfUtility(file, null)) { //Act doc.SelectRadiobutton("Signature1", null); } }
public void FlagCheckbox_ArgumentNull_ArgumentNullException() { //Arrange byte[] file = File.ReadAllBytes(FILE_WITH_CHECKBOX); using (PdfUtility doc = new PdfUtility(file, null)) { //Act doc.FlagCheckbox(null); } }
public void InsertTextInField_FieldExists() { //Arrange byte[] file = File.ReadAllBytes(FILE_WITH_CHECKBOX); using (PdfUtility doc = new PdfUtility(file, null)) { //Act doc.InsertTextInField("Nome", "Pippo"); } }
public void InsertTextInField_DocumentHasNoFields_DocumentHasNoFieldsException() { //Arrange byte[] file = File.ReadAllBytes(FILE_WITH_NO_FIELDS); using (PdfUtility doc = new PdfUtility(file, null)) { //Act doc.InsertTextInField("Nome", "Pippo"); } }
public void InsertTextInField_TextArgumentNull_ArgumentNullException() { //Arrange byte[] file = File.ReadAllBytes(FILE_WITH_CHECKBOX); using (PdfUtility doc = new PdfUtility(file, null)) { //Act doc.InsertTextInField("Nome", null); } }
public void SelectRadiobutton_ValueToSelectDoesntExist_FieldNotFoundException() { //Arrange byte[] file = File.ReadAllBytes(FILE_WITH_RADIOBUTTON); using (PdfUtility doc = new PdfUtility(file, null)) { //Act doc.SelectRadiobutton("language_gc", "Pluto"); } }
public void SubstituteSignature_DocumentHasNoFields_DocumentHasNoFieldsException() { //Arrange byte[] file = File.ReadAllBytes(FILE_WITH_NO_FIELDS); using (PdfUtility doc = new PdfUtility(file, null)) { //Act doc.SubstituteSignature("Signature1"); } }
public void GetAcrofieldType_DocumentHasNoFields_DocumentHasNoFieldsException() { //Arrange byte[] file = File.ReadAllBytes(FILE_WITH_NO_FIELDS); using (PdfUtility doc = new PdfUtility(file, null)) { //Act var type = doc.GetAcrofieldType("Nomi"); } }
public void SelectRadiobutton_RadiobuttonExists() { //Arrange byte[] file = File.ReadAllBytes(FILE_WITH_RADIOBUTTON); using (PdfUtility doc = new PdfUtility(file, null)) { //Act doc.SelectRadiobutton("language_gc", "English"); } }
public void SelectRadiobutton_FieldArgumentNull_ArgumentNullException() { //Arrange byte[] file = File.ReadAllBytes(FILE_WITH_CHECKBOX); using (PdfUtility doc = new PdfUtility(file, null)) { //Act doc.SelectRadiobutton(null, "English"); } }
public void FlagCheckbox_DocumentHasNoFields_DocumentHasNoFieldsException() { //Arrange byte[] file = File.ReadAllBytes(FILE_WITH_NO_FIELDS); using (PdfUtility doc = new PdfUtility(file, null)) { //Act doc.FlagCheckbox("Pluto"); } }
public void GetAcrofieldType_FieldDoesntExist_FieldNotFoundException() { //Arrange byte[] file = File.ReadAllBytes(FILE_WITH_CHECKBOX); using (PdfUtility doc = new PdfUtility(file, null)) { //Act var type = doc.GetAcrofieldType("Nomi"); } }
public void SelectRadiobutton_DocumentHasNoFields_DocumentHasNoFieldsException() { //Arrange byte[] file = File.ReadAllBytes(FILE_WITH_NO_FIELDS); using (PdfUtility doc = new PdfUtility(file, null)) { //Act doc.SelectRadiobutton("Signature1", "English"); } }
public void SubstituteSignature_SignatureDoesntExist_FieldNotFoundException() { //Arrange byte[] file = File.ReadAllBytes(FILE_WITH_CHECKBOX); using (PdfUtility doc = new PdfUtility(file, null)) { //Act doc.SubstituteSignature("Pluto"); } }
public void SubstituteSignature_SignatureExists() { //Arrange byte[] file = File.ReadAllBytes(FILE_WITH_SIGNATUREFIELD); using (PdfUtility doc = new PdfUtility(file, null)) { //Act doc.SubstituteSignature("Signature1"); } }
public void SubstituteSignature_ArgumentNull_ArgumentNullException() { //Arrange byte[] file = File.ReadAllBytes(FILE_WITH_CHECKBOX); using (PdfUtility doc = new PdfUtility(file, null)) { //Act doc.SubstituteSignature(null); } }
public void InsertTextInField_FieldDoesntExist_FieldNotFoundException() { //Arrange byte[] file = File.ReadAllBytes(FILE_WITH_CHECKBOX); using (PdfUtility doc = new PdfUtility(file, null)) { //Act doc.InsertTextInField("Nomi", "Pippo"); } }
public void FlagCheckbox_CheckboxExists() { //Arrange byte[] file = File.ReadAllBytes(FILE_WITH_CHECKBOX); using (PdfUtility doc = new PdfUtility(file, null)) { //Act doc.FlagCheckbox("CheckBox1"); } }
public void GetAcrofieldType_ArgumentNull_ArgumentNullException() { //Arrange byte[] file = File.ReadAllBytes(FILE_WITH_CHECKBOX); using (PdfUtility doc = new PdfUtility(file, null)) { //Act var type = doc.GetAcrofieldType(null); } }
public void SelectRadiobutton_SelectingTwiceRadiobuttonAssigningDifferentValues() { //Arrange byte[] file = File.ReadAllBytes(FILE_WITH_RADIOBUTTON); using (PdfUtility doc = new PdfUtility(file, null)) { //Act doc.SelectRadiobutton("language_gc", "English"); doc.SelectRadiobutton("language_gc", "Spanish"); } }
public void FlagCheckbox_CheckingTwice() { //Arrange byte[] file = File.ReadAllBytes(FILE_WITH_CHECKBOX); using (PdfUtility doc = new PdfUtility(file, null)) { //Flagging first doc.FlagCheckbox("CheckBox1"); //Flagging second doc.FlagCheckbox("CheckBox1"); } }
public void FlagCheckbox_TwoCheckableCheckboxes() { //Arrange byte[] file = File.ReadAllBytes(FILE_WITH_CHECKBOX); using (PdfUtility doc = new PdfUtility(file, null)) { //Act //Flagging first checkbox doc.FlagCheckbox("CheckBox1"); //Flagging second doc.FlagCheckbox("CheckBox2"); } }
public void SubstituteSignature_SubstituteTwice_FieldNotFoundException() { //Arrange byte[] file = File.ReadAllBytes(FILE_WITH_SIGNATUREFIELD); using (PdfUtility doc = new PdfUtility(file, null)) { //Act //Flagging first checkbox doc.SubstituteSignature("Signature1"); //Flagging second doc.SubstituteSignature("Signature1"); } }
public void GetAcrofieldType_FieldExists_ReturnsFieldType() { //Arrange byte[] file = File.ReadAllBytes(FILE_WITH_CHECKBOX); using (PdfUtility doc = new PdfUtility(file, null)) { //Act var type = doc.GetAcrofieldType("Nome"); System.Diagnostics.Debug.WriteLine("Looking for acrofield named \"Nome\", type: " + type + " (" + PdfUtility.GetFormType(type) + ")"); //Assert Assert.IsTrue(type > -1); } }
public void InsertTextInField_InsertingTextTwice() { //Arrange byte[] file = File.ReadAllBytes(FILE_WITH_CHECKBOX); using (PdfUtility doc = new PdfUtility(file, null)) { //Act //Inserting first time doc.InsertTextInField("Nome", "Pippo"); //Inserting second time doc.InsertTextInField("Nome", "Pippo2"); } }
private string CreatePdfSessionOrGetCurrent(Signature signature) { var key = Session["PdfToSignKey"] as string; if (string.IsNullOrEmpty(key) || Cache[key] == null) { //Create a stream of the pdf to be signed //var pdfBytes = // File.ReadAllBytes(Server.MapPath(ResourceLoader.ResourcesPrefix + "docs/Brugeraftale_for_medarbejdere.pdf")); var pdfBytes = new WebClient().DownloadData("http://api.bizdoc.dk/pdf/getpdf/" + signature.pdf.id); var ms = new MemoryStream(pdfBytes); //Create an instance of Signaturgruppen's PdfUtility //from this you can read the required properties, checksums etc. pdfUtil = new PdfUtility(ms); //Generate some kind of session/otp url and make the pdf available. //The applet will not inherit the current session, so it is required that we make and url getting //the pdf directly, yet we need to protect the pdf from general download //In this demo, we store the pdf using a hard-to-guess key var pwd = Membership.GeneratePassword(18, 0); Encoding encoding = new UTF8Encoding(); key = Convert.ToBase64String(encoding.GetBytes(pwd)); Session["PdfToSignKey"] = key; Cache.Insert(key, pdfUtil.BytesFromPdf, null, DateTime.Now.AddMinutes(10), System.Web.Caching.Cache.NoSlidingExpiration); } if (pdfUtil == null) { pdfUtil = new PdfUtility(new MemoryStream((byte[])Cache[key])); } return key; }