Example usage for com.lowagie.text Document add

List of usage examples for com.lowagie.text Document add

Introduction

In this page you can find the example usage for com.lowagie.text Document add.

Prototype


public boolean add(Element element) throws DocumentException 

Source Link

Document

Adds an Element to the Document.

Usage

From source file:ch.gpb.elexis.kgexporter.pdf.PdfHandler.java

License:Open Source License

public static void createDiagnosenSheet(Patient patient, String filename, String footerText)
        throws DocumentException, IOException {

    StringBuffer sb = new StringBuffer("Diagnosen:\n");
    sb.append(patient.getDiagnosen());//w ww  . j  a  va2s  .c  o  m
    sb.append("\n");
    sb.append("Persnliche Anamnese:\n");
    sb.append(patient.getPersAnamnese());
    sb.append("\n");

    // step 1
    Document document = new Document(PageSize.A4);

    // step 2
    PdfWriter.getInstance(document, new FileOutputStream(filename));
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
    // step 3
    //Rectangle rect = new Rectangle(30, 30, 559, 800);
    writer.setBoxSize("art", rect);

    HeaderFooterPageEvent event = new HeaderFooterPageEvent();
    event.setHeaderText(
            patient.getVorname() + " " + patient.getName() + " (" + patient.getGeburtsdatum() + ")");
    event.setFooterText(footerText);
    writer.setPageEvent(event);

    document.setMargins(36, 72, 60, 60);

    // step 3
    document.open();

    document.add(new Chunk("")); // << this will do the trick. 

    if (patient.getDiagnosen().length() > 0) {
        Paragraph p = new Paragraph("Diagnosen:", fontTimesTitle);
        p.setSpacingAfter(10f);
        document.add(p);

        String[] chunksDiag = patient.getDiagnosen().toString().split("(?m)^\\s*$");
        for (String chunk : chunksDiag) {
            document.add(new Paragraph(chunk, fontTimes));
        }
    } else {
        document.add(new Paragraph("Keine Diagnosen vorhanden", fontTimes));

    }

    if (patient.getPersAnamnese().length() > 0) {
        Paragraph p = new Paragraph("Persnliche Anamnese:", fontTimesTitle);
        p.setSpacingBefore(10f);
        p.setSpacingAfter(10f);

        document.add(p);

        String[] chunksAnam = patient.getPersAnamnese().toString().split("(?m)^\\s*$");
        for (String chunk : chunksAnam) {
            document.add(new Paragraph(chunk, fontTimes));
        }
    } else {
        document.add(new Paragraph("Keine Persnliche Anamnese vorhanden", fontTimes));

    }

    // step 5
    document.close();

}

From source file:ch.gpb.elexis.kgexporter.pdf.PdfHandler.java

License:Open Source License

public static void createFixMediSheet(Patient patient, String filename, String footerText)
        throws DocumentException, IOException {
    Prescription[] prescriptions = patient.getFixmedikation();
    StringBuffer sb = new StringBuffer();
    for (Prescription prescription : prescriptions) {
        //System.out.println("Prescription: " + prescription.getLabel() + "/" + prescription.getDosis());
        sb.append(prescription.getLabel());
        sb.append("\r\n");
    }/*w  ww.j  a va  2 s.c  om*/

    // step 1
    Document document = new Document(PageSize.A4);

    // step 2
    PdfWriter.getInstance(document, new FileOutputStream(filename));
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
    // step 3
    //Rectangle rect = new Rectangle(30, 30, 559, 800);
    writer.setBoxSize("art", rect);

    HeaderFooterPageEvent event = new HeaderFooterPageEvent();
    event.setHeaderText(
            patient.getVorname() + " " + patient.getName() + " (" + patient.getGeburtsdatum() + ")");
    event.setFooterText(footerText);
    writer.setPageEvent(event);

    document.setMargins(36, 72, 60, 60);

    // step 3
    document.open();

    document.add(new Chunk("")); // << this will do the trick. 

    if (sb.length() > 0) {
        Paragraph p = new Paragraph("Fixmedikation:", fontTimesTitle);
        p.setSpacingAfter(10f);
        document.add(p);

        String[] chunksDiag = sb.toString().split("(?m)^\\s*$");
        for (String chunk : chunksDiag) {
            document.add(new Paragraph(chunk, fontTimes));
        }
    } else {

        //document.add(new Paragraph("Keine Medikationen vorhanden", fontTimes));
        Paragraph p = new Paragraph(new Chunk("Keine Medikationen vorhanden", fontTimesTitle));
        p.setSpacingBefore(20f);
        document.add(p);

    }

    // step 5
    document.close();

}

From source file:checker.ReportWriter.java

License:Open Source License

private void writePdfReport(ArrayList<String> text, String fileName) throws IOException, DocumentException {
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(fileName));
    document.open();//from w  ww  .ja va  2 s.  c  o m
    document.addTitle(getTitle());

    Paragraph paragraph = new Paragraph();
    for (String line : text) {
        if (line.equals("")) {
            paragraph.add(Chunk.NEWLINE);
        } else {
            paragraph.add(line);
            paragraph.add(Chunk.NEWLINE);
        }
    }
    document.add(paragraph);
    /*List list = new List(false);
    for (String line : text) {
       if (line.equals("")) {
    document.add(list);
    list = new List(false);
       } 
       else {
    list.add(new ListItem(line));
       }
    }*/
    //document.add(list);
    document.close();
}

