Do you own a Debenu Quick PDF Library 12/11/10/9/8/7? Upgrade to Debenu Quick PDF Library 13!

Foxit Quick PDF Library

Frequently Asked Question:

Return to FAQ Index

How can I specify which font I want to use when creating tables in a PDF?

Question

How can I specify which font I want to use when creating tables in a PDF?

Answer

In order to specify which font you would like to use when creating tables in a PDF you will need to use the AddTrueTypeFont function to first load the font you wish to use into your document and then you will need the SelectFont function to select that font. Once that has been done you'll need to use the SetHTMLNormalFont function to use the selected font for the text that you will draw in your table.

A C# sample demonstrating this has been included here:

// Load the font into the document, select it and then assign it
int fontID = qp.AddTrueTypeFont("Microsoft Sans Serif", 1);
qp.SelectFont(fontID);
qp.SetHTMLNormalFont("Default", fontID);
// Set the page size of the new document
qp.SetPageSize(PageSize);

// Create the table and specify the number of rows and columns
int tableID = qp.CreateTable(5, 5);

// Specify color and width of borders   
qp.SetTableBorderColor(tableID, 0, 0.3, 0.204, 0);
qp.SetTableBorderWidth(tableID, 0, 0.2);

// Specify table row height and table column width
qp.SetTableRowHeight(tableID, 1, 5, 0);
qp.SetTableColumnWidth(tableID, 1, 5, 100);

// Specify a background color for the column headers
qp.SetTableCellBackgroundColor(tableID, 1, 1, 1, 5, 0.201, 0.100, 0.235);
qp.SetTableCellAlignment(tableID, 1, 1, 1, 5, 4);

// Setup the column headers for the first row
qp.SetTableCellContent(tableID, 1, 1, "<b>This Week</b>");
qp.SetTableCellContent(tableID, 1, 2, "<b>Last Week</b>");
qp.SetTableCellContent(tableID, 1, 3, "<b>Artist Name</b>");
qp.SetTableCellContent(tableID, 1, 4, "<b>Peak</b>");
qp.SetTableCellContent(tableID, 1, 5, "<b>Weeks On</b>");

// Insert the content for the second row
qp.SetTableCellContent(tableID, 2, 1, "1");
qp.SetTableCellContent(tableID, 2, 2, "1");
qp.SetTableCellContent(tableID, 2, 3, "<b>The Black Eyed Peas</b><br>Boom Boom Pow");
qp.SetTableCellContent(tableID, 2, 4, "<b>1</b>");
qp.SetTableCellContent(tableID, 2, 5, "<b>11</b>");

// Draw the table onto the document
double s = qp.DrawTableRows(tableID, 50, 800, 400, 1, 0);

// Save the document to disk
qp.SaveToFile(output);

© 2015 Debenu & Foxit. All rights reserved. AboutBuyContactBlogNewsletterSupportFAQProduct UpdatesForum