Tornado Class Library

Special Topic - Pdf Report

Traditionally, ASP-db produces very comprehensive reports in the Html screen format. ASP-db output are incorporated into Excel, Word and other tools to compose a report and then printed to Pdf file. This process takes a lot of time and is not automated. The Tornado new feature (dbPdf) enables user to generate a customized ASP-db Pdf report. A customized ASP-db Pdf report is one that user can design the Pdf page content like page size, header, footer, ASP-db output, security and delivery format. In conjunction with the template feature of Tornado, users now can produce very advanced Web database applications nobody else can.

We have implemented a lot of Pdf features to cover many aspects like Page Control, Document Security and Info as well as streamline them such that it is easy to use. For example, you can produce a pdf report that contains a grid from the database, project information from another table and deliver to different users with their profiles stored in yet another table.

See example #6 for a complete application with the ASP-db application with a magicell link to generate a Pdf report. The entire application is less than 30 lines of code! Can you feel the power of ASP-db.Net (Tornado)?

 

Syntax

 

obj.AspdbUrlPdf() = Method to render stand alone application output to a Pdf file. See example #7.

obj.dbPDF = "(;,|!)BaseURL | Cover | EmbedFonts | HtmlAppend | ImageFT | ImageHD | ImageWM | Info | Link | Orientation | PageSize | PdfAppend | Savefile | Security | Security | SetupFT | SetupHD | TextFT | TextHD | TextWM| Url"

(;,|!) = Property Delimiters - [;] Delimits repeated options within a keyword, [,] delimits values within options, [|] Delimits keywords, [!] Delimits Options within keyword

 

Document Properties

 

Keyword / Options

Default

Description

Url

blank

Url of an application program in which the output will be rendered into a Pdf file inheriting the rest of the dbPdf properties. In some situation, the HTML output is not static and the data will not be rendered. The inline dbBLOB is such an example where the display of BLOB is via the repeated execution of the html code. Static code in this case will be not be able to be rendered in Pdf. In this case you can use this option to render the Pdf.

BaseURL

blank

The urlBase parameter allows the Pdf converter to determine the full URLs from relative URLs for images and CSS files appearing in the HTML file. When a relative URL from the HTML string is prefixed by the urlBase, the correct full URL of the image or of the CSS file should be produced. When the urlBase is not null, the converter automatically inserts a <BASE HREF="urlBase"> tag under the HEAD tag from the HTML file. If the HTML string does not contain a HEAD tag, the urlBase parameter does not have any effect.

Cover

blank

Path of the cover page file in html format. If not blank, this cover file will be added to the beginning of the pdf report. Normally, FirstPage of header and footer should be false to prohibit header and footer be placed in the cover page. The actual format is physical but you can use virtual address and let the system convert that to physical address.

EmbedFonts

true

Embed fonts in Pdf document.

FitWidth

true

Set if the HTML content is resized if necessary to fit the PDF page width.

Info

blank

Set document information parameters. 

Author

blank

Set the name of the PDF document author.

Subject

blank

Set the subject of the PDF document.

Keywords

blank

Set the keywords of the PDF document delimited by [,]. 

Title

blank

Set the title of the PDF document.

Date

today

Set the create date of the PDF document.

Link

true

Enable live Http links in Pdf Document

Orientation

Portrait

Set page orientation.

PaperSize

A4

A0, A1, A10, A2, A3, A4, A5, A6, A7, A8,, A9,, ArchA, ArchB, ArchB, ArchC, ArchD, ArchE, B0, B1, B2, B3, B4, B5, Custom, Flsa, HalfLetter, Ledger, Legal, Letter, Letter11x17, Note.

SaveFile

inline

Filename (attachment) of saved pdf file. If blank then pdf file is delivered to the browser (inline). if no extension is specified then '.pdf' will be appended to the filename.

Security

blank

Set document security parameters.

User

blank

User password of pdf file. If not blank then a user password will be applied to the file. When you set a user password the PDF document is encrypted and that password will be asked by the PDF viewer in order to open the PDF document

Owner

 

blank

