I am trying to achieve a multi-line paragraph that starts with a paragraph 
number and a tab. I want the paragraph to be justified but i think the tab is 
messing up the character spacing. (Please see attached pdf)


I think this is the opposite of the bug submiited here: 
https://sourceforge.net/tracker/?func=detail&aid=2980158&group_id=15255&atid=115255

I can't use first line indent since I want the paragraph number to be the the 
same left alignment as the rest of the paragraph.

Correct me if I'm wrong but I believe this tab and alignment is part of the 
iText 5.0.2 release.
 - Tabs and justified alignment don't mix. Not really a bug fix, but at 
least the line doesn't jump
out of the text column anymore.

This is the code:

public byte[] generatePDF() throws Exception {
        try {
            init();
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            Document doc = new Document(PageSize.LETTER, 54f, 54f, 18f, 54f);
            PdfWriter.getInstance(doc, stream);
            doc.open();
            addPara1();
            addPara2();
            doc.close();
            return stream.toByteArray();
        } catch (Exception e) {
            throw e;
        }
    }

private void addPara1() throws Exception {
        Chunk tab = new Chunk(new VerticalPositionMark(), 50f, false);
        Paragraph p = new Paragraph("");
        p.add("I am trying to achieve this indentation but with paragraph 
number before the paragraph. " +
                "As you can see, the indentation of this line is justified 
correctly." +
                "This is some very long content to a very simple paragraph that 
will be repeated again and again.");
        p.setFirstLineIndent(50f);
        p.setAlignment(Element.ALIGN_JUSTIFIED);
        doc.add(p);
        
        p = new Paragraph("");
        p.setAlignment(Element.ALIGN_JUSTIFIED);
        p.setIndentationLeft(50f);
        p.add("(a) This sub-paragraph will be left-aligned based on the tab 
space of the first paragraph");
        doc.add(p);
        
        p = new Paragraph("");
        p.setAlignment(Element.ALIGN_JUSTIFIED);
        p.setIndentationLeft(50f);
        p.add("(b) This sub-paragraph will be left-aligned based on the tab 
space of the first paragraph");
        doc.add(p);
        doc.add(new Paragraph(Chunk.NEWLINE));
    }
    
    private void addPara2() throws Exception {
        Chunk tab = new Chunk(new VerticalPositionMark(), 50f, false);
        Paragraph p = new Paragraph("");
        p.setAlignment(Element.ALIGN_JUSTIFIED);
        p.add("1");
        p.add(tab);
        p.add("I am trying to achieve this indentation but with paragraph 
number before the paragraph. " +
                "The alignment of the first line doesn't look okay. This is 
some very long content " +
                "to a very simple paragraph that will be repeated again and 
again.");
        doc.add(p);
        
        p = new Paragraph("");
        p.setAlignment(Element.ALIGN_JUSTIFIED);
        p.setIndentationLeft(50f);
        p.add("(a) This sub-paragraph will be left-aligned based on the tab 
space of the first paragraph");
        doc.add(p);
        
        p = new Paragraph("");
        p.setAlignment(Element.ALIGN_JUSTIFIED);
        p.setIndentationLeft(50f);
        p.add("(b) This sub-paragraph will be left-aligned based on the tab 
space of the first paragraph");
        doc.add(p);
    }

Thank you very much to whoever would advise me on this query ^_~

Attachment: pdf.pdf
Description: Adobe PDF document

------------------------------------------------------------------------------
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions: 
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/

Reply via email to