This article provides a solution to generate the form archive as a PDF. The HTML version of the form archive is converted to PDF using an external library (WkHtmlToPdf).
Note: This solution has not been tested with a high number of transactions.
-
Install WkHtmlToPdf (http://wkhtmltopdf.org/). Advantages:
-
32-bit and 64-bit versions are available.
-
Good CSS support
-
License L-GPL (free)
-
-
Create a
FORM_PRINT
process data (FILE data type). This process data will contain the PDF version of the form archive. -
Add a form section with two text fields with the IDs
FORM_DRAFT
andFORM_PRINT
. You must hide this section for all workflow actions (edit the section Settings / Section Behavior / Hidden checkbox). -
Map the
FORM_PRINT
textbox to theFORM_PRINT
process data. For each action of your workflow you have to mapFORM_PRINT
textbox to theFORM_PRINT
process data. You can use the action parameters. -
In the .NET editor, add the following code:
protected void Page_Load(object sender, EventArgs e) { base.Page_Load(sender, e); this.FORM_PRINT.Text = "form_print.pdf"; } protected override void Render(HtmlTextWriter writer) { base.Render(writer); if (this.FormArchive != null) { HTML2PDF(this.FormArchive, this.StoragePath + "\\form_print.pdf"); } } private void HTML2PDF (string HTML, string Path) { System.Diagnostics.Process p; System.IO.StreamWriter stdin; System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo(); // run the conversion utility psi.UseShellExecute = false; psi.FileName = @"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe"; psi.CreateNoWindow = true; psi.RedirectStandardInput = true; psi.RedirectStandardOutput = true; psi.RedirectStandardError = true; string args = "-q -n - " + Path; psi.Arguments = args; p = System.Diagnostics.Process.Start(psi); try { stdin = p.StandardInput; stdin.AutoFlush = true; stdin.Write(HTML); stdin.Close(); if (p.WaitForExit(20000)) { Response.BinaryWrite(System.IO.File.ReadAllBytes(Path)); } } finally { p.Close(); p.Dispose(); } }
Alternative libraries
It’s also possible to use a commercial component such as EVO or HiQPdf.
Example with EVO
EvoPdf.PdfConverter pdfConverter = new EvoPdf.PdfConverter();
pdfConverter.PdfDocumentOptions.PdfPageSize = EvoPdf.PdfPageSize.A4;
pdfConverter.PdfDocumentOptions.PdfCompressionLevel = EvoPdf.PdfCompressionLevel.Normal;
pdfConverter.JavaScriptEnabled = false;
pdfConverter.SavePdfFromHtmlStringToFile(this.FormArchive, this.StoragePath + "\\form_print.pdf");
Example with HiQPdf
HiQPdf.HtmlToPdf htmlToPdfConverter = new HiQPdf.HtmlToPdf();
htmlToPdfConverter.Document.PageSize = HiQPdf.PdfPageSize.A4;
htmlToPdfConverter.Document.PageOrientation = HiQPdf.PdfPageOrientation.Portrait;
htmlToPdfConverter.Document.Margins = new HiQPdf.PdfMargins(5);
htmlToPdfConverter.ConvertHtmlToFile(this.FormArchive, this.StoragePath + "\\form_print.pdf")