Owner password of pdf file. When you set the owner password that password will be required when someone wants to change the PDF permissions. If the Owner option is blank and the User is not blank, the Owner will be automatically assigned with the value from User and when the PDF document is opened in the viewer using the user password (which is also the owner password) all the operations like printing, copying, etc will be allowed.

Copy

true

Allow user to copy document content.

Edit

true

Allow user to edit document content.

FillForm

true

Allow form fields tp be filled. This option has effect when a 128 bit key is used. To disable form filling the Edit and Annotate must be set to false.

Print

true

Allow user to print document content.

Annotate

 

true

Allow user to edit document annotations.

KeySize

40

Set the encryption key size. By default a 40 bit key is used.


 

Header Properties

 

Keyword / Options

Default

Description

SetupHD

blank

Setup the general header parameters. If blank then no header.

Height

50

Setup header height in pixels.

Line

true

Draw a line between header and content.

FirstPage

true

Apply header to first page. Cover page usually does not have header and footer and should be set to false.

EvenPage

false

Apply header to even pages only.

Odd Page

false

Apply header to odd pages only.

HtmlPath

 blank

Specify header html file.

xy

0,0

Offset (pixel) of header html file.

ImageHD

blank

Setup Image(s) in the header. If blank then no custom image in header.

ImagePath

blank

Virtual path of image file. Delimit multiple images with [;].

xy

0,0

Image offset (pixel). Manually position the image in header.

width

blank

Image width (pixel). Self adjust according to the image original width and height ratio when blank. Should only specify only one.

height

blank

Image height (pixel). Self adjust according to the image original width and height ratio when blank. Should only specify only one.

TextHD

 

Setup custom text in the header. If blank then no custom text for header.

Text

blank

If this is blank then no custom text in header. Delimit multiple text with [;]. One special feature about text in header and footer is the special macro &P0 and &P1. For example, &P0 of &P1 will be translated to Page 1 of 5. Another macro is the timestamp macro - &dt(Format). Example - &dt(MMM-dd-yy HH:mm).

y

0

This is a preferred and easy way to place text. Set the 'y' offset only and let system align the text using 'align' (usually center). The alternative is to use 'xy' and 'width' to manually place the text. When you automate the report and have different header text for different report then you must use this property to center the text. NOTE: This can be only used in the first text element. All elements after that must use xy instead.

xy

0,0

Text offset (pixel).

width

200

Text container width (pixel). Allocate appropriate width to avoid text wrap.

align

LEFT

Text alignment -  CENTER, DEFAULT, JUSTIFY, LEFT, RIGHT. When using with 'y' it align with the header. When use with 'xy' and 'width' it aligns to the container.

Font

HELVETICA

Header text font - COURIER, COURIERBOLD, COURIERBOLDOBLIQUE, COURIEROBLIQUE, HELVETICA, HELVETICABOLD, HELVETICAOBLIQUE, HELVETIVABOLDOBLIQUE, TIMESBOLD, TIMESBOLDITALIC, TIMESITALIC, TIMESROMAN

Size

18

Text size.

Color

BLACK

