Example usage for com.itextpdf.text Anchor setName

List of usage examples for com.itextpdf.text Anchor setName

Introduction

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

Prototype

public void setName(final String name) 

Source Link

Document

Sets the name of this Anchor.

Usage

From source file:com.example.pdfcreate.MainActivity.java

private static void addContent(Document document) throws DocumentException {
    Anchor anchor = new Anchor("ESTIMATING APP");
    anchor.setName("ESTIMATING APP");

    // Second parameter is the number of the chapter
    Chapter catPart = new Chapter(new Paragraph(anchor), 1);

    Paragraph subPara = new Paragraph("Subcategory 1");
    Section subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Hello This Is PDF yeeee"));

    subPara = new Paragraph("Subcategory 2");
    subCatPart = catPart.addSection(subPara);

    subCatPart.add(new Paragraph(str1));
    subCatPart.add(new Paragraph(str2));
    subCatPart.add(new Paragraph("Paragraph 3"));

    // Add a list
    createList(subCatPart);//ww w  .j  a  v  a  2s .  c  om
    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, 5);
    subCatPart.add(paragraph);

    // Add a table
    createTable(subCatPart);

    // Now add all this to the document
    document.add(catPart);

    // Next section
    anchor = new Anchor("Second Chapter");
    anchor.setName("Second Chapter");

    // Second parameter is the number of the chapter
    catPart = new Chapter(new Paragraph(anchor), 1);

    subPara = new Paragraph("Subcategory");
    subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("This is a very important message"));

    // Now add all this to the document
    document.add(catPart);

}

From source file:com.horizzon.inventerium.ExportPdf.java

private static void addContent(Document document) throws DocumentException {
    Anchor anchor = new Anchor("First Chapter");
    anchor.setName("First Chapter");

    // Second parameter is the number of the chapter
    Chapter catPart = new Chapter(new Paragraph(anchor), 1);

    Paragraph subPara = new Paragraph("Subcategory 1");
    Section subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Hello"));

    subPara = new Paragraph("Subcategory 2");
    subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Paragraph 1"));
    subCatPart.add(new Paragraph("Paragraph 2"));
    subCatPart.add(new Paragraph("Paragraph 3"));

    // add a list
    createList(subCatPart);//w  w  w.j  av  a2 s . c om
    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, 5);
    subCatPart.add(paragraph);

    // add a table
    createTable(subCatPart);

    // now add all this to the document
    document.add(catPart);

    // Next section
    //    anchor = new Anchor("Second Chapter", catFont);
    //    anchor.setName("Second Chapter");

    // Second parameter is the number of the chapter
    //    catPart = new Chapter(new Paragraph(anchor), 1);

    //    subPara = new Paragraph("Subcategory", subFont);
    //    subCatPart = catPart.addSection(subPara);
    //    subCatPart.add(new Paragraph("This is a very important message"));

    // now add all this to the document
    //   document.add(catPart);

}

From source file:com.imipgroup.hieuvt.pdf.PdfUtils.java

private static void addContent(Document document) {
    Anchor anchor = new Anchor("First Chapter", catFont);
    anchor.setName("First Chapter");

    // Second parameter is the number of the chapter
    Chapter catPart = new Chapter(new Paragraph(anchor), 1);

    Paragraph subPara = new Paragraph("Subcategory 1", subFont);
    Section subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Hello"));

    subPara = new Paragraph("Subcategory 2", subFont);
    subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Paragraph 1"));
    subCatPart.add(new Paragraph("Paragraph 2"));
    subCatPart.add(new Paragraph("Paragraph 3"));

    // add a list
    createList(subCatPart);/*from  w  w  w. j  a  v a  2 s. c om*/
    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, 5);
    subCatPart.add(paragraph);
    // add a table
    createTable(subCatPart);

    // now add all this to the document
    try {
        document.add(catPart);
    } catch (DocumentException e) {
        e.printStackTrace();
    }

    // Next section
    anchor = new Anchor("Second Chapter", catFont);
    anchor.setName("Second Chapter");

    // Second parameter is the number of the chapter
    catPart = new Chapter(new Paragraph(anchor), 1);

    subPara = new Paragraph("Subcategory", subFont);
    subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("This is a very important message"));

    // now add all this to the document
    try {
        document.add(catPart);
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}

From source file:com.pdg.ticket.utils.FirstPdf.java

