Example usage for com.itextpdf.text.pdf PdfPCell setIndent

List of usage examples for com.itextpdf.text.pdf PdfPCell setIndent

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfPCell setIndent.

Prototype

public void setIndent(float indent) 

Source Link

Document

Sets the first paragraph line indent.

Usage

From source file:com.ideationdesignservices.txtbook.pdf.TxtBookPdf.java

public Boolean createFrontCoverPage(Document document, String coverTitle, Bitmap photo)
        throws DocumentException, MalformedURLException, IOException {
    if (photo != null) {
        int imageMaxWidth;
        int imageMaxHeight;
        int imagePosX;
        int imagePosY;
        if (photo.getWidth() < photo.getHeight()) {
            imageMaxWidth = 900;//w ww.  j  av  a2  s.  co  m
            imageMaxHeight = 1200;
            imagePosX = 198;
            imagePosY = 379;
        } else {
            imageMaxWidth = 1200;
            imageMaxHeight = 900;
            imagePosX = 162;
            imagePosY = 379;
        }
        OutputStream stream = new ByteArrayOutputStream();
        ImageUtilities.scaleCenterCrop(photo, imageMaxWidth, imageMaxHeight).compress(CompressFormat.JPEG, 50,
                stream);
        Image coverImage = Image.getInstance(stream.toByteArray());
        coverImage.setAbsolutePosition(0.0f, 0.0f);
        PdfTemplate t = this.writer.getDirectContent().createTemplate((float) imageMaxWidth,
                (float) imageMaxHeight);
        t.newPath();
        t.moveTo(0.0f, (float) imageMaxHeight);
        t.lineTo(0.0f, 71.0f);
        t.lineTo(17.0f, 71.0f);
        t.lineTo(17.0f, 0.0f);
        t.lineTo(72.0f, 71.0f);
        t.lineTo((float) imageMaxWidth, 71.0f);
        t.lineTo((float) imageMaxWidth, (float) imageMaxHeight);
        t.lineTo(0.0f, (float) imageMaxHeight);
        t.closePath();
        t.clip();
        t.newPath();
        t.addImage(coverImage);
        t.setColorStroke(new BaseColor(0, 0, 0));
        t.setLineWidth(BUBBLE_TEXT_INDENT_ALTERNATE);
        t.newPath();
        t.moveTo(0.0f, (float) imageMaxHeight);
        t.lineTo(0.0f, 71.0f);
        t.lineTo(17.0f, 71.0f);
        t.lineTo(17.0f, 0.0f);
        t.lineTo(72.0f, 71.0f);
        t.lineTo((float) imageMaxWidth, 71.0f);
        t.lineTo((float) imageMaxWidth, (float) imageMaxHeight);
        t.lineTo(0.0f, (float) imageMaxHeight);
        t.closePathStroke();
        Image clipped = Image.getInstance(t);
        clipped.scalePercent(24.0f);
        clipped.setAbsolutePosition((float) imagePosX, (float) imagePosY);
        clipped.setCompressionLevel(this.settings.compressionLevel);
        clipped.setAlignment(5);
        document.add(clipped);
    }
    if (coverTitle != null && coverTitle.length() > 0) {
        PdfContentByte canvas = this.writer.getDirectContent();
        Paragraph coverTitleEl = new Paragraph(coverTitle, this.serifFont24);
        coverTitleEl.setAlignment(1);
        PdfPTable table = new PdfPTable(1);
        table.setTotalWidth(311.0f);
        PdfPCell cell = new PdfPCell();
        cell.setBorder(0);
        cell.addElement(coverTitleEl);
        cell.setPadding(0.0f);
        cell.setIndent(0.0f);
        table.addCell(cell);
        table.completeRow();
        table.writeSelectedRows(0, -1, 147.0f, 390.0f, canvas);
    }
    return Boolean.valueOf(true);
}

From source file:com.ideationdesignservices.txtbook.pdf.TxtBookPdf.java

