activePDF KB #11742 - Dynamically Generate a Table Grid
activePDF KB #11742 - Dynamically Generate a Table Grid
Dynamically Generate a Table Grid
Product
Version
Code Samples
Toolkit Lite Toolkit Std Toolkit Pro
4.0
VBS ASP
Description
The following VBScript example demonstrates how to dynamically generate a basic table grid in a PDF.
This file is required:
NOTE: This example is available in other scripts. Choose from the Code Samples list above to display the download link for the language appropriate for your environment.
Click here to download this example for VBScript (includes required file) :
' Variables
' New PDF name
strOutputName = "Table.pdf"
' Page Title Properties
strTitleText = "Table create using DrawTo and PrintMultilineText"
strTitleFont = "Helvetica"
fltTitleFontSize = 24
' Page dimensions (72 units = 1 inch)
fltPageHeight = 792
fltPageWidth = 612
' Margins for Table
fltMarginLeft = 72
fltMarginRight = 72
fltMarginTop = 144
fltMarginBottom = 72
' Table header properties (0 font size = auto size)
strHeadFont = "Helvetica Bold"
fltHeadFontSize = 12
' Table body properties (0 font size = auto size)
strBodyFont = "Helvetica"
fltBodyFontSize = 10
' Table variables
intVisableLines = 1
' Common field and line variables
intTotalRows = 24
intTotalCols = 5
fltRowHeight = ( fltPageHeight - fltMarginTop - fltMarginBottom ) / intTotalRows
fltColWidth = ( fltPageWidth - fltMarginLeft - fltMarginRight ) / intTotalCols
fltMaxTableHeight = fltPageHeight - fltMarginTop - fltMarginBottom
fltMaxTableRows = fltMaxTableHeight \ fltRowHeight
fltMaxTableWidth = fltPageWidth - fltMarginLeft - fltMarginRight
fltMaxTableCols = fltMaxTableWidth \ fltColWidth
fltStartLocX = fltMarginLeft
fltStartLocY = fltPageHeight - fltMarginTop
fltEndLocX = fltPageWidth - fltMarginRight
fltEndLocY = fltMaxTableRows * fltRowHeight
' Visable line properties
intLineWidth = 1
' Added form field properties
fltTableWidth = fltPageWidth - fltMarginLeft - fltMarginRight
' Instantiate Object
Set objTK = CreateObject ("APToolkit.Object")
' OpenOutputFile
lngReturn = objTK.OpenOutputFile ( strOutputName )
If lngReturn <> 0 Then
errorRtn "OpenOutputFile" , lngRtn
Else
objTK.SetFont strTitleFont, fltTitleFontSize, 0
fltTextWidth = objTK.GetTextWidth ( strTitleText )
objTK.PrintText ( fltPageWidth / 2 ) - ( fltTextWidth / 2 ) , 720 , strTitleText, 0
If intVisableLines = 1 Then
' Start drawing process
objTK.LineWidth intLineWidth, 0
objTK.MoveTo fltStartLocX, fltStartLocY, 0
' Horizontal lines
fltCurrentY = fltStartLocY
For intA = 0 to fltMaxTableRows
objTK.DrawTo fltEndLocX, fltCurrentY, 0
fltCurrentY = fltCurrentY - fltRowHeight
objTK.MoveTo fltMarginLeft, fltCurrentY, 0
Next
fltEndLocY = fltCurrentY + fltRowHeight
objTK.MoveTo fltStartLocX, fltStartLocY, 0
' Vertical Lines
fltCurrentX = fltStartLocX
For intB = 0 to fltMaxTableCols + 1
objTK.DrawTo fltCurrentX, fltEndLocY, 0
fltCurrentX = fltCurrentX + fltColWidth
objTK.MoveTo fltCurrentX, fltStartLocY, 0
Next
End If
' CloseOutputFile
objTK.CloseOutputFile
msgbox "Done!"
End If
' Release Toolkit object
Set objTK = Nothing
' Error Return Handling
Sub errorRtn ( strMethod, RtnCode )
msgbox strMethod & " error: " & RtnCode & VBCRLF & _
"http://www.activepdf.com/support/kb/?id=10670&tk=ts"
End Sub
Keywords
OpenOutputFile, GetTextWidth, PrintText, DrawTo, MoveTo, CloseOutputFile, generate, create, generated, form, forms, configure, parameters, build, invoice, table, how, to, method, property, methods, properties, pdf, pdfs, VBS, VBScript, vb, script, example
The information in this article is for the use of activePDF Customers and Evaluation Users Only. No part of this document may be transmitted or reproduced without the express written consent of activePDF.
Copyright © 2005, activePDF, Inc. All Rights Reserved