Example usage for com.itextpdf.text.pdf PdfTemplate closePathStroke

List of usage examples for com.itextpdf.text.pdf PdfTemplate closePathStroke

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfTemplate closePathStroke.

Prototype


public void closePathStroke() 

Source Link

Document

Closes the path and strokes it.

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 w  w  . jav a2 s  . c  o  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);
}