Report Maker - Automated Generation of Reports

Although generated reports can be exported to different file formats from the Dashboard display in DataStudio, it is often useful to automate this export to happen either periodically or on demand. The Report Maker application included in the setup) is designed to do just that. To access the Report Maker in Lua we can create an Action Item to execute a Lua script that uses the inmation.reportmaker library (need to use the require command to call this). The makereport method from this library takes a Lua table as its argument. This table contains the following parameters.

  • The path to the Report Item that contains the report

  • The location and filename of the exported Report

  • The format of the exported report

  • (optional) The Report Name property in the Report Item, found in the Report Design Data. If not specified, the default report will be used.

  • (optional) The location of the ReportMaker.exe application (found in the inmation.root\reporting directory). It not specified, it will be detected automatically.

Report Maker Example in Lua

For the purposes of this example, we will execute the script from an Action Item, however any object with the ability to execute Lua scripts can be used to trigger the Report Maker application.

Create and Action Item in the Report Demo folder by right-clicking on the folder and selecting Admin → New → Data Processing → Action Item. In the Create Object wizard fill in the Object Name and click Create.

Report Maker Action Item
Figure 1. Report Maker Action Item

Open the Lua Script Body for the Action Item and enter the following script:

local RPM = require 'inmation.reportmaker'
local params = {}
params.ReportItemPath = "/System/inmws030/my report/ReportItem1"
params.OutputFile = "D:\\Temp\\Report"
params.OutputFormat = "PDF"
params.ReportName = "Test Report" --optional
params.ReportMakerPath = "C:\\inmation.root\\reporting\\Reportmaker.exe" --optional
local err, q = RPM:MAKE_REPORT(params)
return err, q

In the above snippet, MAKE_REPORT is used. This method is optimized for the use in a VQT based script object. It returns an error string, and quality.

local r = RPM:makereport(params)
if r.Succeeded then
	return "Report created succesfully"
else
	return result.Logtext
end

In this snippet, makereport is used instead. This method’s return is library friendly, it returns a result table with the keys Succeeded and Logtext.

The paths and other parameter information should be changes to match your system setup and to match the appropriate paths and Report names for your Report Items.

Click Ok to execute the Lua script and the Action Item will return the log information determining whether the Report creation and export were successful.

Successful Report Creation Output

Check the specified output directory to see if the Report File has been exported.

Exported File in Directory
Figure 2. Exported File in Directory
If the same script is executed again the existing file will be overwritten in the output directory. If the exported report file is open in another program when the script is executed then the report creation will fail and will be indicated in the log output.

Output Format Examples for reportmaker Lua library

The available output formats configured in the OutputFormat parameter are shown below with commented code examples:

PDF format

reportmaker = require ("inmation.reportmaker")
local params = {}
params.ReportItemPath = "/System/Core/Report"
params.ReportName = "Report"
params.OutputFile = "D:\\Tmp\\Out\\Report"
params.OutputFormat = "PDF"
local PdfExportSettings = {}

-- The ImageQuality will be available only if you select the compression method JPEG.  Keep in mind that if you change this option the size of the finished file will increase. The higher the quality is, the larger is the size of the finished file.

PdfExportSettings.ImageQuality = 0.75

-- Depending on the values of this parameter, a certain resolution will be applied to the image in the report.
Possible values are:
-- reportmaker.StiImageResolutionMode.Exactly
-- reportmaker.StiImageResolutionMode.NoMoreThan
-- reportmaker.StiImageResolutionMode.Auto
--
-- Exactly - all images after conversion will have the resolution specified in the Image resolution option;
-- NoMoreThan - if the original resolution of the image is less than specified in the Image resolution parameter, then the resolution of the image after the conversion of the report will be equal to the original one. If the original resolution is greater than the one specified in the Image Resolution settings, the image resolution will correspond to the value of the Image Resolution settings.
-- Auto - the image after the report is converted will have the original resolution.
PdfExportSettings.ImageResolutionMode = reportmaker.StiImageResolutionMode.NoMoreThan
--
-- The ImageResolution is used to change DPI (image property PPI (Pixels Per Inch)). The greater the number of pixels per inch is, the greater is the quality of the image. It should be noted that the value of this parameter affects the size of the finished file. The higher the value is, the greater is the size of the finished file.

PdfExportSettings.ImageResolution = 100.0

-- The flag EmbeddedFonts provides the ability to embed the font files into the created PDF file. If this option is enabled, then when you export a report, the files of all the fonts used in the report will be included in a PDF file, and fonts in the resulting file will be displayed correctly in any PDF viewer. If the property is disabled, then to display the file correctly all the fonts used in the report must be installed on the computer.

