But this way, the numbering seems not to be continued in the scetions/subsections. In your pdf the numbering is: 1. chapter 1 1. Section 1 (BTW: without indentation) 1. Subsection 1
I want to have:
Chapter (invisible)
1. Section 1
1.1 Subsection 1
1.2. Subsection 2
2. Section 2
2.1 Subsection 1
...
I have a main Chapter in which I add several Sections just to have a
continuous numbering (Chapter --> no numbering, Section 1, 2, 3, 4, ...,
subsections 1.1, 1.2, ...3.1, 3.2, ...).
The #1-level section shall be placed at the left edge. All subsections
shall have an indention (as well as possible separating lines between
subsections which means the line shall start at the x-position of the
subsections numbering). Subsections have PdfPTables as a first element.
(Attached is a misformed pdf document.)
/**
* Generates the PDFDocument.
*
* @throws IOException
* @throws DocumentException
*/
public void generateDocument() throws IOException, DocumentException
{
// Define the header and/or footer to be displayed on every
page which
// will be inserted on the onPageEvent.
HeaderFooterCreator hfc = new HeaderFooterCreator(25, 25, 0,
0);
// Create the document to be fille dwith content.
document = new Document(PageSize.A4, 40, 25, 75, 40);
// Provide some document properties (author, ...)
initDocumentProperties();
// Define the writer to output the document's content.
pdfWriter = PdfWriter.getInstance(document, new
FileOutputStream(testlocation));
pdfWriter.setViewerPreferences(PdfWriter.PageModeUseOutlines);
pdfWriter.setPageEvent(hfc);
pdfWriter.setPageEvent(new GenericTag());
// Document start :
document.open();
// Define the content of the document's header.
PdfPTable t = initHeader();
hfc.setHeaderTable(t);
// Create a main chapter which contains all sub-chapters
(sections).
// This is neccessary to avoid triggering new pages when
creating a
// new chapter. If a chapter has little content it is almost
unwanted
// to begin the next chapter on a new page.
Chapter mainChapter = new Chapter(new Paragraph(""), 0);
mainChapter.setNumberDepth(0);
// The RfE section:
//document.add(this.buildRfeChapter());
this.buildRfeSection(mainChapter);
// The summary section:
//document.add(this.buildSummaryChapter());
this.buildSummarySection(mainChapter);
// The confirmation section:
//document.add(this.buildConfirmationChapter());
this.buildConfirmationSection(mainChapter);
// The condition section:
this.buildConditionSection(mainChapter);
// The paragraph section:
this.buildProcessSection(mainChapter);
document.add(mainChapter);
document.close();
}//end generateDocument
//-------------------------------------------------------------------------
This is the method building the section with problems:
protected Section buildConditionSection(Chapter mainChapter)
{
Paragraph conditionTitle = new Paragraph("Conditions",
chapterFont);
Section sec = mainChapter.addSection(conditionTitle);
//sec.add(new Paragraph("\n")); // Add some extra
space between section title and content.
//sec.add(new Paragraph(" "));
//sec.setIndentation(20f);
List conditions = data.getConditions();
List openissues = data.getOpenIssues();
List kocriterias = data.getKoCriteria();
Chunk lastConditionChunk = new Chunk(" ");
lastConditionChunk.setGenericTag("lastCondition");
// The different Conditions :
if(conditions != null && conditions.size() > 0)
{
try {
Section conditionSection =
sec.addSection("Conditions");
conditionSection.add(createTableForAnyTypeOfCondition(conditions,
"Conditions"));
//conditionSection.setIndentation(-20f);
conditionSection.add(lastConditionChunk);
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(openissues != null && openissues.size() > 0)
{
try {
Section openissueSection =
sec.addSection("Action Items");
openissueSection.add(createTableForAnyTypeOfCondition(openissues, "Action
Items"));
//openissueSection.setIndentation(-20f);
openissueSection.add(lastConditionChunk);
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(kocriterias != null && kocriterias.size() > 0)
{
try {
Section kocriteriasSection =
sec.addSection("Non-fulfilled Ko-deliverables");
kocriteriasSection.add(createTableForAnyTypeOfCondition(kocriterias,
"Non-fulfilled Ko-deliverables"));
//kocriteriasSection.setIndentation(-20f);
kocriteriasSection.add(lastConditionChunk);
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//Add some extra space to have spacing to the following
section(title).
Chunk emptyChunk = new Chunk("\n");
sec.add(emptyChunk);
return sec;
}//end buildConditionSection
//-------------------------------------------------------------------------
Besides I have an EventHandler defined to draw a line after particular
sections:
import com.lowagie.text.Document;
import com.lowagie.text.ExceptionConverter;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfPageEvent;
import com.lowagie.text.pdf.PdfPageEventHelper;
import com.lowagie.text.pdf.PdfWriter;
/**
* A class invoked on PageEvents which is used to output specific content
* according to a specified iText element.
*
* @author Dirk Ulrich, 2006-11-24
*/
public class GenericTag extends PdfPageEventHelper
{
/**
* @see
com.lowagie.text.pdf.PdfPageEventHelper#onEndPage(com.lowagie.text.pdf.PdfWriter,
com.lowagie.text.Document)
*/
public void onGenericTag(PdfWriter writer, Document document,
Rectangle rect, String text)
{
try
{
if ( "lastCondition".equals(text) )
{
float left =
document.left()-document.leftMargin();
float right =
document.right()-document.rightMargin();
PdfContentByte cb = writer.getDirectContent();
cb.setLineWidth(0.5f);
cb.moveTo(rect.left(), rect.bottom());
cb.lineTo(right, rect.bottom());
cb.setRGBColorStrokeF(0x00, 0x00, 0x00);
cb.stroke();
}
}
catch (Exception e) {
throw new ExceptionConverter(e);
}
}
}//end GenericTag
>
> -------- Original-Nachricht --------
> Datum: Tue, 05 Dec 2006 15:20:12 +0100
> Von: "Bruno Lowagie (iText)" <[EMAIL PROTECTED]>
> An: Post all your questions about iText here
> <[email protected]>
> Betreff: Re: [iText-questions] Indentation of Sections
>
> Dirk Ulrich wrote:
> > Why does an indentation of a section indent an "outer" section as
> well?
>
> It doesn't. See the attached example.
> You'll have to rephrase your question if you
> are having a problem with Chapters/Sections.
>
> > I have a Section just showing a numbering and a title. Within this
> > section I have another Section and I want to indent this section. If I
> > set an indentation to this "inner" section, the outer section is
> > indented as well.
> >
> > Here's what I intend to do:
> > 1. Outer Section 1
> > 1.1 Inner Section 1
> > 1.2 Inner Section 2
> > 1.3 Inner Section 3
> >
> > 2. Outer Section 2
> > ...
>
> A code sample would help.
> br,
> Bruno
>
--
Mit freundlichen Grüßen
Dirk Ulrich
Jansenstraße 21
13437 Berlin
fon:0++49-(0)30-40 999 087
mobil:++49-(0)174/948 87 39
"Ein Herz für Kinder" - Ihre Spende hilft! Aktion: www.deutschlandsegelt.de
Unser Dankeschön: Ihr Name auf dem Segel der 1. deutschen America's Cup-Yacht!
sectionTest.pdf
Description: application/octetstream
------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://itext.ugent.be/itext-in-action/
