Example usage for com.itextpdf.text Chunk Chunk

List of usage examples for com.itextpdf.text Chunk Chunk

Introduction

In this page you can find the example usage for com.itextpdf.text Chunk Chunk.

Prototype

@Deprecated
public Chunk(final DrawInterface separator, final float tabPosition, final boolean newline) 

Source Link

Document

Creates a tab Chunk.

Usage

From source file:com.ashish.medicine.admin.invoice.InvoiceAction.java

public void addLogo(PdfPTable table) throws BadElementException, MalformedURLException, IOException {
    String logoFilePath = "C:/Ashish/Java/logo.png";
    Image logo = Image.getInstance(logoFilePath);

    table.setWidthPercentage(100);//from www .  ja  v  a2  s. c  om

    PdfPCell logocell = new PdfPCell();
    logocell.setBorder(Rectangle.NO_BORDER);
    logocell.addElement(new Chunk(logo, 0, 5));

    table.addCell(logocell);

    logocell = new PdfPCell();
    logocell.setBorder(Rectangle.NO_BORDER);

    table.addCell(logocell);
    table.addCell(logocell);
    table.addCell(logocell);
    table.addCell(logocell);
    table.addCell(logocell);
}

From source file:com.ashish.medicine.admin.invoice.InvoiceAction.java

public void addImage(Document document) throws DocumentException, MalformedURLException, IOException {
    Image logo = Image.getInstance(invoiceBean.getLogoPath());
    document.add(new Chunk(logo, 0, 5));
}

From source file:de.domjos.schooltools.core.utils.fileUtils.PDFBuilder.java

License:Open Source License

public void onEndPage(PdfWriter writer, Document document) {
    try {/*from   ww  w .  j  a va2  s . c om*/
        Rectangle rect = writer.getBoxSize("art");
        Image img = Image.getInstance(Converter.convertDrawableToByteArray(this.context, R.drawable.icon));
        Phrase phrase = new Phrase();
        phrase.add(new Chunk(img, 0, 0));
        ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, phrase, rect.getLeft(),
                rect.getBottom(), 0);
        ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER,
                new Phrase(String
                        .valueOf(this.context.getString(R.string.api_page) + " " + document.getPageNumber())),
                rect.getRight(), rect.getBottom(), 0);
    } catch (Exception ex) {
        Helper.printException(context, ex);
    }
}

From source file:Integral.PDF.java

/**
 * Crea un objeto imagen de tipo Chunk//from   w  w w. j av a2s  .com
 * @param archivo Ruta de la imagen
 * @param x Posision en x para la imagen dentro del archivo
 * @param y Posision en y para la imagen dentro del archivo
 * @param escala escala de la imagen en porcentaje
 * @return Retorna una objeto de tipo Chunk
 */
public Chunk crearImagen(String archivo, int x, int y, int escala) {
    try {
        RandomAccessFile rf1 = new RandomAccessFile(ruta + archivo, "r");
        int size1 = (int) rf1.length();
        byte imagedata[] = new byte[size1];
        rf1.readFully(imagedata);
        rf1.close();
        Image img11 = Image.getInstance(imagedata);
        img11.scalePercent(escala);
        Chunk logo = new Chunk(img11, x, y);
        return logo;
    } catch (Exception e) {
        System.out.println(e);
        return null;
    }
}

From source file:Integral.PDF.java

/**
 * Crea un objeto imagen de tipo Chunk/*from   ww  w.jav  a 2s . c o  m*/
 * @param archivo Ruta de la imagen
 * @param x Posision en x para la imagen dentro del archivo
 * @param y Posision en y para la imagen dentro del archivo
 * @param w_escala escala de la imagen en relacion horizontal
 * @param h_escala escala de la imagen en relacion a vertical
 * @param grados grados para girar la imagen
 * @return Retorna una objeto de tipo Chunk
 */
public Chunk crearImagen(String archivo, int x, int y, int w_escala, int h_escala, float grados) {
    try {
        RandomAccessFile rf1 = new RandomAccessFile(ruta + archivo, "r");
        int size1 = (int) rf1.length();
        byte imagedata[] = new byte[size1];
        rf1.readFully(imagedata);
        rf1.close();
        Image img11 = Image.getInstance(imagedata);
        img11.scaleAbsolute(w_escala, h_escala);
        img11.setRotationDegrees(grados);
        Chunk logo = new Chunk(img11, x, y);
        return logo;
    } catch (Exception e) {
        System.out.println(e);
        return null;
    }
}