PdfExportSettings.EmbeddedFonts = true

-- Sets value which indicates if only standard PDF fonts will be used in result PDF file
PdfExportSettings.StandardPdfFonts = false

-- Sets value which indicates if result file will use compression

PdfExportSettings.Compressed = true

-- The flag ExportRtfTextAsImage as Image as Image enables/disables the conversion of the RTF text into the image. If the option is disabled, the Rich Text is decomposed into simpler primitives supported by the PDF format. The Rich Text with complex formatting (embedded images, tables) cannot always be converted correctly. In this case it is recommended to enable this option.

PdfExportSettings.ExportRtfTextAsImage = false

-- In the field PasswordInputUser, specify the password required to open the document. If you set the password, access to the opening file is limited and will occur only if you specify the correct password. If no password is specified, i.e. the field is left blank, then the file may be opened without restrictions.

PdfExportSettings.PasswordInputUser = "mypassword"

-- In the field PasswordInputOwner, specify the owner password to access the file. If you specify a password, access to the file operations, such as printing, copying etc. will be available only after entering a password. If no password is specified, i.e., the field is left blank, the file operations will be available without restriction. If the owner's password is set, and the public password is not set, then, when opening a document, the password is not requested.

PdfExportSettings.PasswordInputOwner = "ownerpassword"

-- Sets user access privileges. Possible values are:
-- reportmaker.StiUserAccessPrivileges.None
-- reportmaker.StiUserAccessPrivileges.PrintDocument
-- reportmaker.StiUserAccessPrivileges.ModifyContents
-- reportmaker.StiUserAccessPrivileges.CopyTextAndGraphics
-- reportmaker.StiUserAccessPrivileges.AddOrModifyTextAnnotations
-- reportmaker.StiUserAccessPrivileges.All

-- The flag PrintDocument enables/disables the restricted access to the printing operation. If this option is disabled, specifying the owner password is required to perform this operation. If enabled, then printing will be available for everyone who opens the document.
-- The flag ModifyContents enables/disables access to editing the text in the report. If this option is disabled, specifying the owner password is required to perform this operation. If enabled, then editing will be available for everyone who opens the document.

-- The flag CopyTextAndGraphics enables/disables access to copying the information. If this option is disabled, specifying the owner password is required to perform this operation. If enabled, then copying will be available for everyone who opens the document.
--The flag AddOrModifyTextAnnotations enables limited access to work with the annotations in the document. If this option is disabled, specifying the owner password is required to perform this operation. If enabled, then this operation will be available for everyone who opens the document.

PdfExportSettings.UserAccessPrivileges = reportmaker.StiUserAccessPrivileges.All

-- The flag KeyLength allows selecting the length of the encryption key. The longer the length is, the more difficult is to decrypt the document, and, therefore, the safety of the document is higher.

PdfExportSettings.KeyLength = reportmaker.StiPdfEncryptionKeyLength.Bit40

-- Sets value which indicates if unicode symbols must be used in result PDF file.
PdfExportSettings.UseUnicode = true
-- Sets keywords information to be inserted into result PDF file.

PdfExportSettings.KeywordsString = "Key1 Key2 Key3"

-- Sets mode of image compression in PDF file. Possible values are:
--
-- reportmaker.StiPdfImageCompressionMethod.Jpeg
-- reportmaker.StiPdfImageCompressionMethod.Flate

PdfExportSettings.ImageCompressionMethod = reportmaker.StiPdfImageCompressionMethod.Jpeg

-- Sets value which indicates the PDF file compliance mode. Possible values are:
--
-- reportmaker.StiPdfComplianceMode.None
-- reportmaker.StiPdfComplianceMode.A1
-- reportmaker.StiPdfComplianceMode.A2
-- reportmaker.StiPdfComplianceMode.A3

PdfExportSettings.PdfComplianceMode = reportmaker.StiPdfComplianceMode.None

-- Sets a value indicating AutoPrint mode. Possible values are:
--
-- reportmaker.StiPdfAutoPrintMode.None
-- reportmaker.StiPdfAutoPrintMode.Dialog
-- reportmaker.StiPdfAutoPrintMode.Silent

PdfExportSettings.AutoPrintMode = reportmaker.StiPdfAutoPrintMode.None

-- The option AllowEditable provides the ability to enable the mode in which, after exporting, it will be possible to modify components with the Editable property enabled. If you select Yes then you can edit components with the Editable property enabled.
-- Possible values are:
--
-- reportmaker.StiPdfAllowEditable.No
-- reportmaker.StiPdfAllowEditable.Yes

