​Hello,

The following Code produces a pdf document.

public class PDFtest {
    private static final Font NORMAL_FONT = new 
Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL);
    private static final Font NORMAL_FONT_RED = new 
Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.RED);
    private static final Font NORMAL_BOLD_FONT = new 
Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);
    private static final Font NORMAL_UNDERLINE_FONT = new 
Font(Font.FontFamily.TIMES_ROMAN, 12, Font.UNDERLINE);

    public static void main(String[] args) throws 
DocumentException, FileNotFoundException {
        Document doc = new 
Document(PageSize.A4, 50, 30, 50, 30);
        PdfWriter writer = 
PdfWriter.getInstance(doc, new FileOutputStream(new File("d:\\test.pdf")));
        doc.open();
        Phrase textblock = new Phrase();

        Chunk chunk = new Chunk("Das ist ein 
erster Text.", NORMAL_FONT);
        textblock.add(chunk);

        chunk = new Chunk("Das ist ein 
zweiter Text.", NORMAL_BOLD_FONT);
        textblock.add(chunk);

        chunk = new Chunk("Das ist ein 
dritter Text.", NORMAL_FONT_RED);
        chunk.setBackground(BaseColor.GREEN);
        textblock.add(chunk);

        textblock.add(Chunk.NEWLINE);
        textblock.add(Chunk.NEWLINE);

        chunk = new Chunk("Das ist ein 
vierter Text.", NORMAL_FONT);
        textblock.add(chunk);

        doc.add(new Paragraph(textblock));
        Phrase p = new Phrase();
        p.add("Zeile1");
        p.add(Chunk.NEWLINE);
        p.add("Zeile2");
        p.add(Chunk.NEWLINE);
        p.add("Zeile3");
        p.add(Chunk.NEWLINE);
        p.add("Zeile4");
        p.add(Chunk.NEWLINE);
        p.add("Zeile5");
        p.add(Chunk.NEWLINE);
        p.add(Chunk.NEWLINE);

        Paragraph para = new Paragraph(p);
        para.setKeepTogether(true);
        doc.add(para);
        doc.add(para);
        doc.add(para);
        doc.add(para);
        doc.add(para);
        doc.add(para);
        doc.add(para);
        doc.add(para);

        Phrase under = new Phrase();
        under.add(new 
Chunk("1     9", NORMAL_UNDERLINE_FONT));
        under.add(Chunk.NEWLINE);
        under.add(new 
Chunk("            ", 
NORMAL_UNDERLINE_FONT));
        under.add(Chunk.NEWLINE);
        under.add(new Chunk("abcdef___", 
NORMAL_UNDERLINE_FONT));
        under.add(Chunk.NEWLINE);
        Paragraph underlineTest = new 
Paragraph(under);
        underlineTest.setKeepTogether(true);
        doc.add(underlineTest);

        doc.addTitle("iText Test");
        doc.addAuthor("wer auch immer");
        doc.addCreationDate();
        doc.addSubject("Hello World");

        doc.close();
        writer.close();
        System.out.println("Fertig");
    }
}

The line

under.add(new 
Chunk("            ", 
NORMAL_UNDERLINE_FONT));

adds a string of spaces to a phrase which are underlined.

if the line

underlineTest.setKeepTogether(true);

is active the string with the underlined space will not shown

If the line is not active (comment) the string with the spaces will shown


Mit freundlichen Grüßen
Christian Marquardt


------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_123012
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
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

Reply via email to