Example usage for com.lowagie.text Chunk NEWLINE

List of usage examples for com.lowagie.text Chunk NEWLINE

Introduction

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

Prototype

Chunk NEWLINE

To view the source code for com.lowagie.text Chunk NEWLINE.

Click Source Link

Document

This is a Chunk containing a newline.

Usage

From source file:org.sonarqube.report.extendedpdf.OverviewPDFReporter.java

License:Open Source License

private void printChapter(Document document, String chapterName) throws DocumentException, IOException {
    Paragraph title = new Paragraph(getTextProperty("extendedpdf." + chapterName), Style.CHAPTER_FONT);
    ChapterAutoNumber chapter = new ChapterAutoNumber(title);
    chapter.setTriggerNewPage(true);/*from  w ww  . j a  va2s .c  om*/
    chapter.add(new Paragraph(getTextProperty("extendedpdf.misc.text"), Style.NORMAL_FONT));
    chapter.add(Chunk.NEWLINE);
    for (String sectionName : getConfigProperty(chapterName + ".sections").split(",")) {
        printChapterSection(chapter, sectionName);
    }
    document.add(chapter);
}

From source file:org.sonarqube.report.extendedpdf.OverviewPDFReporter.java

License:Open Source License

private void printChapterSection(ChapterAutoNumber chapter, String sectionName)
        throws DocumentException, IOException {
    String sectionDisplayName = getTextProperty("extendedpdf." + sectionName);
    String imagePath = screenshotsDir + File.separator + sectionName + ".png";
    File file = new File(imagePath);
    if (file.exists() && !file.isDirectory()) {
        Section section = chapter.addSection(new Paragraph(sectionDisplayName, Style.TITLE_FONT));
        Image image = Image.getInstance(imagePath);
        section.add(image);//from   w ww  .  j  a  va2 s  .c  o  m
        section.add(Chunk.NEWLINE);
    }
}

From source file:org.tellervo.desktop.print.BasicBoxLabel.java

License:Open Source License