Text color -  ALICEBLUE, ANTIQUEWHITE, AQUA, AQUAMARINE, AZURE, BEIGE, BISQUE, BLACK, BLANCHEDALMOND, BLUE, BLUEVIOLET, BROWN, BURLYWOOD, CADETBLUE, CHARTREUSE, CHOCOLATE, CORAL, CORNFLOWERBLUE, CORNSILK, CRIMSON, CYAN, DARKBLUE, DARKCYAN, DARKGOLDENROD, DARKGRAY, DARKGREEN, DARKKHAKI, DARKMAGENTA, DARKOLIVEGREEN, DARKORANGE, DARKORCHID, DARKRED, DARKSALMON, DARKSEAGREEN, DARKSLATEBLUE, DARKSLATEGRAY, DARKTURQUOISE, DARKVIOLET, DEEPPINK, DEEPSKYBLUE, DIMGRAY, DODGERBLUE, FIREBRICK, FLORALWHITE, FORESTGREEN, FUCHSIA, GAINSBORO, GHOSTWHITE, GOLD, GOLDENROD, GRAY, GREEN, GREENYELLOW, HONEYDEW, HOTPINK, INDIANRED, INDIGO, IVORY, KHAKI, LAVENDER, LAVENDERBLUSH, LAWNGREEN, LEMONCHIFFON, LIGHTBLUE, LIGHTCORAL, LIGHTCYAN, LIGHTGOLDENRODYELLOW, LIGHTGRAY, LIGHTGREEN, LIGHTPINK, LIGHTSALMON, LIGHTSEAGREEN, LIGHTSKYBLUE, LIGHTSLATEGRAY, LIGHTSTEELBLUE, LIGHTYELLOW, LIME, LIMEGREEN, LINEN, MAGENTA, MAROON, MEDIUMAQUAMARINE, MEDIUMBLUE, MEDIUMORCHID, MEDIUMPURPLE, MEDIUMSEAGREEN, MEDIUMSLATEBLUE, MEDIUMSPRINGGREEN, MEDIUMTURQUOISE, MEDIUMVIOLETRED, MIDNIGHTBLUE, MINTCREAM, MISTYROSE, MOCCASIN, NAVAJOWHITE, NAVY, OLDLACE, OLIVE, OLIVEDRAB, ORANGE, ORANGERED, ORCHID, PALEGOLDENROD, PALEGREEN, PALETURQUOISE, PALEVIOLETRED, PAPAYAWHIP, PEACHPUFF, PERU, PINK, PLUM, POWDERBLUE, PURPLE, RED, ROSYBROWN, ROYALBLUE, SADDLEBROWN, SALMON, SANDYBROWN, SEAGREEN, SEASHELL, SIENNA, SILVER, SKYBLUE, SLATEBLUE, SLATEGRAY, SNOW, SPRINGGREEN, STEELBLUE, TAN, TEAL, THISTLE, TOMATO, TRANSPARENT, TURQUOISE, VIOLET, WHEAT, WHITE, WHITESMOKE, YELLOW, YELLOWGREEN


 

Footer Properties

 

Keyword / Options

Default

Description

SetupFT

blank

Setup the general footer parameters. If blank then no footer.

Height

50

Setup footer height in pixels.

Line

true

Draw a line between footer and content.

AutoPage

false

Add the text 'Page n of t'  to the right hand side of the footer. n=page number; t=total number of pages. No need to use &P0 and &P1.

YAutoPage

0

'y' offset of the page numbering text. Should be the same as the other text.

FontAutoPage

HELVETICA

Font type of the page numbering text.

FmtAutoPage

Page n of t

Page numbering string format. n = page number; t=total number of pages.

SizeAutoPage

8

Font size of the page numbering text.

FirstPage

true

Apply footer to first page. Cover page usually does not have header and footer and should be set to false.

EvenPage

false

Apply footer to even pages only.

Odd Page

false

Apply footer to odd pages only.

HtmlPath

 blank

Specify footer html file.

 xy

0,0

Html File offset (pixel).

ImageFT

blank

Setup Image(s) in the footer. If blank then no custom image in footer.

Path

blank

Virtual path of image file. Delimit multiple images with [;].

xy

0,0

Image offset (pixel).

width

blank

Image width (pixel). Self adjust when only height is specified. Do not specify both.

height

blank

Image height (pixel). Self adjust when only width is specified. Do not specify both.

TextFT

blank 

Setup custom text in the footer. If blank then no custom text for footer.

Text

blank

If this is blank then no custom text in footer. Delimit multiple text with [;]. One special feature about text in header and footer is the special &P0 and &P1. For example, &P0 of &P1 will be translated to Page 1 of 5.

xy

0,0

Same as header.

y

0

This is a preferred and easy way to place text. Set the 'y' offset only and let system align the text using 'align' (usually center). The alternative is to use 'xy' and 'width' to manually place the text. When you automate the report and have different header text for different report then you must use this property to center the text. NOTE: This can be only used in the first text element. All elements after that must use xy instead.

width

200

Same as header.

align

LEFT

Same as header. 

Font

HELVETICA

Same as header. 

Size

10

 Same as header. 

Color

BLACK

 same as Header.


 

