i am creating a TOC as I merge PDF’s together. I want to have the TOC start half way down the page but can’t figure out how to do so.
static private void TOCCreationTest()
{
GetAsposeLic();
var TOC_Doc = new Aspose.Pdf.Document(@"F:\Template.pdf");
var files = Directory.GetFiles(@"F:\pdf test\", "*.pdf");
//add TOC to existing DOc
var tocPage = TOC_Doc.Pages[1];
// Create object to represent TOC information
TocInfo tocInfo = new TocInfo();
Aspose.Pdf.Text.TextFragment title = new Aspose.Pdf.Text.TextFragment("Table Of Contents");
title.TextState.FontSize = 22;
title.TextState.FontStyle = Aspose.Pdf.Text.FontStyles.Bold;
var h = tocPage.PageInfo.Height;
double yIndent = (tocPage.PageInfo.Height / 4) * 3;
title.Position.YIndent = yIndent;
// Set the title for TOC
tocInfo.Title = title;
tocInfo.FormatArrayLength = 3;
LevelFormat lf = new LevelFormat();
lf.Margin = new MarginInfo(0, 0, 0, yIndent);
tocPage.TocInfo = tocInfo;
OutlineItemCollection pdfOutline = new OutlineItemCollection(TOC_Doc.Outlines);
pdfOutline.Title = "Table of Contents";
pdfOutline.Italic = true;
pdfOutline.Bold = true;
//set the destination page number
pdfOutline.Action = new Aspose.Pdf.InteractiveFeatures.GoToAction(tocPage);
//add bookmark in the document's outline collection.
TOC_Doc.Outlines.Add(pdfOutline);
foreach (var file in files)
{
var doc = new Aspose.Pdf.Document(file);
int pageNum = TOC_Doc.Pages.Count +1;
TOC_Doc.Pages.Add(doc.Pages);
pdfOutline = new OutlineItemCollection(TOC_Doc.Outlines);
pdfOutline.Title = Path.GetFileName(file);
pdfOutline.Italic = true;
pdfOutline.Bold = true;
//set the destination page number
pdfOutline.Action = new Aspose.Pdf.InteractiveFeatures.GoToAction(TOC_Doc.Pages[pageNum]);
//add bookmark in the document's outline collection.
TOC_Doc.Outlines.Add(pdfOutline);
//add TOC
Aspose.Pdf.Heading heading2 = new Aspose.Pdf.Heading(1);
Aspose.Pdf.Text.TextSegment segment2 = new Aspose.Pdf.Text.TextSegment();
heading2.TocPage = tocPage;
heading2.Segments.Add(segment2);
// Specify the destination page for heading object
heading2.DestinationPage = TOC_Doc.Pages[pageNum];
// Destination page
heading2.Top = TOC_Doc.Pages[pageNum].Rect.Height;
// Destination coordinate
segment2.Text = pdfOutline.Title;
// Add heading to page containing TOC
tocPage.Paragraphs.Add(heading2);
}
TOC_Doc.Save(@"F:\TOC_Test.pdf");
}