From source file:classroom.filmfestival_a.Movies01.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    // step 1//  w w  w  .  ja  v  a2  s. c o  m
    Document document = new Document();
    try {
        // step 2
        PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        // step 3
        document.open();
        // step 4
        Session session = (Session) MySessionFactory.currentSession();
        Query q = session.createQuery("from FilmTitle order by title");
        java.util.List<FilmTitle> results = q.list();
        for (FilmTitle movie : results) {
            document.add(new Paragraph(movie.getTitle()));
        }
        // step 5
        document.close();
    } catch (IOException e) {
        LOGGER.error("IOException: ", e);
    } catch (DocumentException e) {
        LOGGER.error("DocumentException: ", e);
    }
}

From source file:classroom.filmfestival_a.Movies02.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    // step 1// www  . ja  va 2 s.  c  om
    Document document = new Document();
    try {
        // step 2
        PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        // step 3
        document.open();
        // step 4
        Session session = (Session) MySessionFactory.currentSession();
        Query q = session.createQuery("from FilmTitle order by title");
        java.util.List<FilmTitle> results = q.list();
        for (FilmTitle movie : results) {
            document.add(new Paragraph(movie.getTitle()));
            Set<DirectorName> directors = movie.getDirectorNames();
            List list = new List();
            for (DirectorName director : directors) {
                list.add(director.getName());
            }
            document.add(list);
        }
        // step 5
        document.close();
    } catch (IOException e) {
        LOGGER.error("IOException: ", e);
    } catch (DocumentException e) {
        LOGGER.error("DocumentException: ", e);
    }
}

From source file:classroom.filmfestival_a.Movies03.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    // step 1//from   w  w w  .java2s.  com
    Document document = new Document();
    try {
        // step 2
        PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        // step 3
        document.open();
        // step 4
        Session session = (Session) MySessionFactory.currentSession();
        Query q = session.createQuery("from FilmTitle order by title");
        java.util.List<FilmTitle> results = q.list();
        Paragraph p;
        Chunk c;
        Font bold = new Font(Font.HELVETICA, 12, Font.BOLD);
        Font italic = new Font(Font.HELVETICA, 12, Font.ITALIC);
        for (FilmTitle movie : results) {
            p = new Paragraph(30);
            c = new Chunk(movie.getTitle(), bold);
            p.add(c);
            c = new Chunk(" (" + movie.getYear() + ")", italic);
            p.add(c);
            document.add(p);
            Set<DirectorName> directors = movie.getDirectorNames();
            List list = new List();
            for (DirectorName director : directors) {
                list.add(director.getName());
            }
            document.add(list);
        }
        // step 5
        document.close();
    } catch (IOException e) {
        LOGGER.error("IOException: ", e);
    } catch (DocumentException e) {
        LOGGER.error("DocumentException: ", e);
    }
}

From source file:classroom.filmfestival_a.Movies04.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    // step 1//from w  w  w .j  a va  2s.  c o m
    Document document = new Document();
    try {
        // step 2
        PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        // step 3
        document.open();
        // step 4
        Session session = (Session) MySessionFactory.currentSession();
        Query q = session.createQuery("from FilmTitle order by title");
        java.util.List<FilmTitle> results = q.list();
        Paragraph p;
        Chunk c;
        Anchor a;
        Font bold = new Font(Font.HELVETICA, 12, Font.BOLD);
        Font italic = new Font(Font.HELVETICA, 12, Font.ITALIC);
        Font underlined = new Font(Font.HELVETICA, 12, Font.UNDERLINE, Color.BLUE);
        for (FilmTitle movie : results) {
            p = new Paragraph(20);
            c = new Chunk(movie.getTitle(), bold);
            c.setAnchor("http://cinema.lowagie.com/titel.php?id=" + movie.getFilmId());
            p.add(c);
            c = new Chunk(" (" + movie.getYear() + ") ", italic);
            p.add(c);
            a = new Anchor("IMDB", underlined);
            a.setReference("http://www.imdb.com/title/tt" + movie.getImdb());
            p.add(a);
            document.add(p);
            Set<DirectorName> directors = movie.getDirectorNames();
            List list = new List();
            for (DirectorName director : directors) {
                list.add(director.getName());
            }
            document.add(list);
        }
        // step 5
        document.close();
    } catch (IOException e) {
        LOGGER.error("IOException: ", e);
    } catch (DocumentException e) {
        LOGGER.error("DocumentException: ", e);
    }
}

