SetTableOfContents

Description

Sets the table of contents for the PDF document..

Applies to

PDFDocument_object

Syntax

SetTableOfContents(PDFTableOfContents toc)

Argument

Description

toc

The PDFTableOfContents_object to add to the PDF document.


Return value

None.

Examples

This example sets the table of contents for the document:

PDFDocument lpdf_doc
PDFpage lpdf_page,lpdf_page1
PDFmultilinetext lpdf_mtext
PDFtableofcontents lpdf_toc
PDFtableofcontentsitem lpdf_tocitem
PDFtext lpdf_title,lpdf_chapter,lpdf_chapteritem
PDFfont lpdf_font

string ls_ssText
integer li_fhandle
long ll_fileLen, ll_readSize

lpdf_doc = create PDFDocument
lpdf_page = create PDFpage
lpdf_page1 = create PDFpage
lpdf_mtext = create PDFmultilinetext
lpdf_toc =  create PDFtableofcontents
lpdf_title = create PDFtext
lpdf_chapter = create PDFtext
lpdf_font = create PDFfont

//Set the font used in the table of contents
lpdf_font.fontname = "Arial"
lpdf_font.bold = true
lpdf_font.italic = true
lpdf_font.fontsize = 20
lpdf_toc.setfont( lpdf_font) 

lpdf_title.content = "Table of Content"
lpdf_title.font.fontsize = 36
lpdf_title.font.bold = true
lpdf_title.y = 20
lpdf_title.x = (lpdf_page.getwidth( )-lpdf_title.width)/2
//Set the title
lpdf_toc.settitle( lpdf_title)

lpdf_chapter.content = "chapter1"
lpdf_chapteritem = lpdf_chapter.clone( )
lpdf_chapteritem.content = "chapter1.1"

//Get the content for the PDF document
ll_fileLen = FileLength64("testdocument.txt")
li_fhandle = fileopen("testdocument.txt", textMode! )
blob readByte
ll_readSize = fileReadEx(li_fhandle, readByte,ll_fileLen)
ls_ssText = string(readByte)
fileclose(li_fhandle)

lpdf_mtext.width = lpdf_page.getwidth( )
lpdf_mtext.content = ls_ssText

//Add level-1 toc item
lpdf_tocitem = lpdf_toc.additem( lpdf_chapter)
//Add level-2 toc item
lpdf_tocitem.additem(lpdf_chapteritem )

lpdf_page.addcontent( lpdf_chapter)
lpdf_page.addcontent( lpdf_chapteritem)
lpdf_page.addcontent( lpdf_mtext)

lpdf_doc.addpage( lpdf_page)

//Set the toc margins
lpdf_toc.SetLeftMargin(100)
lpdf_toc.SetTopMargin(100)
lpdf_toc.SetRightMargin(100)
lpdf_toc.SetBottomMargin(100)

//PDFTableOfContentsStyle_Simple!             /*simple toc: title 1 */
// PDFTableOfContentsStyle_Classic!            /*classic toc:title.........1 */
lpdf_toc.setstyle( PDFTableOfContentsStyle_Simple!)

lpdf_doc.settableofcontents( lpdf_toc)
lpdf_doc.save( "D:\tocitem.pdf")

This example sets the table of contents for the document (including importing data from a DataWindow, setting title for the pages, and linking the TOC entries to the pages):

long  ll_return,ll_page,ll_pagecount
                
PDFDocument  lpdf_doc
pdfpage  lpdf_page,lpdf_current_page
pdftext  lpdf_text,lpdf_title,lpdf_chapter,lpdf_textclone
PDFtableofContents  lpdf_toc
PDFtableofContentsitem  lpdf_tocitem

lpdf_doc = Create PDFDocument
lpdf_text = create pdftext
lpdf_title = create pdftext
lpdf_chapter = create pdftext
lpdf_page = Create pdfpage 
lpdf_toc = create PDFtableofContents

dw_2.SetTransObject( SQLCA )

ll_return = dw_2.Retrieve()

// Import data from a DataWindow
lpdf_doc.importdatawindow( dw_2)
// Calculate the number of pages imported
ll_pagecount = lpdf_doc.getpagecount( )

lpdf_title.content = "TableOfContents"
lpdf_title.font.fontsize = 36
lpdf_title.x = lpdf_page.getwidth( )/2 - lpdf_title.width/2
lpdf_title.y=50

// Set the display style of table of contents
lpdf_toc.setstyle( PDFTableOfContentsStyle_Classic!)

lpdf_toc.setrightmargin( 100)
lpdf_toc.setleftmargin( 100)
lpdf_toc.settopmargin( 50)
lpdf_toc.settitle( lpdf_title)

//Set the text position according to actual situation
lpdf_chapter.x = lpdf_page.getwidth( )/2 - lpdf_chapter.width/2
lpdf_chapter.y = 5

for ll_page=1 to ll_pagecount
                //Get the current page
                lpdf_current_page =  lpdf_doc.getpage( ll_page)
                
                //Clone the PDFText object
                lpdf_textclone = lpdf_chapter.clone( )
                lpdf_textclone.content = "Chapter"+string(ll_page)
                
                //Set the text to the table of contents and page
                lpdf_tocitem = lpdf_toc.additem( lpdf_textclone)
                lpdf_current_page.addcontent( lpdf_textclone)
next

lpdf_doc.settableofcontents( lpdf_toc)

ll_return = lpdf_doc.save( "D:\TOC.pdf")

See also

AddPage

Clone

GetPage

GetPageCount

GetTableOfContents

ImportDataWindow

ImportPDF

ImportRichTextEdit

IndexOf

InsertPage

RemovePage

Save

SearchObject