public Boolean createBackCoverPage(Document document, String backCoverNote)
        throws DocumentException, MalformedURLException, IOException {
    document.newPage();//from   www  .  j a  va2s. co  m
    Image backCoverImageFrame = Image
            .getInstance(ImageUtilities.getImageDataForFile(this.mContext, "pdf/txtbook_backpage_300.png"));
    backCoverImageFrame.scalePercent(24.0f);
    backCoverImageFrame.setAbsolutePosition(87.0f, 78.0f);
    backCoverImageFrame.setCompressionLevel(this.settings.compressionLevel);
    document.add(backCoverImageFrame);
    PdfContentByte canvas = this.writer.getDirectContent();
    PdfPTable table = new PdfPTable(1);
    table.setTotalWidth(215.0f);
    if (backCoverNote != null && backCoverNote.length() > 0) {
        Paragraph backCoverEl = new Paragraph(backCoverNote, this.serifFont14);
        PdfPCell cell = new PdfPCell();
        cell.setBorder(0);
        cell.addElement(backCoverEl);
        cell.setPadding(13.0f);
        cell.setIndent(0.0f);
        cell.setFixedHeight(310.0f);
        table.addCell(cell);
        table.completeRow();
    }
    Element backUrl = new Anchor("txt-book.com", this.sansFont11Gray);
    backUrl.setName("txt-book.com");
    backUrl.setReference("http://www.txt-book.com");
    Paragraph paragraph = new Paragraph();
    paragraph.setAlignment(2);
    paragraph.add(backUrl);
    PdfPCell cell2 = new PdfPCell();
    cell2.setBorder(0);
    cell2.setHorizontalAlignment(2);
    cell2.addElement(paragraph);
    cell2.setPadding(0.0f);
    cell2.setPaddingTop(0.0f);
    cell2.setIndent(0.0f);
    table.addCell(cell2);
    table.completeRow();
    table.writeSelectedRows(0, -1, 306.0f, 400.0f, canvas);
    return Boolean.valueOf(true);
}

From source file:ics4u.ics4u_final_project.Recipe.java

License:Open Source License

