Pdf/demo/outline_demo.tsl

84 lines
2.0 KiB
Plaintext

Uses TSPdfEnumerations;
{$IFDEF LINUX}
separator := "/";
{$ELSE}
separator := "\\";
{$ENDIF}
alias := "";
path := "";
InitCmdParams(alias, path);
output_file := "outline_demo.pdf";
output_file := path + separator + output_file;
pdf := new PdfFile();
// create default-font
font := pdf.GetFont("Helvetica", "");
// Set page mode to use outlines.
pdf.SetPageMode(TSPdfEnumerations.PAGE_MODE_USE_OUTLINE);
page_arr := array();
// Add 3 pages to the document.
page := pdf.AddPage();
page.SetFontAndSize(font, 30);
PrintPage(page, font, 1);
page_arr[0] := page;
page := pdf.AddPage();
page.SetFontAndSize(font, 30);
PrintPage(page, font, 2);
page_arr[1] := page;
page := pdf.AddPage();
page.SetFontAndSize(font, 30);
PrintPage(page, font, 3);
page_arr[2] := page;
// create outline root.
root := pdf.CreateOutline(nil, "OutlineRoot", nil);
root.SetOpened(true);
outline1 := pdf.CreateOutline(root, "page1", nil);
outline2 := pdf.CreateOutline(root, "page2", nil);
// create outline with test which is ISO8859-2 encoding
outline3 := pdf.CreateOutline(root, "ISO8859-2 text سشصض×طظ", pdf.GetEncoder("ISO8859-2"));
// create destination objects on each pages and link it to outline items.
dst := page_arr[0].CreateDestination();
height := page_arr[0].GetHeight();
dst.SetXYZ(0, height, 1);
outline1.SetDestination(dst);
dst := page_arr[1].CreateDestination();
height := page_arr[1].GetHeight();
dst.SetXYZ(0, height, 1);
outline2.SetDestination(dst);
dst := page_arr[2].CreateDestination();
height := page_arr[2].GetHeight();
dst.SetXYZ(0, height, 1);
outline3.SetDestination(dst);
// save the document to a file
err := pdf.SaveToFile(alias, output_file);
echo "SaveToFile::\t", "err := ", format("%x", err), "\toutput_file := ", output_file, "\n";
return;
Function PrintPage(page, font, page_num);
Begin
page.SetWidth(800);
page.SetHeight(800);
page.SetFontAndSize(font, 20);
page.BeginText();
page.MoveTextPos(30, 740);
buf := format("Page:%d", page_num);
page.ShowText(buf);
page.EndText();
End;