Example usage for com.itextpdf.text.pdf PdfContentByte ALIGN_LEFT

List of usage examples for com.itextpdf.text.pdf PdfContentByte ALIGN_LEFT

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfContentByte ALIGN_LEFT.

Prototype

int ALIGN_LEFT

To view the source code for com.itextpdf.text.pdf PdfContentByte ALIGN_LEFT.

Click Source Link

Document

The alignment is left

Usage

From source file:dk.dma.epd.common.util.FALPDFGenerator.java

License:Apache License

public void generateFal1Form(FALForm1 fal1form, String filename) {

    try {// w ww . j  a  v  a  2 s. c o m

        PdfReader pdfReader = new PdfReader("FALForm1.pdf");

        FileOutputStream fileWriteStream = new FileOutputStream(filename);

        PdfStamper pdfStamper = new PdfStamper(pdfReader, fileWriteStream);

        for (int i = 1; i <= pdfReader.getNumberOfPages(); i++) {

            PdfContentByte content = pdfStamper.getUnderContent(i);

            // Text over the existing page
            BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.WINANSI, BaseFont.EMBEDDED);
            content.beginText();
            content.setFontAndSize(bf, 8);

            int xFirstColum = 68;
            int xSecondColum = 314;

            int startYFirstColumn = 659;

            int startYSecondColumn = 659;

            // Arrival Depature
            if (fal1form.isArrival()) {
                content.showTextAligned(PdfContentByte.ALIGN_LEFT, "X", 316, 690, 0);
            } else {
                // Departure
                content.showTextAligned(PdfContentByte.ALIGN_LEFT, "X", 380, 690, 0);
            }

            // Name and Type of ship
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, fal1form.getNameAndTypeOfShip(), xFirstColum,
                    startYFirstColumn, 0);

            // IMO Number
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, fal1form.getImoNumber(), xSecondColum,
                    startYSecondColumn, 0);

            // Call Sign
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, fal1form.getCallSign(), xFirstColum,
                    startYFirstColumn - 30, 0);

            // Voyage Number
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, fal1form.getVoyageNumber(), xSecondColum,
                    startYSecondColumn - 30, 0);

            // Port of Arrival/depature
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, fal1form.getPortOfArrivalDeapture(), xFirstColum,
                    startYFirstColumn - 60, 0);

            // Date and time of arrival/depature
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, fal1form.getDateAndTimeOfArrivalDepature(),
                    xSecondColum, startYFirstColumn - 60, 0);

            // Flag State of ship
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, fal1form.getFlagStateOfShip(), xFirstColum,
                    startYFirstColumn - 90, 0);

            // Name of Master
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, fal1form.getNameOfMaster(), xFirstColum + 135,
                    startYFirstColumn - 90, 0);

            // Last port of call/next port of all
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, fal1form.getLastPortOfCall(), xSecondColum,
                    startYFirstColumn - 90, 0);

            // Certificate of registry
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, fal1form.getCertificateOfRegistry(), xFirstColum,
                    startYFirstColumn - 120, 0);

            String nameAndContact = fal1form.getNameAndContactDetalsOfShipsAgent();

            addMultiLine(nameAndContact, startYFirstColumn, xSecondColum, content, 54, 120);

            // Gross Tonnage
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, fal1form.getGrossTonnage(), xFirstColum,
                    startYFirstColumn - 150, 0);

            // Net Tonnage
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, fal1form.getNetTonnage(), xFirstColum + 135,
                    startYFirstColumn - 150, 0);

            // Position of the ship in the port
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, fal1form.getPositionOfTheShip(), xFirstColum,
                    startYFirstColumn - 180, 0);

            // Brief particulars of voyage
            String briefVoyageParticulars = fal1form.getBriefParticulars();

            addMultiLine(briefVoyageParticulars, startYFirstColumn, xFirstColum, content, 140, 210);

            // Brief particulars of cargo
            String briefCargoParticulars = fal1form.getBriefDescriptionOfCargo();

            addMultiLine(briefCargoParticulars, startYFirstColumn, xFirstColum, content, 140, 257);

            // Number of Crew
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, fal1form.getNumberOfCrew(), xFirstColum,
                    startYFirstColumn - 305, 0);

            // Number of Passengers
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, fal1form.getNumberOfPassengers(),
                    xFirstColum + 130, startYFirstColumn - 305, 0);

            // Remarks
            String remarks = fal1form.getRemarks();
            addMultiLine(remarks, startYFirstColumn, xSecondColum, content, 54, 305);

            // Ship waste requirements
            String wasteRequirements = fal1form.getShipWasteRequirements();
            addMultiLine(wasteRequirements, startYFirstColumn, xSecondColum, content, 54, 405);

            content.endText();
        }

        pdfStamper.close();
        fileWriteStream.close();
        fileWriteStream.flush();

    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }

}