Watermark Properties

 

Multiple text and image watermarks can be placed in the document pages.
 

Keyword / Options

Default

Description

ImageWM

blank

Watermark image parameters.

Path

blank

Physical path of image or html file containing the image.

xy

0,0

Offset from Rectangle

Rectangle

0,0,100,50

x, y, width, height of image container.

Angle

0

Angle of image - counterclockwise. You must adjust Rectangle to hold the angled element.

Transparency

25

Image transparency.

TextWM

blank 

Watermark text parameters.

Text

blank 

Watermark text.

xy

0,0

Offset from Rectangle.

Rectangle

0,0,100,50 

x, y, width, height of rectangle image container.

Angle

0 

Angle of text - counterclockwise. You must adjust Rectangle to hold the angled element.

Transparency

25

Text transparency.

Font

HELVETICA

Same as header.

Size

18

Same as header.

Color

BLACK

Same as header.

 

Append File Properties

 

Keyword / Options

Default

Description

HtmlAppend

blank

Virtual paths of Html files to be appended. Header and footer will apply to these pages. Files are delimited with [;]

PdfAppend

blank

Physical paths of Pdf files to be appended. Header and footer will not apply to these pages. Files are delimited with [;]


 

Notes

 

 

Example 1 - Basic ASPdb output to Pdf

This basic simple example redirects the ASP-db html output to a PDF file in an inline format. Inline means the Pdf file will display in the browser instead of prompting to save as a file. Specify any of the dbPdf properties will activate the Pdf report action.

<script language="VB" runat="server">
Sub Page_Load(Src As Object, E As EventArgs)
   Dim x As New Tornado.z
   x.dbQP = "U=2| M=Grid| S=1| ps=-1| ni=none| DSN=Nwind| gdf=0,1,3,4,5| th=tit=ASPdb Report"
   x.dbSQL = "Select * from Orders where Employeeid = 1"
   x.dbPdf = "Pagesize=A4"
   x.ASPdbNET()
End Sub
</script> 

 

Example 2 - Pdf with password

This example shows how to specify document info and assign a password to the Pdf file. After the Pdf file is displayed, right click and check document properties and you'll see the Author field being set. A password (aspdb) is needed to view the file in browser or as a saved file.

<script language="VB" runat="server">
Sub Page_Load(Src As Object, E As EventArgs)
   Dim x As New Tornado.z
   x.dbQP = "U=2| M=Grid| S=1| ps=-1| ni=none| DSN=Nwind| gdf=0,1,3,4,5| th=tit=ASPdb Report"
   x.dbSQL = "Select * from Orders where Employeeid = 1"
   x.dbPdf = "Security=User=aspdb| Info=Author=Frank Kwong"
   x.ASPdbNET()
End Sub
</script>  

 

Example 3

In this example, we'll add simple header and footer to the Pdf document. Header height is 40 Px. There are two text element. Text 1 is centered and Text 2 is at 630,15 and of size 8 in the header. SInce we have a very fancy header, the ASP-db header is disabled by not specifying title in the text-holder (th).

The footer is also 40 Px high. Auto Page number system is set to true, The Auto Page text has a y offset of 10 Px and right aligned. There are additional 2 Text elements. Text 1 is centered and Text 2 is a timestamp located at 5,10 and of size 8 and blue color. Note that the only text element that can align is Text element #1. This align (usually center) effect can be used to align different text hence make dynamic text possible. Dynamic text enables the Pdf report to be delivered to difference users with a customized look.

<script language="VB" runat="server">
Sub Page_Load(Src As Object, E As EventArgs)
   Dim x As New Tornado.z
   x.dbQP = "U=2| M=Grid| S=1| ps=-1| ni=none| DSN=Nwind| gdf=0,1,3,4,5"
   x.dbSQL = "Select * from Orders where Employeeid = 1"
   x.dbPdf = "Security=User=aspdb| Info=Author=Frank Kwong |" & _
      "SetupHD=he=40| " & _
      "TextHD=Text=Northwind Sales Report! y=10! siz=14! align=center; Text=Prepared by Frank Kwong! xy=630,15! siz=8 |" & _
      "SetupFT=he=40! AutoPage=t! Yautopage=10 |" & _
      "TextFT=Text=Northwind Report Sept 2009! y=10! align=center; Text=&dt(MMM-dd-yy HH:mm)! xy=5,10! siz=8! co=blue"
   x.ASPdbNET()