private static void addContent(Document document) throws DocumentException {
    Anchor anchor = new Anchor("First Chapter", catFont);
    anchor.setName("First Chapter");

    // Second parameter is the number of the chapter
    Chapter catPart = new Chapter(new Paragraph(anchor), 1);

    Paragraph subPara = new Paragraph("Subcategory 1", subFont);
    Section subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Hello"));

    subPara = new Paragraph("Subcategory 2", subFont);
    subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Paragraph 1"));
    subCatPart.add(new Paragraph("Paragraph 2"));
    subCatPart.add(new Paragraph("Paragraph 3"));

    // Add a list
    //createList(subCatPart);
    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, 5);//from w  w w.  j  a  v a2 s.c o  m
    subCatPart.add(paragraph);

    // Add a table
    createTable(subCatPart);

    // Now add all this to the document
    document.add(catPart);

    //      // Next section
    //      anchor = new Anchor("Second Chapter", catFont);
    //      anchor.setName("Second Chapter");
    //
    //      // Second parameter is the number of the chapter
    //      catPart = new Chapter(new Paragraph(anchor), 1);
    //
    //      subPara = new Paragraph("Subcategory", subFont);
    //      subCatPart = catPart.addSection(subPara);
    //      subCatPart.add(new Paragraph("This is a very important message"));
    //
    //      // Now add all this to the document
    //      document.add(catPart);

}

From source file:com.shashi.itext.write.FirstPdf.java

private static void addContent(Document document) throws DocumentException {

    Anchor anchor = new Anchor("First Chapter", catFont);
    anchor.setName("First Chapter");

    // Second parameter is the number of the chapter
    Chapter catPart = new Chapter(new Paragraph(anchor), 1);

    Paragraph subPara = new Paragraph("Subcategory 1", subFont);
    Section subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Hello"));

    subPara = new Paragraph("Subcategory 2", subFont);
    subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Paragraph 1"));
    subCatPart.add(new Paragraph("Paragraph 2"));
    subCatPart.add(new Paragraph("Paragraph 3"));

    // Add a list
    createList(subCatPart);//  www. j a  v  a  2 s  .  c  o m
    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, 5);
    subCatPart.add(paragraph);

    // Add a table
    createTable(subCatPart);

    // Now add all this to the document
    document.add(catPart);

    // Next section
    anchor = new Anchor("Second Chapter", catFont);
    anchor.setName("Second Chapter");

    // Second parameter is the number of the chapter
    catPart = new Chapter(new Paragraph(anchor), 1);

    subPara = new Paragraph("Subcategory", subFont);
    subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("This is a very important message"));

    // Now add all this to the document
    document.add(catPart);

}

From source file:com.util.Imprimir.java

public static void addContent(Document document) throws DocumentException {
    Anchor anchor = new Anchor("Capitulo Primeiro", catFont);
    anchor.setName("Capitulo Primeiro");

    // Second parameter is the number of the chapter
    Chapter catPart = new Chapter(new Paragraph(anchor), 1);

    Paragraph subPara = new Paragraph("Subcategoria 1", subFont);
    Section subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Hello"));

    subPara = new Paragraph("Subcategoria 2", subFont);
    subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("Paragrafo 1"));
    subCatPart.add(new Paragraph("Paragrafo 2"));
    subCatPart.add(new Paragraph("Paragrafo 3"));

    // add a list
    createList(subCatPart);/*from   w w w .j a  v a  2  s  . c o m*/
    Paragraph paragraph = new Paragraph();
    addEmptyLine(paragraph, 5);
    subCatPart.add(paragraph);

    // add a table
    createTable(subCatPart);

    // now add all this to the document
    document.add(catPart);

    // Next section
    anchor = new Anchor("Capitulo Segundo", catFont);
    anchor.setName("Capitulo Segundo");

    // Second parameter is the number of the chapter
    catPart = new Chapter(new Paragraph(anchor), 1);

    subPara = new Paragraph("Subcategoria", subFont);
    subCatPart = catPart.addSection(subPara);
    subCatPart.add(new Paragraph("This is a very important message"));

    // now add all this to the document
    document.add(catPart);

}

From source file:com.VanLesh.macsv10.macs.Models.Pdf.java

License:GNU General Public License