public void generateBoxLabel(OutputStream output) {

    try {// w  ww.jav  a2 s .c om

        PdfWriter writer = PdfWriter.getInstance(document, output);

        document.setPageSize(PageSize.LETTER);

        document.open();

        cb = writer.getDirectContent();

        // Set basic metadata
        document.addAuthor("Tellervo");
        document.addSubject("Tellervo Box Labels");

        PdfPTable table = new PdfPTable(2);
        table.setTotalWidth(495f);
        table.setLockedWidth(true);

        for (WSIBox b : boxlist) {
            Paragraph p = new Paragraph();

            p.add(new Chunk(b.getTitle() + Chunk.NEWLINE, labelTitleFont));
            p.add(new Chunk(Chunk.NEWLINE + b.getComments() + Chunk.NEWLINE, bodyFont));
            p.add(new Chunk(App.getLabName() + Chunk.NEWLINE + Chunk.NEWLINE, bodyFont));
            p.add(new Chunk(this.getBarCode(b), 0, 0, true));

            PdfPCell cell = new PdfPCell(p);
            cell.setPaddingLeft(15f);
            cell.setPaddingRight(15f);
            cell.setBorderColor(Color.LIGHT_GRAY);

            table.addCell(cell);

        }

        PdfPCell cell = new PdfPCell(new Paragraph());
        cell.setBorderColor(Color.LIGHT_GRAY);

        table.addCell(cell);
        document.add(table);
        document.close();

        /*float top = document.top(15);
        int row = 1;
                
        for(int i = 0; i< boxlist.size(); i = i+2)
        {
                   
           log.debug("Document left : "+document.left());
           log.debug("Document right: "+document.right());
           log.debug("Top           : "+top);
                   
                   
                   
                   
                   
                   
          // Column 1      
          ColumnText ct1a = new ColumnText(cb);
          ct1a.setSimpleColumn(document.left(), 
                   top-210, 
                   368, 
                   top, 
                   20, 
                   Element.ALIGN_LEFT);
                  
          ColumnText ct1b = new ColumnText(cb);
          ct1b.setSimpleColumn(document.left(), 
             top-70, 
             document.left()+206, 
             top-150, 
             20, 
             Element.ALIGN_LEFT);
                  
          try{
        WSIBox b1 = boxlist.get(i);
        ct1a.addText(getTitlePDF(b1));
        ct1a.go();
                     
                
        ct1b.addElement(getBarCode(b1));
        ct1b.go();
                
          } catch (Exception e)
          {
             log.debug("Failed writing box label in left column where i="+i);
          }
                  
                  
          // Column 2      
          ColumnText ct2a = new ColumnText(cb);
          ct2a.setSimpleColumn(306, 
                   top-210, 
                   document.right(), 
                   top, 
                   20, 
                   Element.ALIGN_LEFT);
                  
          ColumnText ct2b = new ColumnText(cb);
          ct2b.setSimpleColumn(306, 
             top-70, 
             512,  
             top-80, 
             20, 
             Element.ALIGN_LEFT);
                  
          try{
        WSIBox b2 = boxlist.get(i+1);
        ct2a.addText(getTitlePDF(b2));
        ct2a.go();
                     
                
        ct2b.addElement(getBarCode(b2));
        ct2b.go();
                
          } catch (Exception e)
          {
             log.debug("Failed writing box label in right column where i="+i);
             //e.printStackTrace();
          }
                  
                  
          // Column 2
        /*   ColumnText ct2 = new ColumnText(cb);
          ct2.setSimpleColumn(370,     //llx 
          top-100,            //lly   
          document.right(0),   //urx
          top+15,            //ury
          20,               //leading
          Element.ALIGN_RIGHT  //alignment
          );
                  
          try{
          WSIBox b2 = boxlist.get(i+1);
          ct2.addText(getTitlePDF(b2));
          ct2.addElement(getBarCode(b2));
          ct2.go();
          } catch (Exception e)
          {
             log.debug("Failed writing box label where i="+i+1);
          }
          */
        /*
                
        top = top-160;
                
        if(row==5)
        {
           top = document.top(15);
        document.newPage();
        row=1;
        }
        else
        {
           row++;
        }
                
                
                
                
                
        }*/

    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    }

    // Close the document
    document.close();
}

From source file:questions.compression.CompressionLevelsWriter.java

public static void createPdf(int compressionLevel) {
    try {//  w ww .  j av a2s .  c o  m
        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT[compressionLevel + 1]));
        writer.setCompressionLevel(compressionLevel);
        document.open();
        BufferedReader reader = new BufferedReader(new FileReader(RESOURCE));
        String line;
        Paragraph p;
        while ((line = reader.readLine()) != null) {
            p = new Paragraph(line);
            p.setAlignment(Element.ALIGN_JUSTIFIED);
            document.add(p);
            document.add(Chunk.NEWLINE);
        }
        reader.close();
        document.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}

From source file:questions.separators.SeparatedWords2.java

public static void main(String[] args) {
    Document document = new Document();
    try {/*from  w w w  .  j  a  v  a  2s  . c o  m*/
        PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        document.open();

        Phrase p;
        Chunk separator = new Chunk(new LineSeparator(0.5f, 70, Color.RED, Element.ALIGN_CENTER, 3));
        for (int i = 0; i < 40; i++) {
            p = new Phrase("TEST");
            p.add(separator);
            p.add(new Chunk(String.valueOf(i)));
            p.add(separator);
            p.add(new Chunk(String.valueOf(i * 2)));
            p.add(separator);
            p.add(new Chunk(WORDS[39 - i]));
            p.add(separator);
            p.add(new Chunk(String.valueOf(i * 4)));
            p.add(separator);
            p.add(new Chunk(WORDS[i]));
            document.add(p);
            document.add(Chunk.NEWLINE);
        }
        document.close();
    } catch (Exception de) {
        de.printStackTrace();
    }
}

