How to Generate Table-of-Figures Dot Leaders in a PdfPCell for the Last Line of Wrapped Text

前端 未结 2 641
旧时难觅i
旧时难觅i 2020-12-11 10:16

I have a Table of Figures generated using PDFPTable like so.

-------------------------------------- 
|Caption|Figure Title           |  PP|
---------------         


        
2条回答
  •  南笙
    南笙 (楼主)
    2020-12-11 11:04

    First things first: +1 for your question and the answer you provided yourself.

    But...

    Although your answer may work, there is a better way to achieve your goal. I've written a small sample called DottedLineLeader as an alternative that will be much easier to maintain. This example uses the DottedLineSeparator wrapped in a Chunk object.

    Take a look at how such a chunk separator is used:

    Chunk leader = new Chunk(new DottedLineSeparator());
    Paragraph p;
    p = new Paragraph("This is a longer title text that wraps");
    p.add(leader);
    

    When we add this Paragraph to a PdfPCell, we get the following effect:

    enter image description here

    The dots in the dotted line are not '.' characters. Instead it's an actual line (vector data) with a specific dash pattern. Using this approach instead of your own, will significantly reduce the number of lines in your code, use less CPU and result in cleaner PDFs.

提交回复
热议问题