From source file:org.opentox.io.publishable.PDFObject.java

License:Open Source License

public void publish(YaqpIOStream stream) throws YaqpException {
    if (stream == null) {
        throw new NullPointerException("Cannot public pdf to a null output stream");
    }//w  ww.j a v  a 2 s. com
    try {
        Document doc = new Document();
        try {
            PdfWriter.getInstance(doc, (OutputStream) stream.getStream());
        } catch (ClassCastException ex) {
            throw new ClassCastException("The stream you provided is not a valid output stream");
        }
        doc.open();
        doc.addAuthor(pdfAuthor);
        doc.addCreationDate();
        doc.addProducer();
        doc.addSubject(subject);
        doc.addCreator(pdfCreator);
        doc.addTitle(pdfTitle);
        doc.addKeywords(pdfKeywords);
        doc.addHeader("License", "GNU GPL v3");
        Image image = null;
        try {
            image = Image.getInstance(new URL(OpenToxLogoUrl));
        } catch (Exception ex) {// OpenTox Logo was not found on the web...
            try {// use the cached image instead
                YaqpLogger.LOG.log(new Trace(getClass(), "OpenTox Logo not found at " + OpenToxLogoUrl));
                image = Image.getInstance(alternativeLogoPath);
            } catch (Exception ex1) {// if no image at local folder
                YaqpLogger.LOG.log(new Debug(getClass(),
                        "OpenTox Logo not found at " + alternativeLogoPath + " :: " + ex1));
            }
        }
        if (image != null) {
            image.scalePercent(40);
            image.setAnnotation(new Annotation(0, 0, 0, 0, "http://opentox.org"));
            Chunk ck_ot = new Chunk(image, -5, -30);
            doc.add(ck_ot);
        }
        try {
            Image yaqp = Image.getInstance(yaqpLogo);
            yaqp.scalePercent(30);
            yaqp.setAnnotation(new Annotation(0, 0, 0, 0, "https://opentox.ntua.gr"));
            yaqp.setAlt("YAQP(R), yet another QSAR Project");
            Chunk ck_yaqp = new Chunk(yaqp, 15, -30);
            doc.add(ck_yaqp);
        } catch (Exception ex) {
            YaqpLogger.LOG
                    .log(new Warning(getClass(), "YAQP Logo not found at " + kinkyDesignLogo + " :: " + ex));
        }
        doc.add(new Paragraph("\n\n\n"));
        for (Element e : elements) {
            doc.add(e);
        }
        doc.close();
    } catch (DocumentException ex) {
        String message = "Error while generating PDF representation.";
        YaqpLogger.LOG.log(new Warning(getClass(), message));
        throw new YaqpException(XPDF18, message, ex);
    }

}

From source file:org.unesco.jisis.printsort.BarCodeGenerator.java

public void generateBarCode() {
    /** Step 1: Create a Document*/
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    try {//from w  w w.  j a v  a2 s.c  o m

        /** Step 2: Create PDF Writer*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("sanjaalDotCom_BarCode1.pdf"));

        /** Step 3: Open the document so that we can write over it.*/
        document.open();

        /** Step 4: We have to create a set of contents.*/
        contentByte = writer.getDirectContent();

        PdfPTable table = new PdfPTable(2);
        table.setWidthPercentage(100);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
        table.getDefaultCell().setFixedHeight(70);

        String myText = "www.sanjaal.com"; // Text to encode

        table.addCell("CODE 39");
        table.addCell(new Phrase(new Chunk(createBarCode39(myText.toUpperCase()), 0, 0)));

        table.addCell("CODE 39 EXTENDED");
        table.addCell(new Phrase(new Chunk(createBarcode39Extended(myText), 0, 0)));

        table.addCell("CODE 128");
        table.addCell(new Phrase(new Chunk(createBarcode128(myText), 0, 0)));

        table.addCell("CODE INTERLEAVED");
        String myTextNum = "12345";
        table.addCell(new Phrase(new Chunk(createBarcodeInter25(myTextNum), 0, 0)));

        table.addCell("CODE POSTNET");
        table.addCell(new Phrase(new Chunk(createBarcodePostnet(myTextNum), 0, 0)));

        table.addCell("CODE PLANET");
        table.addCell(new Phrase(new Chunk(createBarcodePostnetPlanet(myTextNum), 0, 0)));

        String myTextEAN13 = "1234567890123";
        table.addCell("CODE EAN");
        table.addCell(new Phrase(new Chunk(createBarcodeEAN(myTextEAN13), 0, 0)));

        table.addCell("CODE EAN\nWITH\nSUPPLEMENTAL 5");
        table.addCell(new Phrase(new Chunk(createBARCodeEANSUPP(myTextEAN13, "12345"), 0, 0)));

        document.add(table);
    } catch (Exception de) {
        de.printStackTrace();
    }

    // step 5: we close the document
    document.close();
}