From source file:questions.stamppages.BookmarksToTOC1.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {//ww  w  .  jav  a  2 s .  c  om
        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
        writer.setPageEvent(new ParagraphBookmarkEvents(false));
        document.open();
        BufferedReader reader = new BufferedReader(new FileReader(RESOURCE));
        String line;
        Paragraph p;
        while ((line = reader.readLine()) != null) {
            p = new Paragraph(line);
            p.setAlignment(Element.ALIGN_JUSTIFIED);
            document.add(p);
            document.add(Chunk.NEWLINE);
        }
        reader.close();
        document.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }

    try {
        PdfReader reader = new PdfReader(baos.toByteArray());
        Rectangle rect = reader.getPageSizeWithRotation(1);
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT));
        stamper.insertPage(1, rect);
        ColumnText column = new ColumnText(stamper.getOverContent(1));
        column.setSimpleColumn(rect.getLeft(36), rect.getBottom(36), rect.getRight(36), rect.getTop(36));
        column.addElement(new Paragraph("TABLE OF CONTENTS"));
        List<Map> list = SimpleBookmark.getBookmark(reader);
        Chunk link;
        PdfAction action;
        String info;
        int p = 1;
        float y = 10;
        for (Map<String, String> bookmark : list) {
            link = new Chunk(bookmark.get("Title"));
            info = bookmark.get("Page");
            p = Integer.parseInt(info.substring(0, info.indexOf(' ')));
            y = Float.parseFloat(info.substring(info.lastIndexOf(' ') + 1) + "f");
            action = PdfAction.gotoLocalPage(p, new PdfDestination(PdfDestination.FITH, y),
                    stamper.getWriter());
            link.setAction(action);
            column.addElement(new Paragraph(link));
        }
        column.go();
        stamper.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }

}

From source file:questions.stamppages.BookmarksToTOC2.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {/*from  w  w  w  .ja  v  a  2s .com*/
        Document document = new Document();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        writer.setViewerPreferences(PdfWriter.PageModeUseOutlines);
        writer.setPageEvent(new ParagraphBookmarkEvents(true));
        document.open();
        BufferedReader reader = new BufferedReader(new FileReader(RESOURCE));
        String line;
        Paragraph p;
        while ((line = reader.readLine()) != null) {
            p = new Paragraph(line);
            p.setAlignment(Element.ALIGN_JUSTIFIED);
            document.add(p);
            document.add(Chunk.NEWLINE);
        }
        reader.close();
        document.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }

    try {
        PdfReader reader = new PdfReader(baos.toByteArray());
        Rectangle rect = reader.getPageSizeWithRotation(1);
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT));
        stamper.insertPage(1, rect);
        ColumnText column = new ColumnText(stamper.getOverContent(1));
        column.setSimpleColumn(rect.getLeft(36), rect.getBottom(36), rect.getRight(36), rect.getTop(36));
        column.addElement(new Paragraph("TABLE OF CONTENTS"));
        List<Map> list = SimpleBookmark.getBookmark(reader);
        Chunk link;
        String dest;
        for (Map<String, String> bookmark : list) {
            link = new Chunk(bookmark.get("Title"));
            dest = bookmark.get("Named");
            link.setAction(PdfAction.gotoLocalPage(dest, false));
            column.addElement(new Paragraph(link));
        }
        column.go();
        stamper.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }

}

From source file:rollyroll.com.servlet.ModuloServlet.java