From source file:dk.dma.epd.common.util.FALPDFGenerator.java

License:Apache License

private void addMultiLine(String text, int startYFirstColumn, int xSecondColum, PdfContentByte content,
        int width, int modifier) {

    String parsedtext = "";
    int length = text.length();
    int startPosition = startYFirstColumn - modifier;

    while (text.length() > width) {
        parsedtext = text.substring(0, width);
        if (!parsedtext.subSequence(parsedtext.length() - 1, parsedtext.length()).equals(" ")) {
            parsedtext = parsedtext + "-";
        }/*  w  w w. j  a v a 2s .co  m*/

        // Name and contact detals of ships agent
        content.showTextAligned(PdfContentByte.ALIGN_LEFT, parsedtext, xSecondColum, startPosition, 0);

        text = text.substring(width, length);

        length = text.length();
        startPosition = startPosition - 10;
    }

    // Name and contact detals of ships agent last part
    content.showTextAligned(PdfContentByte.ALIGN_LEFT, text, xSecondColum, startPosition, 0);
}

From source file:fattura.Fattura.java

public void inserisciDatiMaglie(String cliente, String data, PdfStamper s)
        throws SQLException, IOException, DocumentException {
    ArrayMaglia arraymaglia = new ArrayMaglia();
    arraymaglia.ArrayIDmaglia(cliente, data);
    float importo;

    PdfContentByte content = s.getUnderContent(1);//1 for the first page
    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED);
    content.setFontAndSize(bf, 7);/*w ww .  j av  a 2  s . co  m*/

    for (int j = 0; j < arraymaglia.IDmaglie.length; j++) {
        arraymaglia.accessoMaglie(j);
        importo = arraymaglia.importoMaglia(j);
        String convertitore = String.valueOf(importo); //Serve per convertire il ritorno del metodo importoUnitarioMaglia (float) a string per stamparlo,  solo un appoggio
        importi.add(importo); //salva l'importo maglia nella prima posizione array i cui elementi poi andranno sommati per calcolare il totale

        for (int z = 0; z < arraymaglia.riga.length; z++) {
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, arraymaglia.riga[z] + "   ", 95 + x, 538 - y, 0);
            x += 97; //sposta la coordinata y ad ogni stampa
        }

        content.showTextAligned(PdfContentByte.ALIGN_LEFT, "Maglia", 95 + x, 538 - y, 0);
        x += 96;
        content.showTextAligned(PdfContentByte.ALIGN_LEFT, convertitore, 95 + x, 538 - y, 0);

        x = 0;
        y += 20;
    }

}

From source file:fattura.Fattura.java

