Example usage for com.itextpdf.text Document newPage

List of usage examples for com.itextpdf.text Document newPage

Introduction

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

Prototype


public boolean newPage() 

Source Link

Document

Signals that an new page has to be started.

Usage

From source file:PDFmaker.java

private static void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);/*from ww  w  .  j  a  va  2 s  .  c o m*/
    // Lets write a big header
    preface.add(new Paragraph("Productielijst", catFont));

    addEmptyLine(preface, 1);
    // Will create: Report generated by: _name, _date
    preface.add(
            new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + LocalDate.now(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    smallBold));
    //        addEmptyLine(preface, 3);
    //        preface.add(new Paragraph(
    //                "This document describes something which is very important ",
    //                smallBold));
    //
    //        addEmptyLine(preface, 8);
    //
    //        preface.add(new Paragraph(
    //                "This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).",
    //                redFont));    
    document.add(preface);
    // Start a new page
    document.newPage();
}

From source file:Pdfsave.java

private static void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);//from w  w  w  .j a  v  a 2  s  .  com
    // Lets write a big header
    preface.add(new Paragraph("Title of the document", catFont));

    addEmptyLine(preface, 1);
    // Will create: Report generated by: _name, _date
    preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            smallBold));
    addEmptyLine(preface, 3);
    preface.add(new Paragraph("This document describes something which is very important ", smallBold));

    addEmptyLine(preface, 8);

    preface.add(new Paragraph(
            "This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).",
            redFont));

    document.add(preface);
    // Start a new page
    document.newPage();
}

From source file:pdf_demo2.java

private static void addTitlePage(Document document) throws DocumentException {
    Paragraph paragraph = new Paragraph();
    // We add one empty line
    addEmptyLine(paragraph, 1);/*  w  w  w . j  av a 2  s .c  o m*/
    // Lets write a big header
    paragraph.add(new Paragraph("Title of the document", titleFont));

    addEmptyLine(paragraph, 1);
    // Will create: Report generated by: _name, _date
    paragraph.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(),
            smallBold));
    addEmptyLine(paragraph, 3);
    paragraph.add(new Paragraph("This document describes something which is very important ", smallBold));

    addEmptyLine(paragraph, 8);
    paragraph.add(
            new Paragraph("This document is a preliminary version and not subject to your license agreement "
                    + "or any other agreement with vogella.com ;-).", redFont));

    document.add(paragraph);
    // Start a new page
    document.newPage();
}

From source file:adams.flow.transformer.pdfproclet.DocumentState.java

License:Open Source License

/**
 * Adds a new page only if none has been added so far.
 *
 * @param doc      the document to add the page to
 * @return      true if successfully added (or not necessary)
 *//*from w ww .  ja  va 2s .c o m*/
public boolean newPage(Document doc) {
    boolean result;

    result = true;

    if (!isNewPage()) {
        result = doc.newPage();
        if (result)
            newPageAdded();
    }

    return result;
}

From source file:app.logica.gestores.GestorPDF.java

License:Open Source License

/**
  * Mtodo para crear un PDF a partir de varias pantalla.
  */*from   www . j a va 2s.  c om*/
  * @param pantallaAPDF
  *            pantalla que se imprimir en PDF
  * @return PDF de una captura de la pantalla pasada
  */
 private PDF generarPDF(ArrayList<Node> pantallasAPDF) throws Exception {
     Document document = new Document();
     ByteArrayOutputStream pdfbaos = new ByteArrayOutputStream();
     PdfWriter escritor = PdfWriter.getInstance(document, pdfbaos);
     document.open();

     for (Node pantalla : pantallasAPDF) {
         new Scene((Parent) pantalla);
         WritableImage image = pantalla.snapshot(new SnapshotParameters(), null);
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", baos);
         byte[] imageInByte = baos.toByteArray();
         baos.flush();
         baos.close();
         Image imagen = Image.getInstance(imageInByte);
         imagen.setAbsolutePosition(0, 0);
         imagen.scaleToFit(PageSize.A4.getWidth(), PageSize.A4.getHeight());
         document.add(imagen);
         document.newPage();
     }

     document.close();

     byte[] pdfBytes = pdfbaos.toByteArray();
     pdfbaos.flush();
     escritor.close();
     pdfbaos.close();
     return (PDF) new PDF().setArchivo(pdfBytes);
 }

From source file:be.rheynaerde.poolsheets.AbstractPoolSheet.java

License:Open Source License

