Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > I need help - I can help
  New Posts New Posts RSS Feed - Tables and Columns
  FAQ FAQ  Forum Search   Register Register  Login Login

Tables and Columns

 Post Reply Post Reply
Author
Message
HNRSoftware View Drop Down
Senior Member
Senior Member


Joined: 13 Feb 11
Location: Washington, USA
Status: Offline
Points: 88
Post Options Post Options   Thanks (0) Thanks(0)   Quote HNRSoftware Quote  Post ReplyReply Direct Link To This Post Topic: Tables and Columns
    Posted: 30 Nov 11 at 1:36PM
I probably should explore this with trial and error, but I thought I would ask for a general opinion first.  I am looking to create pricelist PDFs directly (library version 7.23, probably will upgrade to 8).
 
From a database, I will assemble a long list of items and prices with mild tab-oriented formatting - like "IDxxx  <tab>Description     <tab-right justified>Price".  I will want to output this in 2 or 3 columns per page with a small amount of additional text at grouping boundaries and a small amount of checking on orphans (a group starting at the bottom of a column).  
 
It appears to me that there are appropriate and sufficient table-oriented calls to do this in a straight-forward and reasonably general way.  I currently do similar tasks in Delphi writing strings to bitmap canvas and doing all the limit checking, but the calls don't map very closely to the PDF library functions.  I also use html tables (which seem similar in structure to what you are implementing here), but html pretty much runs into a wall when thinking about columns.
 
All I'm really looking for in an answer is "Go for it" or "Try something else".  The table/row/column/cell calls look like they will take some getting used to, but I think the pieces are all there.
 
Thanks - Howard
Back to Top
Rowan View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 10 Jan 09
Status: Offline
Points: 398
Post Options Post Options   Thanks (0) Thanks(0)   Quote Rowan Quote  Post ReplyReply Direct Link To This Post Posted: 01 Dec 11 at 9:34AM
Hi Howard,

In short: go for it.

The table functions will help you layout the columns relatively easily. The table functions also make drawing the content onto multiple pages easy, so you shouldn't have too many issues here. You can use the libraries HTML tags to style the content in the table as well.

You could also do this stuff using the DrawText, GetTextWidth, GetTextHeight, etc, functions but the table stuff will probably be the easiest to start with.

Cheers,
- Rowan.
Back to Top
HNRSoftware View Drop Down
Senior Member
Senior Member


Joined: 13 Feb 11
Location: Washington, USA
Status: Offline
Points: 88
Post Options Post Options   Thanks (0) Thanks(0)   Quote HNRSoftware Quote  Post ReplyReply Direct Link To This Post Posted: 01 Dec 11 at 1:29PM
Hi Rowan - thanks for the encouragement.  Just looking over the table-oriuented calls (v7.23), I think there are a couple of missing pieces that mean that I will need to go to the DrawText level instead.  One piece that I think is missing is the equivalent of html "ColSpan" which would be necessary for lines on the grouping level which would not fit into the cells.  I will miss the cell-level formating options, but DrawHTMLText looks encouraging, although I can't spot any align="right" support, but I should be able to implement that by using GetHTMLTextWidth.  Thanks - Howard
 
Back to Top
greymont View Drop Down
Beginner
Beginner
Avatar

Joined: 21 May 12
Status: Offline
Points: 11
Post Options Post Options   Thanks (0) Thanks(0)   Quote greymont Quote  Post ReplyReply Direct Link To This Post Posted: 21 May 12 at 10:54AM
I am just looking at QP for an application that has very similar requirements as HNRSoftware has described here. Database table that needs to be rendered into PDF form with many records interspersed with header/grouping information every so often.

I am also looking at the table API calls to accomplish this. But I'm not finding any documentation on the design ideas behind the table API calls. Is there a write up that provides a tutorial explanation of these? What I'm looking for is a statement/explanation of how they are intended to be used. What I'm looking for is a "theory of operation".

Here are some specific questions I have that might be answered in such a document:
Does a "table" exist as part of a page or as part of a document? Can there be more than one table at a time? If one at a time, how do I "clear" a table to start adding rows for another one?
 
Back to Top
AndrewC View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 08 Dec 10
Location: Geelong, Aust
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote AndrewC Quote  Post ReplyReply Direct Link To This Post Posted: 22 May 12 at 12:51PM
Here is some code I found relating to table.  There are 3 separate samples here.

