When creating PDF reports of completed forms you may become aware that the Grid control in Mi-Forms does not have the ability to render in an Image or PDF export. The result you get is a blank spot in the page that exported where the grid resides. To resolve this pproblem, and ensure that the data is made visible on the PDF export you can use the concept of a report page using Dynamic Labels to display the values in the grid.

Her is an extremely simplified solution to that problem. This form has a grid on Page one, and a reporting Page two. When the DataPaths are exported ,a PDF file containing Page 2 is repeated for each row of the grid using simple looping logic. This solution could easily be modified to show several items on a page, but we only show one to make this example simple.

The following function is a modification of the method we commonly use to generate PDF exports that includes logic to loop through the grid and populate Hidden Fields as saves a file to c:\temp\GridOutput.pdf.


	''' <summary>
	''' Generate our PDF And store an export result indicating success Or failure
	''' </summary>
    Private Sub GeneratePDF()
		' First we find the ID of the blank PDF that's attached. In this specific case, 
		' the attachment was manually named blank.pdf
        Dim xattid As String = GetPDFAttachmentID("blank.pdf")

		' Create a render settings object that tells our PDF generator how it should
		' handle all types of fields
        Dim xrs As New RenderSettings(CTextRenderType.FieldValues, FreeformRenderType.Ink, CheckboxRenderType.Symbol, PageRenderType.Ink)

		' Define the filename where the PDF will be written to
		Dim strFilename As String = "c:\temp\GridOutput.pdf"

			' The object of type PDFDoc (which is in the MiCo.MiForms.DatapathExportModule assembly)
			' is the class that will do all the "heavy lifting" of creating the actual
			' PDF file
            Dim xdoc As New MiCo.MiForms.DataPaths.PDFDoc(_form, xattid, strFilename)

			' Here we take a row from the grid and populate data on the report page
			Dim table As DataTable = _Grid.Value
			For Each row As DataRow In table.Rows
				' Clear the field values first
				_Dosage.Value = ""
				_Drug.Value = ""
				_Patient.Value = ""
				_Date.Value = ""
				' Now populate them from the grid
				_Dosage.Value = row.Item("Dosage")
				_Drug.Value = row.Item("Drug")
				_Patient.Value = row.Item("Patient")
				_Date.Value = row.Item("Date")
				' Now we create a pdf page
				xdoc.AddPage(xrs, 0, 1)
			' We close the PDF document to let the engine know we're done with adding pages
			' Finally we record that we successfully exported the PDF
            Me.RecordExportResult("EXP_PDF", True, "Export to PDF", "Export details to multi-page PDF", "Success in writing PDF", strFilename)
        Catch ex As Exception
			' Or that we failed somewhere along the line
            Me.RecordExportResult("EXP_PDF", False, "Export to PDF", "Export details to multi-page PDF", "Failed to write PDF: " & ex.Message, strFilename)
        End Try
    End Sub


You can download the functional version of the sample form attached to this article.