private void addData(Document doc) {
    //create the format for the % Daily Value
    DecimalFormat onePer = new DecimalFormat("#,##0%");
    try {/*w w  w  . j  a  v  a2s  .  c o  m*/
        //add the title of the recipe
        doc.add(new Paragraph(title, TITLE_FONT));
        //add each of the ingredients
        for (int i = 0; i < ingredients.size(); i++) {
            doc.add(new Paragraph(ingredients.get(i).getFormattedName(), LABEL_NORMAL));
        }
        //add the instructions
        Paragraph p = new Paragraph();
        if (!instructions.equals("")) {
            p = new Paragraph(new Phrase("Instructions:\n", LABEL_FONT));
            doc.add(p);
            p = new Paragraph();
            p.add(new Phrase(instructions + "\n", LABEL_NORMAL));
        } else {
            p.add(new Phrase("\n"));
        }
        //create the nutrient value table
        PdfPTable label = new PdfPTable(10);
        label.setWidthPercentage(30);
        //Top
        PdfPCell c = new PdfPCell(new Phrase("Nutrition Facts", LABEL_FONT));
        c.setColspan(10);
        c.setBorderWidthBottom(0);
        label.addCell(c);
        c = new PdfPCell(new Phrase("Per " + servingName, LABEL_BOLD));
        c.setColspan(10);
        c.setBorderWidthTop(0);
        label.addCell(c);
        //Amount
        PdfPCell c2a = new PdfPCell(new Phrase("Amount", LABEL_SMALL));
        c2a.setColspan(3);
        c2a.setBorderWidthRight(0);
        PdfPCell c2b = new PdfPCell(new Phrase("% Daily Value", LABEL_SMALL));
        c2b.setColspan(10);
        c2b.setHorizontalAlignment(Element.ALIGN_RIGHT);
        c2b.setBorderWidthLeft(0);
        label.addCell(c2a);
        label.addCell(c2b);
        //Calories
        c = new PdfPCell(new Phrase("Calories " + (int) (nutrients[208] / servings), LABEL_BOLD));
        c.setColspan(10);
        c.setBorderWidthTop(2);
        label.addCell(c);
        //Fat
        PdfPCell ca = new PdfPCell(new Phrase("Fat " + (int) (nutrients[204] / servings) + "g", LABEL_BOLD));
        ca.setColspan(6);
        ca.setBorderWidthRight(0);
        PdfPCell cb = new PdfPCell(new Phrase(onePer.format((nutrients[204] / servings) / 60.0), LABEL_BOLD));
        cb.setColspan(10);
        cb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cb.setBorderWidthLeft(0);
        label.addCell(ca);
        label.addCell(cb);
        //fat 2
        ca = new PdfPCell(new Phrase("Saturated " + ((int) (nutrients[606] / servings)) + "g\n\t+ Trans "
                + ((int) (nutrients[605] / servings)) + "g", LABEL_NORMAL));
        ca.setColspan(6);
        ca.setIndent(16);
        ca.setBorderWidthRight(0);
        cb = new PdfPCell(new Phrase(onePer.format((nutrients[606] / servings) / 20.0), LABEL_BOLD));
        cb.setColspan(10);
        cb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cb.setBorderWidthLeft(0);
        label.addCell(ca);
        label.addCell(cb);
        //Cholesterol
        c = new PdfPCell(new Phrase("Cholesterol " + ((int) (nutrients[601] / servings)) + "mg", LABEL_BOLD));
        c.setColspan(10);
        label.addCell(c);
        //Sodium
        ca = new PdfPCell(new Phrase("Sodium " + (int) (nutrients[307] / servings) + "mg", LABEL_BOLD));
        ca.setColspan(6);
        ca.setBorderWidthRight(0);
        cb = new PdfPCell(new Phrase(onePer.format((nutrients[307] / servings) / 2400.0), LABEL_BOLD));
        cb.setColspan(10);
        cb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cb.setBorderWidthLeft(0);
        label.addCell(ca);
        label.addCell(cb);
        //Carbs
        ca = new PdfPCell(new Phrase("Carbohydrate " + (int) (nutrients[205] / servings) + "g", LABEL_BOLD));
        ca.setColspan(7);
        ca.setBorderWidthRight(0);
        cb = new PdfPCell(new Phrase(onePer.format((nutrients[205] / servings) / 300.0), LABEL_BOLD));
        cb.setColspan(10);
        cb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cb.setBorderWidthLeft(0);
        label.addCell(ca);
        label.addCell(cb);
        //Fibre
        ca = new PdfPCell(new Phrase("Fibre " + (int) (nutrients[291] / servings) + "g", LABEL_NORMAL));
        ca.setColspan(6);
        ca.setIndent(16);
        ca.setBorderWidthRight(0);
        cb = new PdfPCell(new Phrase(onePer.format((nutrients[291] / servings) / 25.0), LABEL_BOLD));
        cb.setColspan(10);
        cb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cb.setBorderWidthLeft(0);
        label.addCell(ca);
        label.addCell(cb);
        //Sugar
        ca = new PdfPCell(new Phrase("Sugars " + (int) (nutrients[269] / servings) + "g", LABEL_NORMAL));
        ca.setColspan(10);
        ca.setIndent(16);
        label.addCell(ca);
        //Protein
        ca = new PdfPCell(new Phrase("Protein " + (int) (nutrients[203] / servings) + "g", LABEL_BOLD));
        ca.setColspan(10);
        label.addCell(ca);
        //Vit A
        ca = new PdfPCell(new Phrase("Vitamin A", LABEL_NORMAL));
        ca.setColspan(6);
        ca.setBorderWidthRight(0);
        ca.setBorderWidthTop(2);
        cb = new PdfPCell(cb = new PdfPCell(new Phrase(
                onePer.format(
                        ((nutrients[319] + (nutrients[321] / 12) + (nutrients[834] / 24)) / servings) / 1000),
                LABEL_NORMAL)));
        cb.setColspan(10);
        cb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cb.setBorderWidthLeft(0);
        cb.setBorderWidthTop(2);
        label.addCell(ca);
        label.addCell(cb);
        //Vit C
        ca = new PdfPCell(new Phrase("Vitamin C", LABEL_NORMAL));
        ca.setColspan(6);
        ca.setBorderWidthRight(0);
        cb = new PdfPCell(new Phrase(onePer.format((nutrients[401] / servings) / 60.0), LABEL_NORMAL));
        cb.setColspan(10);
        cb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cb.setBorderWidthLeft(0);
        label.addCell(ca);
        label.addCell(cb);
        //Calcium
        ca = new PdfPCell(new Phrase("Calcium", LABEL_NORMAL));
        ca.setColspan(6);
        ca.setBorderWidthRight(0);
        cb = new PdfPCell(new Phrase(onePer.format((nutrients[301] / servings) / 1100.0), LABEL_NORMAL));
        cb.setColspan(10);
        cb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cb.setBorderWidthLeft(0);
        label.addCell(ca);
        label.addCell(cb);
        //Iron
        ca = new PdfPCell(new Phrase("Iron", LABEL_NORMAL));
        ca.setColspan(6);
        ca.setBorderWidthRight(0);
        cb = new PdfPCell(new Phrase(onePer.format((nutrients[303] / servings) / 14.0), LABEL_NORMAL));
        cb.setColspan(10);
        cb.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cb.setBorderWidthLeft(0);
        label.addCell(ca);
        label.addCell(cb);
        //Add to the table
        label.setHorizontalAlignment(Element.ALIGN_LEFT);
        p.add(label);
        //add to the document
        doc.add(p);

    } catch (DocumentException ex) {
        System.out.println("Error: " + ex.toString());
    }
}