PdfExportSettings.AllowEditable = reportmaker.StiPdfAllowEditable.Yes

-- Set this parameter and SubjectNameString to digitaly sign the document.

PdfExportSettings.UseDigitalSignature = true

-- Reason of document signing

PdfExportSettings.DigitalSignatureReason= "I have reviewed this document"

-- Location of document signing

PdfExportSettings.DigitalSignatureLocation= "Cologne"

-- Report maker will try to find and use the first certificate containing this string in the subject field of the certificate.

PdfExportSettings.SubjectNameString = "john.wood@acme.com"

-- Set this parameter as "true" to use local machine certificate store.
-- Otherwise report maker will use certificate store of the account which Core service uses to log on.

PdfExportSettings.UseLocalMachineCertificates = true

PdfExportSettings.PageRange = {}
-- Sets type of the range.
--Possible values are:
-- reportmaker.StiRangeType.All
-- reportmaker.StiRangeType.CurrentPage
-- reportmaker.StiRangeType.Pages

PdfExportSettings.PageRange.RangeType = reportmaker.StiRangeType.Pages

-- If RangeType is equal “CurrentPage” then this parameter defines the page which will be printed.

PdfExportSettings.PageRange.CurrentPage = 1

-- The page numbers to be processed. If RangeType is equal “Pages” then this parameter defines pages to print. You can specify a single page, a list of pages (using a comma as the separator), as well as specify the range by setting the start page of the range separated by "-" and the end pagit branchge of the range. For example: 1,3,5-12.

PdfExportSettings.PageRange.PageRanges = "3-3"
params.PdfExportSettings = PdfExportSettings

-- If ReportMakerPath parameter is empty then default path will be used.

params.ReportMakerPath = ""

local result = reportmaker:makereport(params)
if not result.Succeeded then
    return result.Logtext
else
    return "OK"
end

XPS Format

reportmaker = require ("inmation.reportmaker")
local params = {}
params.ReportItemPath = "/System/Core/Report"
params.ReportName = "Report"
params.OutputFile = "D:\\Tmp\\Out\\Report"
params.OutputFormat = "XPS"
local XpsExportSettings = {}
params.XpsExportSettings = XpsExportSettings
params.ReportMakerPath = ""
XpsExportSettings.ImageQuality = 0.75
XpsExportSettings.ImageResolution = 300
XpsExportSettings.PageRange = {}
XpsExportSettings.PageRange.RangeType = reportmaker.StiRangeType.All

local result = reportmaker:makereport(params)
if not result.Succeeded then
    return result.Logtext
else
    return "OK"
end

HTML Table Format

reportmaker = require ("inmation.reportmaker")
local params = {}
params.ReportItemPath = "/System/Core/Report"
params.ReportName = "Report"
params.OutputFile = "D:\\Tmp\\Out\\Report"
params.OutputFormat = "HTMLTABLE"
local HtmlExportSettings = {}
params.HtmlExportSettings = HtmlExportSettings
params.ReportMakerPath = ""
-- Sets image format. Possible values are:
--
-- reportmaker.StiHtmlImageFormat.Jpeg
-- reportmaker.StiHtmlImageFormat.Gif
-- reportmaker.StiHtmlImageFormat.Bmp
-- reportmaker.StiHtmlImageFormat.Png

HtmlExportSettings.ImageFormat = reportmaker.StiHtmlImageFormat.Gif

-- Set this value to compress compress result file.

HtmlExportSettings.CompressToArchive = true
-- Sets zoom factor.

HtmlExportSettings.Zoom = 2.5

HtmlExportSettings.PageRange = {}

-- Sets type of the range. Possible values are:
--reportmaker.StiRangeType.All
reportmaker.StiRangeType.CurrentPage
reportmaker.StiRangeType.Pages
imageExportSettings.PageRange.RangeType = reportmaker.StiRangeType.Pages
imageExportSettings.PageRange.CurrentPage = 1
imageExportSettings.PageRange.PageRanges = “2-3”
local result = reportmaker:makereport(params)
if not result.Succeeded then
    return result.Logtext
else
 return "OK"
end

RTF Format

reportmaker = require ("inmation.reportmaker")
local params = {}
params.ReportItemPath = "/System/Core/Report"
params.ReportName = "Report"
params.OutputFile = "D:\\Tmp\\Out\\Report"

params.OutputFormat = "RTF"
local RtfExportSettings = {}
params.RtfExportSettings = RtfExportSettings
params.ReportMakerPath = ""