End Sub
</script> 

 

 

Example 4 - Pdf with custom Header and Footer

In this example, we'll use an Html file as header. In addition to that, a text #1 element is overlaid and centered in the header. Besides using the text element as in Example 3, a footer .gif image is overlaid on the left (xy=0,0 default). The height of the image is specified as 30 Px to fit in the 40Px footer height. You can specify either the width or the height of the image and let the other dimension scaled automatically.

<script language="VB" runat="server">
Sub Page_Load(Src As Object, E As EventArgs)
   Dim x As New Tornado.z
   x.dbQP = "U=2| M=Grid| S=1| ps=-1| ni=none| DSN=Nwind| gdf=0,1,3,4,5"
   x.dbSQL = "Select * from Orders where Employeeid = 1"
   x.dbPdf = "Security=User=aspdb| Info=Author=Frank Kwong |" & _
      "SetupHD=he=100! htmlpath=http://localhost/mysite8/MyHeader.html | " & _
      "TextHD=Text=Sept 2009 Sales Report! y=60! siz=14! align=center! color=red |" & _
      "SetupFT=he=40! AutoPage=t! Yautopage=10 |" & _
      "TextFT=Text=Northwind Report Sept 2009! y=10! align=center; Text=&dt(MMM-dd-yy HH:mm)! xy=5,10! siz=8! co=blue" & _
      "ImageFT=Path=http://localhost/mysite8/nwind.gif! height=30"
   x.ASPdbNET()
End Sub
</script> 

 

Example 5 - Cover page and appended pages

In this example,  we insert several type of pages in the document -

<script language="VB" runat="server">
Sub Page_Load(Src As Object, E As EventArgs)
   Dim x As New Tornado.z
   x.dbQP = "U=1|s=plain|d=NWIND|Q=Orders|ni=none|ps=100|Gdf=0,1,2,3,4,5"
   x.dbPdf = "Savefile=aspdb| Cover=http://localhost/mysite8/MyCover.html |" & _
      "Security= User=aspdb|" & _
      "Info=Author=Frank Kwong|" & _
      "SetupHD=Line=false! he=120! FirstPage=false! html=path=http://localhost/mysite8/MyHeader.html |" & _
      "ImageHD=path=http://localhost/mysite8/nwind.gif! xy=200,50! wi=75; path=http://localhost/mysite8/nwind.gif! xy=550,50! wi=75 |" & _
      "TextHD=Text=Northwind Sales!Color=blue!style=bold!xy=300,5!wi=300; Text=Pdf Report!Color=red!xy=350,60!size=14!wi=300 |" & _
      "SetupFT=he=55! ShowPage=t! FirstPage=false! html=path=http://localhost/mysite8/MyFooter.html | " & _
      "TextFT=Text=Page &P0 of &P1!xy=700,25!wi=200!si=8!co=red; Text=&dt(MMM-dd-yy HH:mm) !xy=45,25!co=blue!siz=8 |" & _
      "HtmlAppend=http://localhost/mysite8/chart1.gif |" & _
      "PdfAppend=D:\T2005\mysite8\W9.pdf; D:\T2005\mysite8\cloud.pdf |" & _
      "ImageWM=path=D:\T2005\MySite8\logo.gif!border=rect!tran=5|" & _
      "TextWM=Text=This is WaterMark!Tran=5"
   x.ASPdbNET()
End Sub
</script> 

 

Example 6 - ASPdb MagicCell linked to Pdf report

In this example,  we have 2 modules. #1 pops the pdf report according to #2's querystring. #2 is a standard ASP-db application with one of the column linked to pop the Pdf report. You can customize the popup pdf report window by modifying the 'pop' variable.

 

