Java Code Examples for com.itextpdf.text.Paragraph#add()

The following examples show how to use com.itextpdf.text.Paragraph#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PDFMigrationReportWriter.java    From bonita-studio with GNU General Public License v2.0 7 votes vote down vote up
private void createLegend(Paragraph mainPara) throws BadElementException,
		MalformedURLException, IOException {
	mainPara.add(new Chunk("      ",legendFont));
	Image im = getImageForStatus(IStatus.OK);
	mainPara.add(new Chunk(im, 0, 0, false));
	mainPara.add(new Chunk(" ",legendFont));
	mainPara.add(new Chunk(Messages.noActionRequired,legendFont));
	mainPara.add(new Chunk("   ",legendFont));
	im = getImageForStatus(IStatus.WARNING);
	mainPara.add(new Chunk(im, 0, 0, false));
	mainPara.add(new Chunk(" ",legendFont));
	mainPara.add(new Chunk(Messages.reviewRequired,legendFont));
	mainPara.add(new Chunk("   ",legendFont));
	im = getImageForStatus(IStatus.ERROR);
	mainPara.add(new Chunk(im, 0, 0, false));
	mainPara.add(new Chunk(" ",legendFont));
	mainPara.add(new Chunk(Messages.actionRequired,legendFont));
}
 
Example 2
Source File: DenseMerging.java    From testarea-itext5 with GNU Affero General Public License v3.0 6 votes vote down vote up
static byte[] createSimpleTextPdf(String paragraphFormat, int paragraphCount) throws DocumentException
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    Document document = new Document();
    PdfWriter.getInstance(document, baos);
    document.open();
    for (int i = 0; i < paragraphCount; i++)
    {
        Paragraph paragraph = new Paragraph();
        paragraph.add(String.format(paragraphFormat, i));
        document.add(paragraph);
    }
    document.close();

    return baos.toByteArray();
}
 
Example 3
Source File: VeryDenseMerging.java    From testarea-itext5 with GNU Affero General Public License v3.0 6 votes vote down vote up
static byte[] createSimpleTextPdf(String paragraphFormat, int paragraphCount) throws DocumentException
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    Document document = new Document();
    PdfWriter.getInstance(document, baos);
    document.open();
    for (int i = 0; i < paragraphCount; i++)
    {
        Paragraph paragraph = new Paragraph();
        paragraph.add(String.format(paragraphFormat, i));
        document.add(paragraph);
    }
    document.close();

    return baos.toByteArray();
}
 
Example 4
Source File: ImportPageWithoutFreeSpace.java    From testarea-itext5 with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * This method creates a PDF with a single styled paragraph.
 */
static byte[] createSimpleTextPdf() throws DocumentException
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    Document document = new Document();
    PdfWriter.getInstance(document, baos);
    document.open();

    Paragraph paragraph = new Paragraph();
    paragraph.add(new Phrase("Beware: ", new Font(FontFamily.HELVETICA, 12, Font.BOLDITALIC)));
    paragraph.add(new Phrase("The implementation of ", new Font(FontFamily.HELVETICA, 12, Font.ITALIC)));
    paragraph.add(new Phrase("MarginFinder", new Font(FontFamily.COURIER, 12, Font.ITALIC)));
    paragraph.add(new Phrase(" is far from optimal. It is not even correct as it includes all curve control points which is too much. Furthermore it ignores stuff like line width or wedge types. It actually merely is a proof-of-concept.", new Font(FontFamily.HELVETICA, 12, Font.ITALIC)));
    document.add(paragraph);

    document.close();

    return baos.toByteArray();
}
 
Example 5
Source File: SimpleRedactionTest.java    From testarea-itext5 with GNU Affero General Public License v3.0 6 votes vote down vote up
static byte[] createSimpleTextPdf() throws DocumentException
{
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    Document document = new Document();
    PdfWriter.getInstance(document, baos);
    document.open();
    for (int i = 1; i < 20; i++)
    {
        Paragraph paragraph = new Paragraph();
        for (int j = 0; j < i; j++)
            paragraph.add("Hello World! ");
        document.add(paragraph);
    }
    document.close();

    return baos.toByteArray();
}
 
Example 6
Source File: AbstractPdfReportBuilder.java    From bdf3 with Apache License 2.0 6 votes vote down vote up
protected Paragraph createReportTitle(ReportTitle reportTitle) {
	Paragraph paragraph = new Paragraph();
	paragraph.setAlignment(Element.ALIGN_CENTER);
	if (reportTitle != null && reportTitle.isShowTitle()) {
		TextChunk titleChunk = new TextChunk();
		titleChunk.setText(reportTitle.getTitle());
		titleChunk.setFontSize(reportTitle.getStyle().getFontSize());
		titleChunk.setFontColor(reportTitle.getStyle().getFontColor());
		paragraph.add(createChunk(titleChunk));
		paragraph.add(Chunk.NEWLINE);
		paragraph.add(Chunk.NEWLINE);
	}
	return paragraph;
}
 