protected void buildSheet() throws DocumentException {
    Rectangle pageSize = configuration.isLandscape(AbstractPoolSheetConfiguration.TITLE_PAGE)
            ? PageSize.A4.rotate()/*from   w w w.  j  a va2 s.  com*/
            : PageSize.A4;
    Document document = new Document(pageSize);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter.getInstance(document, baos);

    document.open();
    document.addTitle(configuration.getTitle());
    document.addCreator(CREATOR);

    buildTitle(document);
    buildTable(document);

    if (configuration.includeOrderOfBouts()) {
        if (configuration.putBoutOrderOnNewPage()) {
            pageSize = configuration.isLandscape(AbstractPoolSheetConfiguration.BOUT_ORDER_PAGE)
                    ? PageSize.A4.rotate()
                    : PageSize.A4;
            document.setPageSize(pageSize);
            document.newPage();
        }

        buildBoutOrder(document);
    }

    document.close();
    sheet = baos.toByteArray();
}

From source file:be.roots.taconic.pricingguide.util.iTextUtil.java

License:Open Source License

public static byte[] emptyPage() throws DocumentException, IOException {

    try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
        final Document document = createNewDocument();

        final PdfWriter pdfWriter = PdfWriter.getInstance(document, baos);
        document.open();// w w  w .j a  v a2  s  . c  o m
        document.newPage();
        pdfWriter.setPageEmpty(false);
        document.close();
        return baos.toByteArray();
    }
}

From source file:be.zenodotus.creatie.GeneratePDF.java

License:Open Source License

public String vakantieAfdruk(Context context, String name, int jaar) {
    this.context = context;
    PdfWriter w = null;/*from  w ww .  ja v  a  2s.  c o  m*/
    Document d = new Document(PageSize.A4.rotate(), 5, 5, 10, 10);
    d.setPageCount(3);
    String fileName = name;
    String file = name;
    GregorianCalendar datum = new GregorianCalendar();
    datum.set(GregorianCalendar.YEAR, jaar);

    String[] maanden = { "Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus",
            "September", "Oktober", "November", "December" };
    int[] dagen = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    VerlofDao dao = new VerlofDao(context);
    FeestdagDao feestdagDao = new FeestdagDao(context);
    WerkdagDao werkdagDao = new WerkdagDao(context);
    File folder = new File(context.getFilesDir(), "pdfs");
    folder.mkdirs();
    if (datum.isLeapYear(jaar)) {
        dagen[1] = 29;
    }
    File temp = null;
    temp = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
            "Jacqueline" + jaar + ".pdf");
    fileName = temp.toString();
    try {
        dao.open();
        ArrayList<Verlof> verloflijst = dao.getAlleVerlovenPerJaar(jaar);
        w = PdfWriter.getInstance(d, new FileOutputStream(temp));
        d.open();
        d.addAuthor("Jacqueline Vandenbroecke");
        d.addCreationDate();
        d.addCreator("Verlofplanner");
        d.addTitle("Vakantie " + jaar + " van Jacqueline Vandenbroecke");
        Font standaard = FontFactory.getFont(FontFactory.HELVETICA, 8);
        Font standaardBold = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.BOLD);
        Paragraph gegeven = new Paragraph("Jacqueline Vandenbroecke Verlof " + jaar + "\n", standaardBold);
        gegeven.setAlignment(Paragraph.ALIGN_CENTER);
        d.add(gegeven);

        for (int paginas = 0; paginas < 2; paginas++) {
            int aantal = 0;
            if (paginas == 1) {
                d.newPage();
                aantal = 6;
            }
            PdfPTable table = new PdfPTable(6);
            for (int i = aantal; i < (aantal + 6); i++) {
                PdfPCell cell = new PdfPCell(new Paragraph(maanden[i], standaardBold));
                cell.setBorder(1);
                table.addCell(cell);
            }
            int dag = 1;
            int k = aantal;
            for (int i = aantal; i < (aantal + 6); i++) {
                for (int j = 0; j < 32; j++) {
                    if (k > ((aantal + 6) - 1)) {
                        k = aantal;
                        dag++;
                    }
                    if (dag > dagen[k]) {
                        PdfPCell cell = new PdfPCell(new Paragraph("", standaard));
                        table.addCell(cell);
                        k++;
                    } else {
                        SimpleDateFormat formatterDag = new SimpleDateFormat("dd");
                        SimpleDateFormat formatterWeek = new SimpleDateFormat("EEE");
                        datum.set(jaar, k, dag);
                        PdfPTable dagTabel = new PdfPTable(4);
                        PdfPCell cellDag = new PdfPCell(
                                new Paragraph(formatterDag.format(datum.getTime()), standaard));
                        PdfPCell cellWeek = new PdfPCell(
                                new Paragraph(formatterWeek.format(datum.getTime()), standaard));
                        ArrayList<Verlof> verlof = new ArrayList<Verlof>();
                        for (int z = 0; z < verloflijst.size(); z++) {
                            if (((verloflijst.get(z).getDag() + 1) == dag)
                                    && (verloflijst.get(z).getMaand() == k)) {
                                verlof.add(verloflijst.get(z));

                            }
                        }
                        feestdagDao.open();
                        Feestdag feestdag = feestdagDao.getFeestdag(jaar, datum.get(GregorianCalendar.MONTH),
                                datum.get(GregorianCalendar.DATE));
                        feestdagDao.close();
                        werkdagDao.open();
                        java.util.List<Werkdag> weekend = werkdagDao.getWeekend();
                        werkdagDao.close();
                        String Verlof = "";
                        String uur = "";
                        if (verlof.size() > 0) {
                            if (verlof.size() > 1) {
                                Verlof = verlof.get(0).getVerlofsoort() + "\n" + verlof.get(1).getVerlofsoort();
                                uur = verlof.get(0).getUrental() + "\n" + verlof.get(1).getUrental();
                            } else {
                                Verlof = verlof.get(0).getVerlofsoort();
                                uur = verlof.get(0).getUrental();
                            }

                        }
                        PdfPCell cellVerlof = new PdfPCell(new Paragraph(Verlof, standaard));
                        PdfPCell uren = new PdfPCell(new Paragraph(uur, standaard));
                        if (verlof.size() > 0) {
                            BaseColor kleur = new BaseColor(Color.GRAY);
                            cellVerlof.setBackgroundColor(kleur);
                            uren.setBackgroundColor(kleur);
                            cellDag.setBackgroundColor(kleur);
                            cellWeek.setBackgroundColor(kleur);
                        }
                        for (int z = 0; z < weekend.size(); z++) {
                            if ((formatterWeek.format(datum.getTime())).equals(weekend.get(z).getDag())) {
                                BaseColor kleur = new BaseColor(Color.LTGRAY);
                                cellVerlof.setBackgroundColor(kleur);
                                uren.setBackgroundColor(kleur);
                                cellDag.setBackgroundColor(kleur);
                                cellWeek.setBackgroundColor(kleur);
                            }
                        }
                        if (feestdag != null) {
                            BaseColor kleur = new BaseColor(Color.GREEN);
                            uren.setBackgroundColor(kleur);
                            cellVerlof.setBackgroundColor(kleur);
                            uren.setBackgroundColor(kleur);
                            cellDag.setBackgroundColor(kleur);
                            cellWeek.setBackgroundColor(kleur);
                        }
                        dagTabel.addCell(cellDag);
                        dagTabel.addCell(cellWeek);
                        dagTabel.addCell(cellVerlof);
                        dagTabel.addCell(uren);
                        table.addCell(dagTabel);
                        k++;
                    }
                }

            }
            d.add(table);
            dao.close();
        }
    } catch (Exception ex) {

        ex.printStackTrace();

    } finally {
        d.close();
        w.close();
    }
    return fileName;
}