private static void addContent(Document doc, Calculation calc) {
    try {/*from   w w w  . jav a2  s. co  m*/
        //special font so we can render greek characters
        BaseFont bfComic = BaseFont.createFont("/system/fonts/DroidSansFallback.ttf", BaseFont.IDENTITY_H,
                BaseFont.EMBEDDED);
        Font font1 = new Font(bfComic, 12);
        Font tgfont, tipfont;

        if (calc.getRollover() > calc.getDrag()) {
            tipfont = redFont;
            tgfont = smallBold;
        } else {
            tipfont = smallBold;
            tgfont = redFont;
        }
        Anchor anchor = new Anchor("Site", subFont);
        anchor.setName("Site Parameters");
        Paragraph identifier = new Paragraph("Calculation ID:    " + calc.getTitle(), font1);
        Paragraph engineer = new Paragraph("Engineer:    " + calc.getEngineerName(), font1);
        Paragraph jobsite = new Paragraph("Jobsite:     " + calc.getJobSite(), font1);
        Paragraph latitude = new Paragraph("Latitude:     " + calc.getLatitude(), font1);
        Paragraph longitude = new Paragraph("Longitude:     " + calc.getLongitude(), font1);

        Anchor vehicleAnchor = new Anchor("Vehicle", subFont);
        vehicleAnchor.setName("Vehicle");
        Paragraph vehicleclass = new Paragraph("Vehicle Class:     " + calc.getVehicle().getVehicleClass(),
                font1);
        Paragraph vehicletype = new Paragraph("Vehicle Type:     " + calc.getVehicle().getVehicleType(), font1);
        Paragraph vehicleweight = new Paragraph("Wv:     " + calc.getVehicle().getWv(), font1);
        Paragraph vehicletracklength = new Paragraph("Tl:     " + calc.getVehicle().getTrackL(), font1);
        Paragraph vehicletrackwidth = new Paragraph("Tw:     " + calc.getVehicle().getTrackW(), font1);
        Paragraph vehiclebladewidth = new Paragraph("Wb:     " + calc.getVehicle().getBladeW(), font1);

        Anchor soilAnchor = new Anchor("Soil", subFont);
        soilAnchor.setName("Soil");
        Paragraph soiltype = new Paragraph("Soil Type:     " + calc.getSoil().getName(), font1);
        Paragraph soilunitweight = new Paragraph("\u03B3:     " + calc.getSoil().getunitW(), font1);
        Paragraph soilfrictionangle = new Paragraph("\u03A6:     " + calc.getSoil().getfrictA(), font1);
        Paragraph soilcohesion = new Paragraph("c:     " + calc.getSoil().getC(), font1);

        Anchor measurementsAnchor = new Anchor("Measurements", subFont);
        anchor.setName("Measurements");
        Paragraph beta = new Paragraph("\u03B2:     " + calc.getBeta(), font1);
        Paragraph theta = new Paragraph("\u03B8:     " + calc.getTheta(), font1);
        Paragraph Ha = new Paragraph("Ha:     " + calc.getHa(), font1);
        Paragraph La = new Paragraph("La:     " + calc.getLa(), font1);
        Paragraph Db = new Paragraph("Db:     " + calc.getD_b(), font1);

        Anchor resultsAnchor = new Anchor("Results", subFont);
        int drag = (int) calc.getDrag();
        int roll = (int) calc.getRollover();
        Paragraph Tg = new Paragraph("Anchor cap Sliding :     " + drag, tgfont);
        Paragraph tipover = new Paragraph("Anchor cap Overturning:     " + roll, tipfont);

        doc.add(anchor);
        doc.add(identifier);
        doc.add(engineer);
        doc.add(jobsite);
        doc.add(latitude);
        doc.add(longitude);

        doc.add(vehicleAnchor);
        doc.add(vehicleclass);
        doc.add(vehicletype);
        doc.add(vehicleweight);
        doc.add(vehicletracklength);
        doc.add(vehicletrackwidth);
        doc.add(vehiclebladewidth);

        doc.add(soilAnchor);
        doc.add(soiltype);
        doc.add(soilunitweight);
        doc.add(soilfrictionangle);
        doc.add(soilcohesion);

        doc.add(measurementsAnchor);
        doc.add(beta);
        doc.add(theta);
        doc.add(Ha);
        doc.add(La);
        doc.add(Db);

        doc.add(resultsAnchor);
        doc.add(Tg);
        doc.add(tipover);
        Log.e("addingcontent", "complete");

    } catch (Exception e) {
        Font font1 = new Font(Font.FontFamily.HELVETICA, 24, Font.NORMAL, BaseColor.BLACK);

    }

}

From source file:com.workhub.utils.PDFUtils.java