Example 7
Source File: NormalSubTitle.java    From xiaoyaoji with GNU General Public License v3.0 5 votes vote down vote up
public NormalSubTitle(Paragraph parent, String title, int index) {

        setFont(font);
        Paragraph titlePara = new Paragraph(title, font);
        titlePara.setSpacingAfter(DEFAULT_MARGIN);
        titlePara.setSpacingBefore(DEFAULT_MARGIN);
        add(titlePara);

        if (parent != null) {
            parent.add(index, this);
        }
    }
 
Example 8
Source File: NormalSubTitle.java    From xiaoyaoji with GNU General Public License v3.0 5 votes vote down vote up
public NormalSubTitle(Paragraph parent, String title, int index, float vMargin) {

        setFont(font);
        Paragraph titlePara = new Paragraph(title, font);
        titlePara.setSpacingAfter(vMargin);
        titlePara.setSpacingBefore(vMargin);
        add(titlePara);

        if (parent != null) {
            parent.add(index, this);
        }
    }
 
Example 9
Source File: PDFMigrationReportWriter.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
private void addTitlePage(Document document)
		throws DocumentException {
	Paragraph preface = new Paragraph();
	// Lets write a big header
	preface.add(new Paragraph(report.getName(), catFont));
	//addEmptyLine(preface, 1);
	// Will create: Report generated by: _name, _date
	preface.add(new Paragraph(new SimpleDateFormat("dd MMM yyyy",new Locale(Platform.getNL())).format(new Date()), smallBold));
	document.add(preface);

}
 
Example 10
Source File: CreateLink.java    From testarea-itext5 with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * <a href="http://stackoverflow.com/questions/34408764/create-local-link-in-rotated-pdfpcell-in-itextsharp">
 * Create local link in rotated PdfPCell in iTextSharp
 * </a>
 * <p>
 * This is the equivalent Java code for the C# code in the question. Indeed, this code
 * also gives rise to the broken result. The cause is simple: Normally iText does not
 * touch the current transformation matrix. So the chunk link creation code assumes the
 * current user coordinate system to be the same as used for positioning annotations.
 * But in case of rotated cells iText does change the transformation matrix and
 * consequently the chunk link creation code positions the annotation at the wrong
 * location.
 * </p>
 */
@Test
public void testCreateLocalLinkInRotatedCell() throws IOException, DocumentException
{
    Document doc = new Document();
    PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(new File(RESULT_FOLDER, "local-link.pdf")));
    doc.open();

    PdfPTable linkTable = new PdfPTable(2);
    PdfPCell linkCell = new PdfPCell();

    linkCell.setHorizontalAlignment(Element.ALIGN_CENTER);
    linkCell.setRotation(90);
    linkCell.setFixedHeight(70);

    Anchor linkAnchor = new Anchor("Click here");
    linkAnchor.setReference("#target");
    Paragraph linkPara = new Paragraph();
    linkPara.add(linkAnchor);
    linkCell.addElement(linkPara);
    linkTable.addCell(linkCell);

    PdfPCell linkCell2 = new PdfPCell();
    Anchor linkAnchor2 = new Anchor("Click here 2");
    linkAnchor2.setReference("#target");
    Paragraph linkPara2 = new Paragraph();
    linkPara2.add(linkAnchor2);
    linkCell2.addElement(linkPara2);
    linkTable.addCell(linkCell2);

    linkTable.addCell(new PdfPCell(new Phrase("cell 3")));
    linkTable.addCell(new PdfPCell(new Phrase("cell 4")));
    doc.add(linkTable);

    doc.newPage();

    Anchor destAnchor = new Anchor("top");
    destAnchor.setName("target");
    PdfPTable destTable = new PdfPTable(1);
    PdfPCell destCell = new PdfPCell();
    Paragraph destPara = new Paragraph();
    destPara.add(destAnchor);
    destCell.addElement(destPara);
    destTable.addCell(destCell);
    destTable.addCell(new PdfPCell(new Phrase("cell 2")));
    destTable.addCell(new PdfPCell(new Phrase("cell 3")));
    destTable.addCell(new PdfPCell(new Phrase("cell 4")));
    doc.add(destTable);

    doc.close();
}
 
Example 11
Source File: PDFMigrationReportWriter.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
private void addEmptyLine(Paragraph paragraph, int number) {
	for (int i = 0; i < number; i++) {
		paragraph.add(new Paragraph(" "));
	}
}