From source file:sipl.recursos.GenerarPDFGrafica.java

private void addTitlePage(Document document)
        throws DocumentException, MalformedURLException, BadElementException, IOException {
    Paragraph preface = new Paragraph();
    addEmptyLine(preface, 1);//from   ww w  .j  ava  2  s.  c  om
    preface.add(new Paragraph(Titulo, catFont));
    addEmptyLine(preface, 1);
    preface.add(new Paragraph(
            "Reporte generado por: " + user.getNombre() + " " + user.getApellido() + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            smallBold));
    addEmptyLine(preface, 3);
    preface.add(new Paragraph("Este documento es creado a peticin del autor", smallBold));

    addEmptyLine(preface, 6);
    Image img = Image.getInstance(direc + "img//logo_unab.jpg");
    img.scaleAbsolute(70, 100);
    img.setAlignment(Image.ALIGN_CENTER);
    Chunk c = new Chunk(img, 0, 0);
    preface.add(c);
    document.add(preface);
    document.newPage();
    Paragraph preface1 = new Paragraph();
    preface1.add(new Paragraph("Grfica", smallBold));
    addEmptyLine(preface1, 20);
    img = Image.getInstance(imgG);
    img.scaleAbsolute(400, 300);
    img.setAlignment(Image.ALIGN_CENTER);
    c = new Chunk(img, 0, 0);
    preface1.add(c);
    document.add(preface1);
    document.newPage();
}

From source file:sipl.recursos.GenerarPDFListar.java

private void addTitlePage(Document document)
        throws DocumentException, MalformedURLException, BadElementException, IOException {
    Paragraph preface = new Paragraph();
    addEmptyLine(preface, 1);/*from   www . j av a  2s .  c om*/
    preface.add(new Paragraph(Titulo, catFont));
    addEmptyLine(preface, 1);
    preface.add(new Paragraph(
            "Reporte generado por: " + user.getNombre() + " " + user.getApellido() + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            smallBold));
    addEmptyLine(preface, 3);
    preface.add(new Paragraph("Este documento es creado a peticin del autor", smallBold));
    addEmptyLine(preface, 6);
    Image img = Image.getInstance(direc + "img//logo_unab.jpg");
    img.scaleAbsolute(70, 100);
    img.setAlignment(Image.ALIGN_CENTER);
    Chunk c = new Chunk(img, 0, 0);
    preface.add(c);
    document.add(preface);
    document.newPage();
}

From source file:sipl.recursos.GenerarPDFtipomaterial.java

private static void addTitlePage(Document document)
        throws DocumentException, MalformedURLException, BadElementException, IOException {
    Paragraph preface = new Paragraph();
    addEmptyLine(preface, 1);/*from  w  w w.j av a  2s  . c  om*/
    preface.add(new Paragraph(Titulo, catFont));
    addEmptyLine(preface, 1);
    preface.add(new Paragraph(
            "Reporte generado por: " + user.getNombre() + " " + user.getApellido() + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            smallBold));
    addEmptyLine(preface, 3);
    preface.add(new Paragraph("Este documento es creado a peticin del autor", smallBold));

    addEmptyLine(preface, 6);
    Image img = Image.getInstance(direc + "img//logo_unab.jpg");
    img.scaleAbsolute(70, 100);
    img.setAlignment(Image.ALIGN_CENTER);
    Chunk c = new Chunk(img, 0, 0);
    preface.add(c);
    document.add(preface);
    document.newPage();
    Paragraph preface1 = new Paragraph();
    preface1.add(new Paragraph("Grfica", smallBold));
    addEmptyLine(preface1, 20);
    img = Image.getInstance(imgG);
    img.scaleAbsolute(400, 300);
    img.setAlignment(Image.ALIGN_CENTER);
    c = new Chunk(img, 0, 0);
    preface1.add(c);
    document.add(preface1);
    document.newPage();
}