private void exportar_ModulosaPDF(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    try {//w  w w . j  av a 2 s . c  o  m
        //            String[] headers = new String[]{"CODIGO", "NOMBRE", "ACCION", "ORDEN", "ICONO", "ESTADO"};
        String[] headers = new String[] { "NOMBRE", "ACCION", "ICONO" };

        ArrayList<Modulo> lista = null;
        lista = moduloService.listar_Modulos();

        PdfPTable table = new PdfPTable(headers.length);
        table.setHorizontalAlignment(0);
        table.setWidthPercentage(95);
        float[] espaciocolumna = new float[] { 25f, 38f, 50f };
        table.setWidths(espaciocolumna);
        for (int i = 0; i < headers.length; i++) {
            String header = headers[i];
            PdfPCell cell = new PdfPCell();
            cell.setBackgroundColor(Color.YELLOW);
            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            cell.setPhrase(new Phrase(header.toUpperCase(), new Font(Font.HELVETICA, 10, Font.BOLD)));
            table.addCell(cell);
        }
        table.completeRow();
        PdfPCell cell;

        //            int codigomodulo = 0;
        String nombremodulo = "";
        String accionmodulo = "";
        //            int ordenmodulo = 0;
        String iconomodulo = "";
        //            int estadomodulo = 0;

        for (Modulo modulo : lista) {
            //                codigomodulo += Integer.parseInt(modulo.getCodigomodulo());
            nombremodulo += modulo.getNombremodulo();
            accionmodulo += modulo.getAccionmodulo();
            //                ordenmodulo += Integer.parseInt(modulo.getOrdenmoduloS());
            iconomodulo += modulo.getIconomodulo();
            //                estadomodulo += Byte.parseByte(modulo.getEstadomoduloS());

            //                cell = new PdfPCell();
            //                cell.setPhrase(new Phrase(modulo.getCodigomoduloS(), new Font(Font.HELVETICA, 10, Font.NORMAL)));
            //                cell.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
            //                table.addCell(cell);
            //                
            cell = new PdfPCell();
            cell.setPhrase(new Phrase(modulo.getNombremodulo(), new Font(Font.HELVETICA, 10, Font.NORMAL)));
            cell.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
            table.addCell(cell);

            cell = new PdfPCell();
            cell.setPhrase(new Phrase(modulo.getAccionmodulo(), new Font(Font.HELVETICA, 10, Font.NORMAL)));
            cell.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
            table.addCell(cell);

            //                cell = new PdfPCell();
            //                cell.setPhrase(new Phrase(modulo.getOrdenmoduloS(), new Font(Font.HELVETICA, 10, Font.NORMAL)));
            //                cell.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
            //                table.addCell(cell);
            cell = new PdfPCell();
            cell.setPhrase(new Phrase(modulo.getIconomodulo(), new Font(Font.HELVETICA, 10, Font.NORMAL)));
            cell.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
            table.addCell(cell);

            //                cell = new PdfPCell();
            //                cell.setPhrase(new Phrase(modulo.getEstadomoduloS(), new Font(Font.HELVETICA, 10, Font.NORMAL)));
            //                cell.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
            //                table.addCell(cell);
        }

        table.completeRow();

        //incia diseo de documento exportado
        Document document = new Document(PageSize.A4.rotate(), 20, 5, 5, 5);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter.getInstance(document, baos);
        document.open();

        document.addTitle("Reporte de Ventas Generales");
        document.add(
                new Paragraph("Reporte: Ventas Generales 2016", new Font(Font.HELVETICA, 16, Font.UNDERLINE)));
        document.add(new Paragraph("_"));
        document.add(table);
        document.add(Chunk.NEWLINE);
        document.add(new Paragraph(
                "Leyenda: AB: Inicio, BA: Retorno (Importante: No se consideran unidades sin GPS)"));
        document.addAuthor("Quispe Roque Alex Christian");

        table = new PdfPTable(4);
        table.setHorizontalAlignment(0);
        table.setWidthPercentage(40);
        espaciocolumna = new float[] { 10f, 40f, 20f, 20f };
        table.setWidths(espaciocolumna);

        cell = new PdfPCell();
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setPhrase(new Phrase("RESUMEN", new Font(Font.HELVETICA, 10, Font.BOLD)));
        cell.setColspan(7);
        table.addCell(cell);
        table.completeRow();

        //aqui iniciamos asignacion de datos
        //===================================================================
        //            cell = new PdfPCell();
        //            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        //            cell.setPhrase(new Phrase("", new Font(Font.HELVETICA, 10, Font.BOLD)));
        //            table.addCell(cell);
        //
        //            cell = new PdfPCell();
        //            cell.setBackgroundColor(Color.yellow);
        //            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        //            cell.setPhrase(new Phrase("FLOTA OPERATIVA", new Font(Font.HELVETICA, 10, Font.BOLD)));
        //            table.addCell(cell);
        //
        //            cell = new PdfPCell();
        //            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        //            cell.setPhrase(new Phrase(lista.size() + "", new Font(Font.HELVETICA, 10, Font.BOLD)));
        //            table.addCell(cell);
        //
        //            cell = new PdfPCell();
        //            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        //            cell.setPhrase(new Phrase("UNIDADES", new Font(Font.HELVETICA, 10, Font.BOLD)));
        //            table.addCell(cell);
        //            table.completeRow();
        //
        //            //==================================================================================
        //            cell = new PdfPCell();
        //            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        //            cell.setPhrase(new Phrase("2", new Font(Font.HELVETICA, 10, Font.BOLD)));
        //            table.addCell(cell);
        //
        //            cell = new PdfPCell();
        //            cell.setBackgroundColor(Color.yellow);
        //            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        //            cell.setPhrase(new Phrase("NRO DE VIAJES", new Font(Font.HELVETICA, 10, Font.BOLD)));
        //            table.addCell(cell);
        //
        //            cell = new PdfPCell();
        //            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        //            cell.setPhrase(new Phrase((totalAB + totalBA) + "", new Font(Font.HELVETICA, 10, Font.BOLD)));
        //            table.addCell(cell);
        //
        //            cell = new PdfPCell();
        //            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        //            cell.setPhrase(new Phrase("VIAJES", new Font(Font.HELVETICA, 10, Font.BOLD)));
        //            table.addCell(cell);
        //
        //            table.completeRow();
        //==================================================================================
        document.add(Chunk.NEWLINE);
        document.add(table);

        document.left(1);
        document.top(1);
        document.close();
        response.setHeader("Expires", "0");
        response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
        //            response.setHeader("Content-Disposition", "attachment; filename=ReporteGeneraldeModulos.pdf");
        response.setHeader("Content-Disposition", "filename=ReporteGeneraldeModulos.pdf");
        response.setHeader("Pragma", "public");
        response.setContentType("application/pdf");
        response.setContentLength(baos.size());
        ServletOutputStream out = response.getOutputStream();
        baos.writeTo(out);
        out.flush();

    } catch (Exception e) {
        RequestDispatcher rd2;
        rd2 = request.getRequestDispatcher("vista/include/error_404.jsp");
        rd2.forward(request, response);
        System.out.println(
                "rollyroll.com.servlet.ModuloServlet.exportar_ModulosaPDF() => ERROR GRAVE AL GENERAR PDF");
        e.getMessage();
    }
}

