Home

PDFDoc Scout

PDFDoc Scout screenshot (click to enlarge)


 Products  |  Download  |  Purchase  |  Support  |  Contacts  |  Testimonials |  
PDFDoc Scout library - Sample

Download Free Trial See Licensing Options More Information

How to draw tables to PDF document using HTML text format and PDFDoc Scout library: 

You can download the source code of this example here: pdfdocscout_drawing_table_using_html_formatting.zip

This example describes how to draw tables in generated PDF document with easy using built-in HTML text formatting support in PDFDoc Scout library

Screenshot of generated PDF document with HTML coded table:

Table created using HTML text formatting in PDF document generated by PDFDoc Scout

Code to compose HTML code for table and draw this table in PDF:

PDFDoc.InitLibrary "demo", "demo"
PDFDoc.OutputFilename = "draw_table.pdf"
PDFDoc.AutoOpenGeneratedPDF = true

PDFDoc.BeginDocument

' compose HTML code for Table with 4 columns and 5 rows (header + 4 rows)
TableHeader = "<table border='1' cellspacing='2'>"
TableFooter = "</table>"

Dim RowHeaders(5), RowFooters(5), Cells(5)

RowHeaders(1) = "<tr bgcolor='#0000CC'>" ' header row
RowHeaders(2) = "<tr bgcolor='#CCCCCC'>"
RowHeaders(3) = "<tr>"
RowHeaders(4) = "<tr bgcolor='#CCCCCC'>"
RowHeaders(5) = "<tr>"

RowFooters(1) = "</tr>" ' header row
RowHeaders(2) = "</tr>"
RowHeaders(3) = "</tr>"
RowHeaders(4) = "</tr>"
RowHeaders(5) = "</tr>"


' Header cells
Cells(1) = "<td valign='middle'><font color='#FFFFFF'><strong>Computer location</strong></font></td>" & "<td valign='middle'> <font color='#FFFFFF'><strong>Does it have a network adapter?</strong></font></td>" & "<td valign='middle'> <font color='#FFFFFF'><strong>What kind of modem?</strong></font></td>" & "<td valign='middle'> <font color='#FFFFFF'><strong>Other hardware devices</strong></font></td>"
' data cells
Cells(2) = "<td valign='middle'>Den</td><td valign='middle'> Ethernet</td><td valign='middle'> <p align='center' >DSL</p></td><td valign='middle'> Printer, scanner</td>"
Cells(3) = "<td valign='middle'>Son's bedroom</td><td valign='middle'> No</td><td valign='middle'> <p align='center' >56 kilobits per second (Kbps) analog modem</td></p> <td valign='middle'> Digital camera</td>"
Cells(4) = "<td valign='middle'>Daughter's bedroom</td><td valign='middle'> No</td><td valign='middle'> <p align='center' >No modem</p></td><td valign='middle'> Scanner</td>"
Cells(5) = "<td valign='middle'><img src='sample.png' width=48 height=48><br/>Library</td><td valign='middle'>Ethernet</td><td valign='middle'><p align='center' >No modem</p></td><td valign='middle'>Printer</p></td>"

' now composing HTML code for whole table
TableCode = TableHeader

For i=1 to 5
' add new row and its header
TableCode = TableCode & RowHeaders(i)
' add cells for this row
TableCode = TableCode & Cells(i)
' add row footer
TableCode = TableCode & RowFooters(i)
Next

' adding table footer
TableCode = TableCode & TableFooter

' finally add HTML box to the current page

PDFDoc.Page.AddHTMLBox TableCode, 20,80,PDFDoc.Page.Width-40, PDFDoc.Page.Height-40, false

PDFDoc.EndDocument ' close PDF document generation

' disconnect from library
Set PDFDoc = Nothing

You can download the source code of this example here: pdfdocscout_drawing_table_using_html_formatting.zip 

Download Free Trial See Licensing Options More Information


See also: Bytescout.PDF - native .NET library to write/read/sign/
modify/merge/split PDF documents (but no HTML2PDF support)



On-line documentation (HTML format)


"Hello, World!" quick start step-by-step tutorials:

Products  |  Download  |  Purchase  |  Support  |  Contacts  |  Testimonials |  

ByteScout, 2003-2008. All other company and product names may be trademarks of their respective companies. Privacy Statement