1. 

            QP.SetPageSize("Letter");
            QP.SetOrigin(1);
            int tableID = QP.CreateTable(2,2);
            QP.SetTableCellContent(tableID, 1, 1, "Something");
            QP.SetTableColumnWidth(tableID, 1, 1, 10);
            QP.SetTableColumnWidth(tableID, 1, 2, 60);
            QP.SetTableCellContent(tableID, 2, 2, "A line of text.");
            QP.SetTableCellContent(tableID, 2, 1, "A 2nd line of text.");

            QP.SetTableBorderWidth(tableID, 0, 0);
            QP.SetTableCellBorderWidth(tableID, 1, 1, 2, 2, 0, 0.02);

            double TableHeight = QP.DrawTableRows(tableID,36,36, QP.PageHeight() - 72, 1, 0);

            QP.SaveToFile("out.pdf");

2.

            QP.NewPage();

            tid = QP.CreateTable(5,3);
            QP.SetTableColumnWidth(tid,1,1,20);
            QP.SetTableColumnWidth(tid,2,2,30);
            QP.SetTableColumnWidth(tid,3,3,50);
            QP.SetTableCellContent(tid,1,1,"1111");
            QP.SetTableCellContent(tid,2,2,"2222");
            QP.SetTableCellContent(tid,5,1,"3333");
            QP.SetTableCellContent(tid,5,2,"4444");

            QP.AppendTableRows(tid,5);

            QP.SetTableCellContent(tid,8,2,"5555");
            QP.SetTableCellContent(tid,9,3,"6666");

            QP.SelectPage(QP.PageCount());

            QP.DrawTextBox(20,20,170,30,"table should be below",0);
            QP.DrawTableRows(tid,20,60,100,1,0);    //  {draws no rows}
            QP.DrawTextBox(20,200,170,90,QP.GetTableLastDrawnRow(tid).ToString() +" rows drawn",0);
            QP.SaveToFile("out.pdf");

3.

            string drawstr2 = "私はこれが働くことを望んで which is \"I hope this works\" in Japanese";

            QP.SetHTMLNormalFont("Default", QP.AddTrueTypeSubsettedFont("MS UI Gothic", drawstr2, 0));
            QP.SetHTMLBoldFont("Default", QP.AddTrueTypeSubsettedFont("Arial Unicode MS [Bold]", drawstr2, 0));
            QP.SetHTMLItalicFont("Default", QP.AddTrueTypeSubsettedFont("Arial Unicode MS [Italic]", drawstr2, 0));
            QP.SetHTMLBoldItalicFont("Default", QP.AddTrueTypeSubsettedFont("Arial Unicode MS [BoldItalic]", drawstr2, 0));

            QP.SetOrigin(1);
            QP.DrawHTMLText(10, 10, 500, drawstr2 + "<i><br><br>" + drawstr2 + "</i>") ;


            int maxrows = 25;

            int tableID = QP.CreateTable(maxrows, 5);
            QP.SetTableBorderColor(tableID, 0, 0.5, 0.5, 0.5);
            QP.SetTableBorderWidth(tableID, 0, 0.3);

            QP.SetTableCellBorderColor(tableID, 1, 1, 25, 5, 0, 0.5, 0.5, 0.5);
            QP.SetTableCellBorderWidth(tableID, 1, 1, 25, 5, 0, 0.3);

            // Specify table row height and table column width
            QP.SetTableRowHeight(tableID, 1, 25, 40);
            QP.SetTableColumnWidth(tableID, 1, 5, 100);

            // Specify a background color for the column headers
            QP.SetTableCellBackgroundColor(tableID, 1, 1, 1, 5, .75, .75, .75);
            QP.SetTableCellAlignment(tableID, 1, 1, 25, 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
            for (int i = 2; i <= maxrows; i++)
            {
                QP.SetTableCellContent(tableID, i, 1, (i-1).ToString());
                QP.SetTableCellContent(tableID, i, 2, "1");
                QP.SetTableCellContent(tableID, i, 3, "<b>The Black Eyed Peas</b><br>Boom Boom Pow");
                QP.SetTableCellContent(tableID, i, 4, "<b>1</b>");
                QP.SetTableCellContent(tableID, i, 5, "<b>11</b>");
            }

            // Draw the table onto the document
            QP.SetOrigin(1);
            double s = QP.DrawTableRows(tableID, 50, 50, QP.PageHeight() - 100, 1, maxrows);

            int lastRow = QP.GetTableLastDrawnRow(tableID);

            while (lastRow < maxrows)
            {
                QP.NewPage();
                QP.SetOrigin(1);

                s = QP.DrawTableRows(tableID, 50, 50, QP.PageHeight() - 100 , lastRow + 1, maxrows);
                lastRow = QP.GetTableLastDrawnRow(tableID);
            }

            QP.SaveToFile("out.pdf");

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store