-- This property defines presentation of the report data after export.
-- Table - the report will look like a table, where each report component is a table cell.
-- Frame - each component will look like a single frame, but without any relationship between them.
-- Possible values are:
-- reportmaker.StiRtfExportMode.Table
-- reportmaker.StiRtfExportMode.Frame

RtfExportSettings.ExportMode = reportmaker.StiRtfExportMode.Table

-- Minimizes empty space at the bottom of the page.

RtfExportSettings.RemoveEmptySpaceAtBottom = true

-- Sets value which indicates that one (first) page header and page footer from report will be used in the file.

RtfExportSettings.UsePageHeadersAndFooters = true
RtfExportSettings.ImageQuality = 0.75
RtfExportSettings.ImageResolution = 300
RtfExportSettings.PageRange = {}
RtfExportSettings.PageRange.RangeType = reportmaker.StiRangeType.All

local result = reportmaker:makereport(params)

if not result.Succeeded then
    return result.Logtext
else
    return "OK"
end

Excel 2007 Format

reportmaker = require ("inmation.reportmaker")
local params = {}
params.ReportItemPath = "/System/Core/Report"
params.ReportName = "Report"
params.OutputFile = "D:\\Tmp\\Out\\Report"
params.OutputFormat = "EXCEL2007"
local Excel2007ExportSettings = {}
params.Excel2007ExportSettings = Excel2007ExportSettings
params.ReportMakerPath = ""

-- Sets value which indicates that one (first) page header and page footer from report will be used in the excel file.

Excel2007ExportSettings.UseOnePageHeaderAndFooter = true

-- Sets value which indicates that only data information will be created in excel file.

Excel2007ExportSettings.ExportDataOnly = true

-- Defines how editing will be restricted. Possible values are:
-- reportmaker.StiExcel2007RestrictEditing.No
-- reportmaker.StiExcel2007RestrictEditing.ExceptEditableFields
-- reportmaker.StiExcel2007RestrictEditing.Yes

Excel2007ExportSettings.RestrictEditing = reportmaker.StiExcel2007RestrictEditing.No

-- Sets value which indicates that special page break markers will be created in excel file.

Excel2007ExportSettings.ExportPageBreaks = true

-- Sets value which indicates that each page from report will be exported to excel file as separate excel sheet.

Excel2007ExportSettings.ExportEachPageToSheet = true

Excel2007ExportSettings.ImageQuality = 0.75
Excel2007ExportSettings.ImageResolution = 300
Excel2007ExportSettings.PageRange = {}
Excel2007ExportSettings.PageRange.RangeType = reportmaker.StiRangeType.All

local result = reportmaker:makereport(params)
if not result.Succeeded then
    return result.Logtext
else
    return "OK"
end

Word 2007 Format

reportmaker = require ("inmation.reportmaker")
local params = {}
params.ReportItemPath = "/System/Core/Report"
params.ReportName = "Report"
params.OutputFile = "D:\\Tmp\\Out\\Report"
params.OutputFormat = "WORD2007"
local Word2007ExportSettings = {}
params.Word2007ExportSettings = Word2007ExportSettings
params.ReportMakerPath = ""

-- Sets value which indicates if the empty space at the bottom of the page will be minimized.

Word2007ExportSettings.RemoveEmptySpaceAtBottom = true

-- Sets value which indicates that one (first) page header and page footer from report will be used in the word file.

Word2007ExportSettings.UsePageHeadersAndFooters = true

-- Defines how editing will be restricted. Possible values are:
-- reportmaker.StiWord2007RestrictEditing.No
-- reportmaker.StiWord2007RestrictEditing.ExceptEditableFields
-- reportmaker.StiWord2007RestrictEditing.Yes

Word2007ExportSettings.RestrictEditing = reportmaker.StiWord2007RestrictEditing.ExceptEditableFields
Word2007ExportSettings.ImageQuality = 0.75
Word2007ExportSettings.ImageResolution = 300
Word2007ExportSettings.PageRange = {}
Word2007ExportSettings.PageRange.RangeType = reportmaker.StiRangeType.All

local result = reportmaker:makereport(params)
if not result.Succeeded then
    return result.Logtext
else
    return "OK"
end

Image Format

reportmaker = require ("inmation.reportmaker")
local params = {}
params.ReportItemPath = "/System/Core/Report"
params.ReportName = "Report"
params.OutputFile = "D:\\Tmp\\Out\\Report"
params.OutputFormat = "IMAGE"
local ImageExportSettings = {}
params.ImageExportSettings = ImageExportSettings
params.ReportMakerPath = ""