From source file:classroom.filmfestival_a.Movies05.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    // step 1//from  w  w  w. j  a v  a2s.c  o  m
    Document document = new Document();
    try {
        // step 2
        OutputStream os = new FileOutputStream(RESULT);
        PdfWriter writer = PdfWriter.getInstance(document, os);
        writer.setPageEvent(new Movies05().new Ellipse());
        // step 3
        document.open();
        // step 4
        Session session = (Session) MySessionFactory.currentSession();
        Query q = session.createQuery("from FilmTitle order by title");
        java.util.List<FilmTitle> results = q.list();
        Paragraph p;
        Chunk c;
        Font bold = new Font(Font.HELVETICA, 12, Font.BOLD);
        Font italic = new Font(Font.HELVETICA, 12, Font.ITALIC);
        Font white = new Font(Font.HELVETICA, 12, Font.BOLD | Font.ITALIC, Color.WHITE);
        for (FilmTitle movie : results) {
            p = new Paragraph(20);
            c = new Chunk(movie.getTitle(), bold);
            c.setAnchor("http://cinema.lowagie.com/titel.php?id=" + movie.getFilmId());
            p.add(c);
            c = new Chunk(" (" + movie.getYear() + ") ", italic);
            p.add(c);
            c = new Chunk("IMDB", white);
            c.setAnchor("http://www.imdb.com/title/tt" + movie.getImdb());
            c.setGenericTag("ellipse");
            p.add(c);
            document.add(p);
            Set<DirectorName> directors = movie.getDirectorNames();
            List list = new List();
            for (DirectorName director : directors) {
                list.add(director.getName());
            }
            document.add(list);
        }
        // step 5
        document.close();
    } catch (IOException e) {
        LOGGER.error("IOException: ", e);
    } catch (DocumentException e) {
        LOGGER.error("DocumentException: ", e);
    }
}

From source file:classroom.filmfestival_a.Movies06.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    // step 1/*from   w w w .j a  va 2s .  c o  m*/
    Document document = new Document();
    try {
        // step 2
        PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        // step 3
        document.open();
        // step 4
        Session session = (Session) MySessionFactory.currentSession();
        Query q = session.createQuery("from FilmTitle order by title");
        java.util.List<FilmTitle> results = q.list();
        File f;
        Image img;
        Paragraph p;
        Chunk c;
        Font bold = new Font(Font.HELVETICA, 12, Font.BOLD);
        Font italic = new Font(Font.HELVETICA, 12, Font.ITALIC);
        for (FilmTitle movie : results) {
            f = new File("resources/classroom/filmposters/" + movie.getFilmId() + ".jpg");
            if (f.exists()) {
                img = Image.getInstance(f.getPath());
                document.add(img);
            }
            p = new Paragraph(20);
            c = new Chunk(movie.getTitle(), bold);
            c.setAnchor("http://cinema.lowagie.com/titel.php?id=" + movie.getFilmId());
            p.add(c);
            c = new Chunk(" (" + movie.getYear() + ") ", italic);
            p.add(c);
            c = new Chunk("IMDB");
            c.setAnchor("http://www.imdb.com/title/tt" + movie.getImdb());
            p.add(c);
            document.add(p);
            Set<DirectorName> directors = movie.getDirectorNames();
            List list = new List();
            for (DirectorName director : directors) {
                list.add(director.getName());
            }
            document.add(list);
        }
        // step 5
        document.close();
    } catch (IOException e) {
        LOGGER.error("IOException: ", e);
    } catch (DocumentException e) {
        LOGGER.error("DocumentException: ", e);
    }
}

From source file:classroom.filmfestival_a.Movies07.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    // step 1//from w w  w . ja  v a 2 s  .  co  m
    Document document = new Document();
    try {
        // step 2
        OutputStream os = new FileOutputStream(RESULT);
        PdfWriter writer = PdfWriter.getInstance(document, os);
        writer.setStrictImageSequence(true);
        // step 3
        document.open();
        // step 4
        Session session = (Session) MySessionFactory.currentSession();
        Query q = session.createQuery("from FilmTitle order by title");
        java.util.List<FilmTitle> results = q.list();
        File f;
        Image img;
        Paragraph p;
        Chunk c;
        Font bold = new Font(Font.HELVETICA, 12, Font.BOLD);
        Font italic = new Font(Font.HELVETICA, 12, Font.ITALIC);
        for (FilmTitle movie : results) {
            f = new File("resources/classroom/filmposters/" + movie.getFilmId() + ".jpg");
            if (f.exists()) {
                img = Image.getInstance(f.getPath());
                document.add(img);
            }
            p = new Paragraph(20);
            c = new Chunk(movie.getTitle(), bold);
            c.setAnchor("http://cinema.lowagie.com/titel.php?id=" + movie.getFilmId());
            p.add(c);
            c = new Chunk(" (" + movie.getYear() + ") ", italic);
            p.add(c);
            c = new Chunk("IMDB");
            c.setAnchor("http://www.imdb.com/title/tt" + movie.getImdb());
            p.add(c);
            document.add(p);
            Set<DirectorName> directors = movie.getDirectorNames();
            List list = new List();
            for (DirectorName director : directors) {
                list.add(director.getName());
            }
            document.add(list);
        }
        // step 5
        document.close();
    } catch (IOException e) {
        LOGGER.error("IOException: ", e);
    } catch (DocumentException e) {
        LOGGER.error("DocumentException: ", e);
    }
}