public static void Create()
{
Document pdfDoc = new Document();
pdfDoc.PageInfo.Width = 612.0;
pdfDoc.PageInfo.Height = 792.0;
pdfDoc.PageInfo.Margin = new Aspose.Pdf.MarginInfo();
pdfDoc.PageInfo.Margin.Left = 72;
pdfDoc.PageInfo.Margin.Right = 72;
pdfDoc.PageInfo.Margin.Top = 72;
pdfDoc.PageInfo.Margin.Bottom = 72;
Aspose.Pdf.Page pdfPage = pdfDoc.Pages.Add();
pdfPage.PageInfo.Width = 612.0;
pdfPage.PageInfo.Height = 792.0;
pdfPage.PageInfo.Margin = new Aspose.Pdf.MarginInfo();
pdfPage.PageInfo.Margin.Left = 72;
pdfPage.PageInfo.Margin.Right = 72;
pdfPage.PageInfo.Margin.Top = 72;
pdfPage.PageInfo.Margin.Bottom = 72;
var contentPage = pdfDoc.Pages.Add();
//For toc
Aspose.Pdf.FloatingBox floatBox = new Aspose.Pdf.FloatingBox();
floatBox.Margin = pdfPage.PageInfo.Margin;
pdfPage.Paragraphs.Add(floatBox);
var margin = new MarginInfo();
margin.Top = 20;
margin.Left = 200;
var heading = new TextFragment();
heading.Text = “List 1”;
heading.HorizontalAlignment = HorizontalAlignment.FullJustify;
heading.Margin = margin;
floatBox.Paragraphs.Add(heading);
var headingNumber = new TextFragment((contentPage.Number).ToString(CultureInfo.InvariantCulture));
headingNumber.TextState.HorizontalAlignment = HorizontalAlignment.Right;
headingNumber.Margin.Top = 20;
headingNumber.IsInLineParagraph = true;
floatBox.Paragraphs.Add(headingNumber);
var heading2 = new TextFragment();
heading2.Text = “List 2”;
heading2.HorizontalAlignment = HorizontalAlignment.FullJustify;
heading2.Margin = margin;
floatBox.Paragraphs.Add(heading2);
var headingNumber2 = new TextFragment((contentPage.Number).ToString(CultureInfo.InvariantCulture));
headingNumber2.TextState.HorizontalAlignment = HorizontalAlignment.Right;
headingNumber2.Margin.Top = 20;
headingNumber2.IsInLineParagraph = true;
floatBox.Paragraphs.Add(headingNumber2);
var heading3 = new TextFragment();
heading3.Text = “List 3”;
heading3.HorizontalAlignment = HorizontalAlignment.FullJustify;
heading3.Margin = margin;
floatBox.Paragraphs.Add(heading3);
var headingNumber3 = new TextFragment((contentPage.Number).ToString(CultureInfo.InvariantCulture));
headingNumber3.TextState.HorizontalAlignment = HorizontalAlignment.Right;
headingNumber3.Margin.Top = 20;
headingNumber3.IsInLineParagraph = true;
floatBox.Paragraphs.Add(headingNumber3);
//For content
var content = @“Aspose.Pdf for .NET is a PDF document creation and manipulation component that enables your .NET applications to read, write and manipulate existing PDF documents without using Adobe Acrobat. It also allows you to create forms and manage form fields embedded in a PDF document.
Aspose.Pdf for .NET is affordable and offers an incredible wealth of features including PDF compression options; table creation and manipulation; support for graph objects; extensive hyperlink functionality; extended security controls; custom font handling; integration with data sources; add or remove bookmarks; create table of contents; add, update, delete attachments and annotations; import or export PDF form data; add, replace or remove text and images; split, concatenate, extract or inset pages; transform pages to image; print PDF documents and much more.
Aspose.Pdf for .NET supports the creation of PDF files directly through its API or via XML templates and is incredibly simple to use. The product comes with fully featured demos written in C# and Visual Basic and comprehensive documentation to help get you started. Aspose.Pdf for .NET is a sophisticated product and integrates perfectly with your application to add PDF capabilities.”;
var text = new TextFragment();
text.Text = content;
text.Margin.Top = 200;
var text2 = new TextFragment();
text2.Text = content;
text2.Margin.Top = 200;
var text3 = new TextFragment();
text3.Text = content;
text3.Margin.Top = 200;
contentPage.Paragraphs.Add(heading);
contentPage.Paragraphs.Add(text);
contentPage.Paragraphs.Add(heading2);
contentPage.Paragraphs.Add(text2);
contentPage.Paragraphs.Add(heading3);
contentPage.Paragraphs.Add(text3);
pdfDoc.Save(“c:/pdftest/PageNumber.pdf”);
}
In the pdf, you could see that the heading “List 3” is on the page 3, but in the toc it’s still page2, how could I get the page number ?