private static void addContent(Document document, List<ElementModel> models) throws DocumentException {
    for (int i = 0; i < models.size(); i++) {
        ElementModel elementModel = models.get(i);
        Anchor anchor = new Anchor(elementModel.getTitle(), catFont);
        anchor.setName(elementModel.getTitle());
        // Second parameter is the number of the chapter
        Chapter catPart = new Chapter(new Paragraph(anchor), i + 1);

        Paragraph content = new Paragraph();
        catPart.add(content);/*from  www  .  ja  va2 s . c o  m*/
        addEmptyLine(content, 2);

        switch (elementModel.getType()) {
        case Constants.TYPE_ELEMENT_TEXT:
            content.add(new Paragraph(((TextElementModel) elementModel).getContent(), smallBold));

            break;
        case Constants.TYPE_ELEMENT_LINK:
            content.add(new Paragraph(((LinkElementModel) elementModel).getContent(), smallBold));

            break;
        case Constants.TYPE_ELEMENT_PICTURE:
            Image image1;
            try {
                if (((PictureElementModel) elementModel).getContent() != null) {
                    image1 = Image.getInstance(((PictureElementModel) elementModel).getContent());

                    content.add(image1);
                }
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            break;
        case Constants.TYPE_ELEMENT_FILE:
            content.add(new Paragraph(((FileElementModel) elementModel).getTitle(), smallBold));
            break;

        }

        document.add(catPart);
    }

}

From source file:com.zaptech.pdfdemo.MainActivity.java

private void addContent(Document document) {
    try {/*from w  w w  .j a  v a  2 s.c  o  m*/
        Anchor anchor = new Anchor("First Chapter", catFont);
        anchor.setName("First Chapter");
        Chapter chapter = new Chapter(new Paragraph(anchor), 1);
        Paragraph paragraph = new Paragraph("Subcategory 1", subFont);
        Section section = chapter.addSection(paragraph);
        section.add(new Paragraph("Hello"));
        paragraph = new Paragraph("Subcategory 2", subFont);
        section = chapter.addSection(paragraph);
        section.add(new Paragraph("Paragraph 1"));
        section.add(new Paragraph("Paragraph 2"));
        section.add(new Paragraph("Paragraph 3"));
        createList(section);
        Paragraph paragraph1 = new Paragraph();
        addEmptyLine(paragraph1, 5);
        section.add(paragraph1);
        document.add(chapter);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Controller.CrearPDF.java

/**
 * We create a PDF document with iText using different elements to learn 
 * to use this library.//w  w w.j a va  2s .  c o  m
 * Creamos un documento PDF con iText usando diferentes elementos para aprender 
 * a usar esta librera.
 * @param pdfNewFile  <code>String</code> 
 *      pdf File we are going to write. 
 *      Fichero pdf en el que vamos a escribir. 
 */
//    public void createPDF(File pdfNewFile, ReparacionEntity reparacion) throws Exception {
public void createPDF(File pdfNewFile) throws Exception {
    // We create the document and set the file name.        
    // Creamos el documento e indicamos el nombre del fichero.
    try {
        //            ClienteController cc = new ClienteController();
        //            Cliente cliente = cc.buscarPorId(reparacion.getCliente());
        Document document = new Document();
        try {

            PdfWriter.getInstance(document, new FileOutputStream(pdfNewFile));

        } catch (FileNotFoundException fileNotFoundException) {
            System.out.println("No such file was found to generate the PDF "
                    + "(No se encontr el fichero para generar el pdf)" + fileNotFoundException);
        }
        document.open();
        // We add metadata to PDF
        // Aadimos los metadatos del PDF
        document.addTitle("Table export to PDF (Exportamos la tabla a PDF)");
        document.addSubject("Using iText (usando iText)");
        document.addKeywords("Java, PDF, iText");
        document.addAuthor("Cdigo Xules");
        document.addCreator("Cdigo Xules");

        // First page
        // Primera pgina 
        Chunk chunk = new Chunk("RDEN DE TRABAJO", categoryFont);
        Chunk c2 = new Chunk("\n\n\nCentro de Formacin SATCAR6\n" + "Calle Artes Grficas n1 Nave 12 A\n"
                + "Pinto (28320), Madrid", smallFont);

        Chunk c3 = new Chunk("Datos del Cliente", smallBold);
        //            Chunk c4 = new Chunk("Nombre: "+cliente.getRazonSocial(),smallBold);
        //            Chunk c5 = new Chunk("Poblacin: "+cliente.getPoblacion(),smallBold);
        //            Chunk c6 = new Chunk("Provincia: "+cliente.getProvincia(),smallBold);
        //            Chunk c7 = new Chunk("Cdigo Postal: "+cliente.getCp(),smallBold);
        //            Chunk c8 = new Chunk("Num Telfono: Pepito"+cliente.getTlf1(),smallBold);
        Chunk c4 = new Chunk("Nombre: Jesus Eduardo Garcia Toril", smallBold);
        Chunk c5 = new Chunk("Poblacin: Pinto", smallBold);
        Chunk c6 = new Chunk("Provincia: Madrid", smallBold);
        Chunk c7 = new Chunk("Cdigo Postal: 28320", smallBold);
        Chunk c8 = new Chunk("Num Telfono: 659408182", smallBold);

        Paragraph parrafo = new Paragraph(chunk);
        Paragraph p2 = new Paragraph(c2);
        Paragraph p3 = new Paragraph(c3);
        Phrase ph1 = new Phrase(c4);
        Phrase ph2 = new Phrase(c5);
        Phrase ph3 = new Phrase(c6);
        Phrase ph4 = new Phrase(c7);
        Phrase ph5 = new Phrase(c8);

        // Let's create de first Chapter (Creemos el primer captulo)

        // We add an image (Aadimos una imagen)
        Image image;
        try {
            parrafo.setAlignment(Element.ALIGN_CENTER);
            image = Image.getInstance(iTextExampleImage);
            image.setAbsolutePosition(0, 750);
            p2.setAlignment(Element.ALIGN_LEFT);
            document.add(parrafo);
            document.add(image);
            document.add(p2);
            document.add(p3);
            document.add(ph1);
            document.add(ph2);
            document.add(ph3);
            document.add(ph4);
            document.add(ph5);

        } catch (BadElementException ex) {
            System.out.println("Image BadElementException" + ex);
        }

        // Second page - some elements
        // Segunda pgina - Algunos elementos

        // List by iText (listas por iText)
        String text = "test 1 2 3 ";
        for (int i = 0; i < 5; i++) {
            text = text + text;
        }
        List list = new List(List.UNORDERED);
        ListItem item = new ListItem(text);
        item.setAlignment(Element.ALIGN_JUSTIFIED);
        list.add(item);
        text = "a b c align ";
        for (int i = 0; i < 5; i++) {
            text = text + text;
        }
        item = new ListItem(text);
        item.setAlignment(Element.ALIGN_JUSTIFIED);
        list.add(item);
        text = "supercalifragilisticexpialidocious ";
        for (int i = 0; i < 3; i++) {
            text = text + text;
        }
        item = new ListItem(text);
        item.setAlignment(Element.ALIGN_JUSTIFIED);
        list.add(item);

        // How to use PdfPTable
        // Utilizacin de PdfPTable

        // We use various elements to add title and subtitle
        // Usamos varios elementos para aadir ttulo y subttulo
        Anchor anchor = new Anchor("Table export to PDF (Exportamos la tabla a PDF)", categoryFont);
        anchor.setName("Table export to PDF (Exportamos la tabla a PDF)");
        Chapter chapTitle = new Chapter(new Paragraph(anchor), 1);
        Paragraph paragraph = new Paragraph("Do it by Xules (Realizado por Xules)", subcategoryFont);
        Section paragraphMore = chapTitle.addSection(paragraph);
        paragraphMore.add(new Paragraph("This is a simple example (Este es un ejemplo sencillo)"));
        Integer numColumns = 6;
        Integer numRows = 120;
        // We create the table (Creamos la tabla).
        PdfPTable table = new PdfPTable(numColumns);
        // Now we fill the PDF table 
        // Ahora llenamos la tabla del PDF
        PdfPCell columnHeader;
        // Fill table rows (rellenamos las filas de la tabla).                
        for (int column = 0; column < numColumns; column++) {
            columnHeader = new PdfPCell(new Phrase("COL " + column));
            columnHeader.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(columnHeader);
        }
        table.setHeaderRows(1);
        // Fill table rows (rellenamos las filas de la tabla).                
        for (int row = 0; row < numRows; row++) {
            for (int column = 0; column < numColumns; column++) {
                table.addCell("Row " + row + " - Col" + column);
            }
        }
        // We add the table (Aadimos la tabla)
        paragraphMore.add(table);
        // We add the paragraph with the table (Aadimos el elemento con la tabla).
        document.add(chapTitle);
        document.close();
        System.out.println("Your PDF file has been generated!(Se ha generado tu hoja PDF!");
    } catch (DocumentException documentException) {
        System.out.println(
                "The file not exists (Se ha producido un error al generar un documento): " + documentException);
    }
}