From source file:se.billes.pdf.renderer.model.text.TableParagraph.java

License:Open Source License

@Override
public void onRender(PdfPCell cell) throws PdfRenderException {

    PdfPTable table = new PdfPTable(widths.length);

    try {/*w w  w  .j a v a  2  s . c om*/
        table.setTotalWidth(getTotalWidthsAsPs());
        table.setLockedWidth(true);
        table.setSpacingAfter(0f);

        for (AbstractParagraph tableCell : cells) {

            PdfPCell c = new PdfPCell();
            float[] padding = new float[] { 0f, 0f, 0f, 0f };
            if (tableCell instanceof TableCell) {
                padding = ((TableCell) tableCell).getPadding();
            }
            c.setBorderWidth(0f);
            c.setLeft(0);
            c.setTop(0);
            c.setRight(0);
            c.setBottom(0);
            c.setUseAscender(true);
            c.setIndent(0);
            c.setHorizontalAlignment(Element.ALIGN_LEFT);
            c.setVerticalAlignment(Element.ALIGN_TOP);
            c.setPaddingLeft(SizeFactory.millimetersToPostscriptPoints(padding[0]));
            c.setPaddingBottom(SizeFactory.millimetersToPostscriptPoints(padding[3]));
            c.setPaddingRight(SizeFactory.millimetersToPostscriptPoints(padding[2]));
            c.setPaddingTop(SizeFactory.millimetersToPostscriptPoints(padding[1]));
            c.setBorder(0);
            tableCell.onRender(c);

            table.addCell(c);

        }
        cell.addElement(table);
    } catch (Exception e) {
        throw new PdfRenderException(e);
    }
}

From source file:se.billes.pdf.renderer.request.factory.CellFactory.java

License:Open Source License

public PdfPCell createCell(Block block) {
    float[] margins = block.getMargins();
    PdfPCell cell = new PdfPCell();
    cell.setBorderWidth(0);//  w  w  w.  j a v  a 2s . c  o m
    cell.setVerticalAlignment(VerticalAlign.getByName(block.getVerticalAlign()).getAlignment());
    cell.setLeft(0);
    cell.setTop(0);
    cell.setRight(0);
    cell.setBottom(0);
    cell.setUseAscender(block.isUseAscender());
    cell.setIndent(0);
    cell.setPaddingLeft(SizeFactory.millimetersToPostscriptPoints(margins[0]));
    cell.setPaddingBottom(SizeFactory.millimetersToPostscriptPoints(margins[3]));
    cell.setPaddingRight(SizeFactory.millimetersToPostscriptPoints(margins[1]));
    cell.setPaddingTop(SizeFactory.millimetersToPostscriptPoints(margins[2]));
    cell.setFixedHeight(SizeFactory.millimetersToPostscriptPoints(block.getPosition()[3]));
    cell.setBorder(0);
    cell.setCellEvent(new CellBlockEvent().createEvent(block));
    cell.setRotation(block.getRotation());
    return cell;
}

From source file:se.billes.pdf.renderer.request.factory.CellFactory.java

License:Open Source License

public PdfPCell getFillCell() {
    PdfPCell fillCell = new PdfPCell();
    fillCell.setBorderWidth(0f);//from  www .  ja  va2s.co  m
    fillCell.setLeft(0);
    fillCell.setTop(0);
    fillCell.setRight(0);
    fillCell.setBottom(0);
    fillCell.setUseAscender(true);
    fillCell.setIndent(0);
    fillCell.setHorizontalAlignment(Element.ALIGN_LEFT);
    fillCell.setVerticalAlignment(Element.ALIGN_BOTTOM);
    fillCell.setPaddingLeft(0f);
    fillCell.setPaddingBottom(0f);
    fillCell.setPaddingRight(0f);
    fillCell.setPaddingTop(0f);
    fillCell.setBorder(0);
    renderEmptyCell(fillCell);

    return fillCell;
}