From source file:s2s.report.Report.java

License:GNU General Public License

public void writeLine() throws DocumentException {
    m_document.add(Chunk.NEWLINE);
}

From source file:uk.ac.ox.oucs.vle.resources.PDFWriter.java

License:Educational Community License

private PdfPCell nameCell(String name, String webauthId, String department) {

    Phrase phrase = new Phrase();
    phrase.add(new Chunk(name, tableNameFont));
    phrase.add(Chunk.NEWLINE);
    StringBuilder otherDetails = new StringBuilder();
    if (webauthId != null && webauthId.trim().length() > 0) {
        otherDetails.append(webauthId);/*from   w w w. j  ava 2 s  .  co m*/
    }
    if (department != null && department.trim().length() > 0) {
        if (otherDetails.length() > 0) {
            otherDetails.append(" ");
        }
        otherDetails.append(department);
    }
    phrase.add(new Chunk(otherDetails.toString(), tableOtherFont));

    PdfPCell pdfCell = new PdfPCell(phrase);
    pdfCell.setMinimumHeight(tableNameFont.getSize() * 2f);
    pdfCell.setHorizontalAlignment(Element.ALIGN_LEFT);
    pdfCell.setVerticalAlignment(Element.ALIGN_CENTER);
    pdfCell.setPaddingBottom(tableNameFont.getSize() * 0.5f);
    pdfCell.setPaddingTop(tableNameFont.getSize() * 0.5f);
    pdfCell.setPaddingLeft(tableNameFont.getSize());
    pdfCell.setPaddingRight(tableNameFont.getSize());
    return pdfCell;
}