Using the Report

From BKeeney Shorts Documentation
Jump to: navigation, search

Displaying the Report

Displaying the report with the BKS_ShortsViewer canvas subclass is easy. Simply assign the document to the viewer instance.

BKS_ShortsViewerInstance.Document = oShortsDocumentObject

Use the GotoPage, NextPage, and PreviousPage methods to change which page is displayed in the viewer.
The BKS_ShortsViewer class will handle scrolling, positioning, and zooming of the report. To zoom change the scale BKS_ShortsViewerInstance.Scale = 2.0

For convenience, the BKS_ShortsViewer also has several "Fit To…" methods.

Printing the Report

Printing is a lot like displaying the report onscreen, Shorts uses the same renderer but at print resolution. In this example the print resolution and a Graphics object is obtained from the Xojo printer methods.

// Now setup the graphics object for printing
dim g as Graphics
dim oPageSetup as new PrinterSetup

// Create a PrinterSetup object to get the resolution from the printer
oPageSetup.MaxHorizontalResolution = 300
oPageSetup.MaxVerticalResolution = 300

if oPageSetup.PageSetupDialog then
g = OpenPrinterDialog(oPageSetup)
end

// Did something go wrong?
if g = nil then return

Create a View object to render the page with, and render the Page object using the BKS_Shorts.GraphicsRenderer.

// Create the View
dim oView as new BKS_Shorts.View
oView.ViewLeft = oPageSetup.PageLeft
oView.ViewTop = oPageSetup.PageTop
oView.ViewWidth = iPageWidth
oView.ViewHeight = iPageHeight
oView.Scale = dScale

// Render the page into the view
dim oRenderer as new BKS_Shorts.GraphicsRenderer(g)
oPage.Render(oRenderer, oView)

The Graphics object from the Printer is passed into the BKS_Shorts.GraphicsRenderer, so when the Page object renders using the GraphicsRenderer object the report is sent to the printer!

To print multiple copies or to print select pages see the "Print Report Definition" example in the Shorts demo project. This example code covers the basics for looping through multiple copies and pages.

Exporting to PDF

BKeeney Shorts can export a report to PDF with the assistance of the DynaPDF Plugin To use the PDF renderer be sure the BKS_ShortsDynaPDF module is included. Create an instance of the BKS_Shorts.PDFRenderer object, and pass the destination FolderItem to the Constructor. Then, just like rendering to a Graphics object, render the page with the PDFRenderer object.

// Use a temporary folder item to render to
dim fTemp as FolderItem = GetTemporaryFolderItem

// Get a FolderItem to store our PDF
dim fDestination as FolderItem = GetSaveFolderItem("", "test.pdf")

// Check if user cancelled
if fDestination = nil then return

// Create our view
dim oView as new BKS_Shorts.View
oView.ViewLeft = 0
oView.ViewTop = 0
oView.Scale = 1.0

// Create DynaPDF Renderer
dim oRenderer as new BKS_ShortsDynaPDF.Renderer(fTemp)

// Now Render
oDoc.Render(oRenderer, oView)

// Move temporary file to selected destination
fTemp.MoveFileTo(fDestination)

Exporting to HTML

BKeeney Shorts can export a report to HTML. Create an instance of the BKS_Shorts.HTMLRenderer object, and pass the destination FolderItem to the Constructor. Then, just like rendering to a Graphics object, render the page with the PDFRenderer object.

// Create our view
dim oView as new BKS_Shorts.View
oView.ViewLeft = 0
oView.ViewTop = 0
oView.ViewWidth = oPage.Width
oView.ViewHeight = oPage.Height
oView.Scale = 1.0

// Create the HTML Renderer
dim fTemp as FolderItem = GetTemporaryFolderItem
dim oRenderer as new BKS_Shorts.HTMLRenderer(fTemp)

// Now Render
oDoc.Render(oRenderer, oView)

// The page is ready to go!
HTMLViewerInstance.LoadPage(fTemp)

Exporting to CSV

Using the CSV Renderer class you can generate CSV from your report template.