public void WriteApplicationPdfWithEveryControl() { ControlList list = ControlListActivator.CreateControlList(); ApplicationPdfWriter writer = new ApplicationPdfWriter(); Application application = new Application { ApplicationData = new ApplicationData() }; foreach (Control control in list) { ValueControl valueControl = control as ValueControl; ContainerControl containerControl = control as ContainerControl; CalculationControl calculationControl = control as CalculationControl; if (valueControl == null && containerControl == null && calculationControl == null) { continue; } object value; switch (control.Type) { case ControlType.CheckboxGroup: value = new string[0]; break; case ControlType.Repeater: value = new object[0]; break; case ControlType.Likert: value = new Dictionary<string, object>(); break; default: value = string.Empty; break; } application.ApplicationData.Add(control.Name, value); } using (MemoryStream stream = new MemoryStream()) { writer.WritePdfToStream(application, list, stream); } }
private void Run() { JsonConvert.DefaultSettings = () => new JsonSerializerSettings { Formatting = Formatting.None, Converters = new JsonConverter[] { new JsonKnownTypeConverter() } }; const string applicationId = "54b841f7606fe6302029d607"; IUnityContainer container = new UnityContainer().LoadConfiguration(); IFormServiceGateway formServiceGateway = container.Resolve<IFormServiceGateway>(); ISecurityService securityServiceGateway = container.Resolve<ISecurityService>(); SecureSession session = securityServiceGateway.CreateSession("Administrator", "dws!1114"); Application application = formServiceGateway.GetApplication(session, applicationId); ProductDefinition product = formServiceGateway.GetProduct(session, application.FormId, null); PdfWriterSettings settings = new PdfWriterSettings { BorderColourHex = "333333", FontColourHex = "333333", FontFace = "Verdana", FontSize = "9pt", HeaderLogoUri = @".\dws-logo.png", HeaderRowBackgroundHex = "015998", HeaderRowFontColourHex = "ffffff", MetaAuthor = "iApply", MetaTitle = "Application PDF" }; FileStream fileStream = new FileStream(@".\iapply.pdf", FileMode.Create); ApplicationPdfWriter writer = new ApplicationPdfWriter(settings); writer.WritePdfToStream(application, product.FormDefinition.Pages.AllControls, fileStream); /*ProductPdfWriter writer = new ProductPdfWriter(settings); writer.WritePdfToFilesystem(product, new ControlEntitlementList());*/ }
/// <summary> /// Generates the application PDF. /// </summary> /// <param name="session">The session.</param> /// <param name="applicationId">The application identifier.</param> /// <returns>A serialisable file representing the PDF.</returns> public FileSerializable GenerateApplicationPdf(SecureSession session, string applicationId) { Application application = this.RetrieveApplication(session, applicationId); ProductDefinition product = this.GetProduct(session, application.FormId, application.UseFormVersion ? application.FormVersion : null, applicationId); ControlList controlList = product.FormDefinition.Pages.AllControls; using (MemoryStream stream = new MemoryStream()) { ApplicationPdfWriter pdfWriter = new ApplicationPdfWriter(this.pdfWriterSettings); pdfWriter.WritePdfToStream(application, controlList, stream); string filename = this.stringFormatter.Format(this.pdfFilenameFormat, application, controlList); byte[] data = new byte[stream.Length]; if (stream.Read(data, 0, Convert.ToInt32(stream.Length)) > 0) { return new FileSerializable(filename, data); } } throw new Exception(string.Format(ExceptionMessages.FailedGeneratingPdf, applicationId)); }