Hi,
our corporate design forces me to put the toc title to the left.
No matter how I format the Textfragment, it is alway in the center.
I found a code snippet from you and I added the corresponding
“HorizontalAlignment.Left” to it.
Is there any other way to get it to the left?
List tflist = new java.util.ArrayList();
Document doc = new Document();
TextFragment tf = new TextFragment(“Heading 1”);
TextFragment tf2 = new TextFragment(“Heading 2”);
TextFragment tf3 = new TextFragment(“Heading 3”);
Page page = doc.getPages().add();
page.getParagraphs().add(tf);
page.getParagraphs().add(tf2);
page.getParagraphs().add(tf3);
tflist.add(tf);
tflist.add(tf2);
tflist.add(tf3);
doc.processParagraphs();Page tocPage = doc.getPages().insert(1);
// Create object to represent TOC information
TocInfo tocInfo = new TocInfo();
TextFragment title = new TextFragment(“Table Of Contents”);
title.getTextState().setFontSize(20);
title.getTextState().setFontStyle(FontStyles.Bold);
title.getTextState().setHorizontalAlignment(HorizontalAlignment.Left);// Set the title for TOC
tocInfo.setTitle(title);
tocPage.setTocInfo(tocInfo);String[] titles = new String[4];
titles[0] = “Heading 1”;
titles[1] = “Heading 2”;
titles[2] = “Heading 3”;
for (int i = 0; i < 3; i++) {
// Create Heading object
Heading heading2 = new Heading(1);TextSegment segment2 = new TextSegment(); heading2.setTocPage(tocPage); heading2.getSegments().add(segment2); heading2.setDestinationPage(page); heading2.setHyperlink(new LocalHyperlink(tflist.get(i))); // Destination coordinate segment2.setText(titles[i]); // Add heading to page containing TOC tocPage.getParagraphs().add(heading2);}
// Save the updated document
doc.save(“TOC_Output_Java.pdf”);