Using setFirstLineIndent() and adding a tabulator Chunk to create a hanging
indent causes the first line to wrap to early. I think the bug is caused by
a missing line in PdfLine.setExtraIndent(float extra).
This is how I think it should be.
void setExtraIndent(float extra) {
left += extra;
width -= extra;
// Add this line
originalWidth -= extra;
}
The following Java program will demonstrate the problem:
import java.io.*;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.*;
import com.itextpdf.text.pdf.draw.*;
public class Bug
{
public static void main ( String[] args )
{
try
{
Document document = new Document(PageSize.A4, 72.0f, 72.0f, 72.0f,
72.0f);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter pdfWriter = PdfWriter.getInstance(document, baos);
document.open();
// Hanging indent, line wraps to early
Paragraph currentParagraph = new Paragraph();
currentParagraph.setIndentationLeft(120.0f);
currentParagraph.setFirstLineIndent(-120.0f);
String text = "The quick fox jumped over the lazy dog. ";
currentParagraph.add(new Chunk("First text"));
Chunk newTab = new Chunk(new VerticalPositionMark(), 120.0f);
currentParagraph.add(newTab);
currentParagraph.add(new Chunk(text));
currentParagraph.add(new Chunk(text));
currentParagraph.add(new Chunk(text));
currentParagraph.add(new Chunk(text));
currentParagraph.add(new Chunk(text));
document.add(currentParagraph);
currentParagraph = new Paragraph();
currentParagraph.add(new Chunk(" "));
document.add(currentParagraph);
// Indented with TAB, line wraps to late
currentParagraph = new Paragraph();
currentParagraph.setIndentationLeft(0.0f);
currentParagraph.setFirstLineIndent(120.0f);
currentParagraph.add(new Chunk("First text"));
Chunk nextTab = new Chunk(new VerticalPositionMark(), 220.0f);
currentParagraph.add(nextTab);
currentParagraph.add(new Chunk(text));
currentParagraph.add(new Chunk(text));
currentParagraph.add(new Chunk(text));
currentParagraph.add(new Chunk(text));
currentParagraph.add(new Chunk(text));
document.add(currentParagraph);
document.close();
byte[] bytes = baos.toByteArray();
File file = new File("hanging.pdf");
OutputStream os = new BufferedOutputStream(new
FileOutputStream(file));
os.write(bytes);
os.flush();
os.close();
}
catch (DocumentException e)
{
e.printStackTrace();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
--
View this message in context:
http://itext-general.2136553.n4.nabble.com/Hanging-indents-bug-report-tp3873928p3873928.html
Sent from the iText - General mailing list archive at Nabble.com.
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples:
http://itextpdf.com/themes/keywords.php