<script language="VB" runat="server">
Sub Page_Load(Src As Object, E As EventArgs)
   Dim thisPageURL As String = Request.Url.AbsoluteUri
   Dim base As String = thisPageURL.Substring(0, thisPageURL.LastIndexOf("/") + 1) '...http://root/site/
   Dim thisPageURL As String = Request.Url.AbsoluteUri
   Dim base As String = thisPageURL.Substring(0, thisPageURL.LastIndexOf("/") + 1) '...http://root/site/
   Dim myself = Request.ServerVariables("SCRIPT_NAME")
   Dim emp As String = "", EmpName As String = ""
   If Not IsNothing(Request.QueryString("Emp")) And Request.QueryString("Emp") <> "" Then 
'... Module 1 : Popup Pdf application according to querystring passed by module 2
      emp = Request.QueryString("Emp")
      EmpName = Request.QueryString("EmpName")
      Dim x As New Tornado.z
      x.dbQP = "U=2| M=Grid| S=1| ps=-1| ni=none| DSN=Nwind| gdf=0,1,3,4,5"
      x.dbSQL = "Select * from Orders where Employeeid = " & emp
      Dim pstr As String = "Security=User=aspdb| Info=Author=Frank Kwong |" & _
         "SetupHD=he=40| " & _
         "TextHD=Text=Sales Report of {0} ! y=10! siz=14! align=center; Text=Prepared by Frank Kwong! xy=630,15! siz=8 |" & _
         "SetupFT=he=40! AutoPage=t! Yautopage=10 |" & _
         "TextFT=Text=Northwind Report Sept 2009! y=10! align=center; Text=&dt(MMM-dd-yy HH:mm)! xy=5,10! siz=8! co=blue| " & _
         "ImageHD=path={1}! wi=48 |" & _ 
         "ImageWM=path=D:\T2005\MySite8\logo.gif!border=rect!tran=25"
      x.dbPdf = String.Format(pstr, EmpName, base & "nwind.gif")
      x.ASPdbNET()
   Else 
'... Module 2 : Normal ASP-db application with MagicCell link to pop Pdf report
      Dim pop As String = "<A HREF='" & myself & "?Emp=#0#&EmpName=#2# #1#' " & _
         "Target='PDFwin' onClick=""window.open('','PDFwin', " & _
         "'width=700, height=900, left=400, top=400, directories=no, menubar=no, toolbar=no, status=no, resizable=yes')"">" & _
         "Report for #2# #1#</A>"
      Dim Mydb As New Tornado.z
      With Mydb
         .dbQP = "U=2| M=Grid| S=1| ps=-1| ni=none| DSN=Nwind| gdf=0,1,2,3| Q=Employees"
         .dbTextHolder = "G3=<hr><h2>Pdf File password = ASPDB</h2>| Tit=Northwind Sales Report"
         .dbMagicCell = "(;![]#|~/+{})f=3| mac=" & pop
         .ASPdbNET()
      End With
   End If 
End Sub
</script> 

 

Example 7 - External Aspdb applications to Pdf

In this example,  we execute an ASPdb application and render the output to a Pdf file. The application pointed to by the url of the example uses dbBLOB to display the images. A direct render of this application will cause the BLOB image to fail. The way to obtain a successful render in this case is to use the 'url' option.

 

<script language="VB" runat="server">
Sub Page_Load(Src As Object, E As EventArgs)
   Dim x As New Tornado.z
   x.dbPdf = "Security=User=aspdb| Info=Author=Frank Kwong | url=http://www.aspdb.com/tornadomanual09/_Code_Repeater1.aspx |" & _
      "SetupHD=he=40| " & _
      "TextHD=Text=Northwind Sales Report! y=10! siz=14! align=center; Text=Prepared by Frank Kwong! xy=630,15! siz=8 |" & _
      "SetupFT=he=40! AutoPage=t! Yautopage=10 |" & _
      "TextFT=Text=Northwind Report Sept 2009! y=10! align=center; Text=&dt(MMM-dd-yy HH:mm)! xy=5,10! siz=8! co=blue"
   x.ASPdbUrlPdf()
End Sub
</script> 

 


Send comments on this topic.
Copyright 1998-2010 ASP-db