Syntax 5: For PDFTableOfContents and PDFTableOfContentsItem
objects
Description
Adds a chapter to the table of contents.
Applies to
PDFTableOfContentsItem
objects
Syntax
|
1 |
PDFTableOfContentsItem AddItem(PDFText chapterObject) |
|
1 |
PDFTableOfContentsItem AddItem(PDFTextBlock chapterObject) |
|
Argument |
Description |
|---|---|
|
chapterObject |
The text or textblock (heading) to add for a chapter in |
Return value
PDFTableOfContentsItem objects.
Returns the table of contents item created in the table of contents if
the function succeeds.
Usage
Use this syntax to add chapters to the table of contents. The
AddItem function of PDFTableOfContents adds the level-1 chapters; and
the AddItem function of PDFTableOfContents adds the sub-level
chapters.
The chapterObject is added to both the table of contents, and to a
PDFPage. Then, the chapterObject in the table of contents is linked to
the actual chapter in the PDFPage.
Examples
This example adds level-1 and level-2 chapters to the table of
contents and have them linking to the actual chapter in the
document:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
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 table of contents font lpdf_font.fontname = "Microsoft YaHei" 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 table of contents title lpdf_toc.settitle( lpdf_title) lpdf_chapter.content = "chapter1" lpdf_chapteritem = lpdf_chapter.clone( ) lpdf_chapteritem.content = "chapter1.1" //Read file content 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 chapter heading to the table of contents lpdf_tocitem = lpdf_toc.additem( lpdf_chapter) //Add level-2 chapter heading to the table of contents 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 table of contents margines lpdf_toc.SetLeftMargin(100) lpdf_toc.SetTopMargin(100) lpdf_toc.SetRightMargin(100) lpdf_toc.SetBottomMargin(100) //PDFTableOfContentsStyle_Simple! /*For example: title 1 */ // PDFTableOfContentsStyle_Classic! /*For example: title.........1 */ lpdf_toc.setstyle( PDFTableOfContentsStyle_Simple!) lpdf_doc.settableofcontents( lpdf_toc) lpdf_doc.save( "D: tocitem.pdf") |
See also