public void inserisciDatiBorse(String cliente, String data, PdfStamper s)
        throws SQLException, IOException, DocumentException {
    ArrayBorsa arrayborsa = new ArrayBorsa();
    arrayborsa.ArrayIDborsa(cliente, data);
    float importo;

    PdfContentByte content = s.getUnderContent(1);//1 for the first page
    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED);
    content.setFontAndSize(bf, 7);//www . j av a2  s  . c  o  m

    for (int j = 0; j < arrayborsa.IDborse.length; j++) {
        arrayborsa.accessoBorse(j);
        importo = arrayborsa.importoBorsa(j);
        String convertitore = String.valueOf(importo); //Serve per convertire il ritorno del metodo importoUnitarioMaglia (float) a string per stamparlo,  solo un appoggio
        importi.add(importo);
        for (int z = 0; z < arrayborsa.riga.length; z++) {
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, arrayborsa.riga[z] + "   ", 95 + x, 538 - y, 0);
            x += 97; //sposta la coordinata y ad ogni stampa

        }
        content.showTextAligned(PdfContentByte.ALIGN_LEFT, "Borsa", 95 + x, 538 - y, 0);
        x += 97;
        content.showTextAligned(PdfContentByte.ALIGN_LEFT, convertitore, 95 + x, 538 - y, 0);
        x = 0;
        y += 20;
    }
    //MI calcolar il prezzo totale man mano che calcolo i preventivi lo agggiungo!

}

From source file:fattura.Fattura.java

public void inserisciDatiPanta(String cliente, String data, PdfStamper s)
        throws SQLException, IOException, DocumentException {
    ArrayPantalone arraypanta = new ArrayPantalone();
    arraypanta.ArrayIDpantalone(cliente, data);
    float importo = (float) 0.00;

    PdfContentByte content = s.getUnderContent(1);//1 for the first page
    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED);
    content.setFontAndSize(bf, 7);// w  ww  .j a va  2  s . c  om

    for (int j = 0; j < arraypanta.IDpantaloni.length; j++) {
        arraypanta.accessoPantaloni(j);
        importo = arraypanta.importoPanta(j);
        String convertitore = String.valueOf(importo); //Serve per convertire il ritorno del metodo importoUnitarioMaglia (float) a string per stamparlo,  solo un appoggio
        importi.add(importo);
        for (int z = 0; z < arraypanta.riga.length; z++) {
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, arraypanta.riga[z] + "   ", 95 + x, 538 - y, 0);
            x += 97; //sposta la coordinata y ad ogni stampa

        }
        content.showTextAligned(PdfContentByte.ALIGN_LEFT, "Pantalone", 95 + x, 538 - y, 0);
        x += 97;
        content.showTextAligned(PdfContentByte.ALIGN_LEFT, convertitore, 95 + x, 538 - y, 0);
        x = 0;
        y += 20;
    }
}

From source file:fattura.Fattura.java

public void inserisciDatiGiubb(String cliente, String data, PdfStamper s)
        throws SQLException, IOException, DocumentException {
    ArrayGiubbotto arraygiubb = new ArrayGiubbotto();
    arraygiubb.ArrayIDgiubbotto(cliente, data);
    float importo;

    PdfContentByte content = s.getUnderContent(1);//1 for the first page
    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED);
    content.setFontAndSize(bf, 7);//from   ww  w.  j  a  v  a2  s.  com

    for (int j = 0; j < arraygiubb.IDgiubbotti.length; j++) {
        arraygiubb.accessoGiubbotti(j);
        importo = arraygiubb.importoGiubbotto(j);
        String convertitore = String.valueOf(importo); //Serve per convertire il ritorno del metodo importoUnitarioMaglia (float) a string per stamparlo,  solo un appoggio
        importi.add(importo);
        for (int z = 0; z < arraygiubb.riga.length; z++) {
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, arraygiubb.riga[z] + "   ", 95 + x, 538 - y, 0);
            x += 97; //sposta la coordinata y ad ogni stampa

        }
        content.showTextAligned(PdfContentByte.ALIGN_LEFT, "Giubbotto", 95 + x, 538 - y, 0);
        x += 97;
        content.showTextAligned(PdfContentByte.ALIGN_LEFT, convertitore, 95 + x, 538 - y, 0);
        x = 0;
        y += 20;
    }

}

From source file:fattura.Fattura.java