From source file:bl.pdf.PDFFile.java

@SuppressWarnings("unused")
private void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);/*from w w w.  j  av a  2  s.  c  om*/
    // Lets write a big header
    preface.add(new Paragraph("Title of the document", catFont));

    addEmptyLine(preface, 1);
    // Will create: Report generated by: _name, _date
    preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            smallBold));
    addEmptyLine(preface, 3);
    preface.add(new Paragraph("This document describes something which is very important ", smallBold));

    addEmptyLine(preface, 8);

    preface.add(new Paragraph(
            "This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).",
            redFont));

    document.add(preface);
    // Start a new page
    document.newPage();
}

From source file:bouttime.report.boutsequence.BoutSequenceReport.java

License:Open Source License

public static boolean generateReport(Dao dao, String session) {
    if (!dao.isOpen()) {
        return false;
    }/*from   w  w  w  . j  av  a  2  s .co  m*/

    if (session != null) {
        session = session.trim();
    }

    List<String> teams = dao.getTeams();
    if ((teams == null) || teams.isEmpty()) {
        logger.warn("Cannot generate report : no teams");
        return false;
    }

    // step 1: creation of a document-object
    Document document = new Document();

    int pages = 0;
    try {

        // step 2: creation of the writer
        FileOutputStream fos = createOutputFile();
        if (fos == null) {
            return false;
        }
        PdfWriter.getInstance(document, fos);

        // step 3: we open the document
        document.open();

        // step 4: create and add content
        for (String team : teams) {
            List<Wrestler> wrestlers = dao.getWrestlersByTeam(team);
            if ((wrestlers == null) || wrestlers.isEmpty()) {
                logger.warn("No wrestlers for team : " + team);
                continue;
            }

            PdfPTable datatable = addBoutSequences(wrestlers, session);
            if (datatable != null) {
                addHeader(dao, document, team, session);
                document.add(datatable);
                document.newPage();
                pages++;
            }
        }

    } catch (DocumentException de) {
        logger.error("Document Exception", de);
        document.close();
        return false;
    }

    if (pages == 0) {
        logger.warn("No pages in report for.");
        // Closing the document with no pages will result in IOException
        return false;
    }

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

    return true;
}