-- Sets image type. Possible values are:
-- reportmaker.StiImageType.Bmp
-- reportmaker.StiImageType.Gif
-- reportmaker.StiImageType.Jpeg
-- reportmaker.StiImageType.Pcx
-- reportmaker.StiImageType.Png
-- reportmaker.StiImageType.Tiff
-- reportmaker.StiImageType.Emf
-- reportmaker.StiImageType.Svg
-- reportmaker.StiImageType.Svgz

ImageExportSettings.ImageType = reportmaker.StiImageType.Png

-- Sets image zoom factor for exported images. This property can't be used with EMF, SVG, SVGZ formats.

ImageExportSettings.ImageZoom = 1.5

-- Sets image resolution (dpi) for exported images.

ImageExportSettings.ImageResolution = 300

-- Sets value which indicates that page margins will be cut or not.

ImageExportSettings.CutEdges = true

-- Sets image format for exported images.

ImageExportSettings.ImageFormat = reportmaker.StiImageFormat.Color
-- Sets dithering type. Possible values are:
-- reportmaker.StiMonochromeDitheringType.None
-- reportmaker.StiMonochromeDitheringType.FloydSteinberg
-- reportmaker.StiMonochromeDitheringType.Ordered

ImageExportSettings.DitheringType = reportmaker.StiMonochromeDitheringType.FloydSteinberg
ImageExportSettings.PageRange = {}

-- Sets type of the range. Possible values are:
-- reportmaker.StiRangeType.All
-- reportmaker.StiRangeType.CurrentPage
-- reportmaker.StiRangeType.Pages

imageExportSettings.PageRange.RangeType = reportmaker.StiRangeType.Pages
imageExportSettings.PageRange.CurrentPage = 1
imageExportSettings.PageRange.PageRanges = “2-3”
local result = reportmaker:makereport(params)
if not result.Succeeded then
    return result.Logtext
else
    return "OK"
end

OpenDocument Calc Format

reportmaker = require ("inmation.reportmaker")
local params = {}
params.ReportItemPath = "/System/Core/Report"
params.ReportName = "Report"
params.OutputFile = "D:\\Tmp\\Out\\Report"
params.OutputFormat = "ODS"
local OdsExportSettings = {}
params.OdsExportSettings = OdsExportSettings
params.ReportMakerPath = ""
OdsExportSettings.ImageQuality = 0.75
OdsExportSettings.ImageResolution = 300
OdsExportSettings.PageRange = {}
OdsExportSettings.PageRange.RangeType = reportmaker.StiRangeType.All

local result = reportmaker:makereport(params)
if not result.Succeeded then
    return result.Logtext
else
    return "OK"
end

OpenDocument Writer Format

reportmaker = require ("inmation.reportmaker")
local params = {}
params.ReportItemPath = "/System/Core/Report"
params.ReportName = "Report"
params.OutputFile = "D:\\Tmp\\Out\\Report"
params.OutputFormat = "ODT"
local OdtExportSettings = {}
params.OdtExportSettings = OdtExportSettings
params.ReportMakerPath = ""

-- Sets value which indicates if the empty space at the bottom of the page will be minimized.

OdtExportSettings.RemoveEmptySpaceAtBottom = true

-- Sets value which indicates that one (first) page header and page footer from report will be used in the file.

OdtExportSettings.UsePageHeadersAndFooters = true

-- Sets image quality.

OdtExportSettings.ImageQuality = 0.75

-- Set image resolution.

OdtExportSettings.ImageResolution = 300
OdtExportSettings.PageRange = {}
OdtExportSettings.PageRange.RangeType = reportmaker.StiRangeType.All

local result = reportmaker:makereport(params)
if not result.Succeeded then
    return result.Logtext
else
    return "OK"
end

Powerpoint 2007 Format

reportmaker = require ("inmation.reportmaker")
local params = {}
params.ReportItemPath = "/System/Core/Report"
params.ReportName = "Report"
params.OutputFile = "D:\\Tmp\\Out\\Report"
params.OutputFormat = "PPT2007"
local Ppt2007ExportSettings = {}
params.Ppt2007ExportSettings = Ppt2007ExportSettings
params.ReportMakerPath = ""
Ppt2007ExportSettings.ImageQuality = 0.75
Ppt2007ExportSettings.ImageResolution = 300
Ppt2007ExportSettings.PageRange = {}
Ppt2007ExportSettings.PageRange.RangeType = reportmaker.StiRangeType.Pages
Ppt2007ExportSettings.PageRange.PageRanges = "1,4"

local result = reportmaker:makereport(params)
if not result.Succeeded then
    return result.Logtext
else
    return "OK"
end