public void inserisciDatiFelpe(String cliente, String data, PdfStamper s)
        throws SQLException, IOException, DocumentException {
    ArrayFelpa arrayfelpa = new ArrayFelpa();
    arrayfelpa.ArrayIDfelpa(cliente, data);
    float importo;

    PdfContentByte content = s.getUnderContent(1);//1 for the first page
    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED);
    content.setFontAndSize(bf, 7);/*from   w w w.j a v a 2  s.  c om*/

    for (int j = 0; j < arrayfelpa.IDfelpe.length; j++) {
        arrayfelpa.accessoFelpe(j);
        importo = arrayfelpa.importoFelpa(j);
        String convertitore = String.valueOf(importo); //Serve per convertire il ritorno del metodo importoUnitarioMaglia (float) a string per stamparlo,  solo un appoggio
        importi.add(importo);
        for (int z = 0; z < arrayfelpa.riga.length; z++) {
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, arrayfelpa.riga[z] + "   ", 95 + x, 538 - y, 0);
            x += 97; //sposta la coordinata y ad ogni stampa

        }
        content.showTextAligned(PdfContentByte.ALIGN_LEFT, "Felpa", 95 + x, 538 - y, 0);
        x += 97;
        content.showTextAligned(PdfContentByte.ALIGN_LEFT, convertitore, 95 + x, 538 - y, 0);
        x = 0;
        y += 20;
    }
    //MI calcolar il prezzo totale man mano che calcolo i preventivi lo agggiungo!

}

From source file:fattura.Fattura.java

public void inserisciDatiPubb(String cliente, String data, PdfStamper s)
        throws SQLException, IOException, DocumentException {
    ArrayPubblicita arraypubb = new ArrayPubblicita();
    arraypubb.ArrayIDpubb(cliente, data);
    float importo;

    PdfContentByte content = s.getUnderContent(1);//1 for the first page
    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED);
    content.setFontAndSize(bf, 7);/*from www.ja v a 2  s .  co  m*/

    for (int j = 0; j < arraypubb.IDpubb.length; j++) {
        arraypubb.accessoPubb(j);
        importo = arraypubb.importoPubblicita(j);
        String convertitore = String.valueOf(importo); //Serve per convertire il ritorno del metodo importoUnitarioMaglia (float) a string per stamparlo,  solo un appoggio
        importi.add(importo); //salva l'importo maglia nella prima posizione array i cui elementi poi andranno sommati per calcolare il totale

        for (int z = 0; z < arraypubb.riga.length; z++) {
            content.showTextAligned(PdfContentByte.ALIGN_LEFT, arraypubb.riga[z] + "   ", 95 + x, 538 - y, 0);
            x += 97; //sposta la coordinata y ad ogni stampa
        }

        content.showTextAligned(PdfContentByte.ALIGN_LEFT, "Mat. Pubb.", 95 + x, 538 - y, 0);
        x += 101;
        content.showTextAligned(PdfContentByte.ALIGN_LEFT, convertitore, 95 + x, 538 - y, 0);

        x = 0;
        y += 20;
    }

}

From source file:fc.extensions.itext.Writer.java

License:MIT License

public void writeBarcode(String barcode, float leftX, float bottomY, float scalePercent, boolean isShowCode)
        throws Exception {
    Barcode39 code39 = new Barcode39();
    code39.setStartStopText(false);//from   www. j a v  a 2  s.  c  o  m
    code39.setTextAlignment(PdfContentByte.ALIGN_LEFT);
    if (!isShowCode) {
        code39.setFont(null);
    }
    code39.setCode(barcode);
    Image image = code39.createImageWithBarcode(pdfWriterCB, this.baseColor, this.baseColor);
    image.setAbsolutePosition(leftX, bottomY);
    image.scalePercent(scalePercent);
    pdfWriterCB.addImage(image);
}

From source file:fc.extensions.itext.Writer.java

License:MIT License

public void addCell(PdfPTable table, String content, int fontSize, float borderWidth, int columnSpan) {
    PdfPCell pCell = new PdfPCell();
    if (columnSpan > 1) {
        pCell.setColspan(columnSpan);//from w w w  . j a  v a2s  .  c  o m
    }
    pCell.setBorderWidth(borderWidth);
    pCell.setPhrase(new Phrase(content, getFont(fontSize)));
    pCell.setNoWrap(false);
    pCell.setHorizontalAlignment(PdfContentByte.ALIGN_LEFT);
    pCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table.addCell(pCell);
}