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:gov.utah.dts.det.ccl.actions.reports.generators.LicenseRenewalLettersReport.java

public static ByteArrayOutputStream generate(java.util.List<FacilityLicenseView> licenses) {
    ByteArrayOutputStream ba = null;
    FacilityLicenseView license;//from  w w w.j  a va2 s  . co  m
    Document document = null;
    Date today = new Date();
    try {
        ba = new ByteArrayOutputStream();
        document = new Document(PageSize.LETTER, 75, 75, 175, 50);
        PdfWriter writer = PdfWriter.getInstance(document, ba);

        document.open();

        if (licenses != null && licenses.size() > 0) {
            for (int i = 0; i < licenses.size(); i++) {
                license = licenses.get(i);
                generateDocumentPage(license, today, document, writer);
                // If there is another letter to print add a new page to the document
                if (i < licenses.size() - 1) {
                    document.newPage();
                }
            }
        } else {
            Paragraph paragraph = new Paragraph(fixedLeading);
            paragraph.add(new Phrase("No renewal licenses were found to print.", mediumfont));
            document.add(paragraph);
        }

        document.close();
    } catch (Exception ex) {
        log.error(ex.getMessage());
        ba = null;
    }
    return ba;
}

From source file:gov.utah.dts.det.ccl.actions.trackingrecordscreening.letters.reports.LivescanAuthorization.java

public static ByteArrayOutputStream generate(TrackingRecordScreeningLetter screeningLetter) {
    ByteArrayOutputStream ba = null;
    Document document = null;
    try {/*from www.  ja  v a2 s. co m*/
        ba = new ByteArrayOutputStream();
        document = new Document(PageSize.LETTER, 35, 35, 75, 0);
        PdfWriter writer = PdfWriter.getInstance(document, ba);

        document.open();

        // LS Authorization Letter Page 1
        generateDocumentPage1(screeningLetter, document, writer);

        // Shift to page 2
        document.newPage();

        // LS Authorization Letter Page 2
        generateDocumentPage2(screeningLetter, document, writer);

        document.close();
    } catch (Exception ex) {
        log.error(ex.getMessage());
        ba = null;
    }
    return ba;
}

From source file:gov.utah.dts.det.ccl.actions.trackingrecordscreening.letters.reports.LivescanAuthorizationB1591.java

public static ByteArrayOutputStream generate(TrackingRecordScreeningLetter screeningLetter) {
    ByteArrayOutputStream ba = null;
    Document document = null;
    try {//from   ww w.ja va  2s . c  om
        ba = new ByteArrayOutputStream();
        document = new Document(PageSize.LETTER, 30, 30, 100, 25);
        PdfWriter writer = PdfWriter.getInstance(document, ba);

        document.open();

        // LS Authorization Letter Page 1
        generateDocumentPage1(screeningLetter, document, writer);

        // Shift to page 2
        document.newPage();

        // LS Authorization Letter Page 2
        generateDocumentPage2(screeningLetter, document, writer);

        document.close();
    } catch (Exception ex) {
        log.error(ex.getMessage());
        ba = null;
    }
    return ba;
}

From source file:gravabncertificado.GerandoArquivoCarimbado_1.java

public static void GerandoArquivoCarimbadoPDF(String caminhoarquivo, String BN) throws InvalidPdfException {
    //Copiando arquivo informado.
    try {//  w ww  .ja v  a2  s .c o  m

        // Adicionado parametro para nao retornar erro quando o documento for protegido.
        PdfReader.unethicalreading = true;
        //Cria o reader para o primeiro PDF

        PdfReader reader = new PdfReader(caminhoarquivo);

        // n recebe o numero total de paginas
        int n = reader.getNumberOfPages();

        //Tamanho da primeira Pagina
        ;

        //Cria Segundo PDF

        Document document = new Document(PageSize.A4, 36, 36, 36, 36);

        PdfWriter writer = PdfWriter.getInstance(document,
                new FileOutputStream(caminhoarquivo.substring(0, caminhoarquivo.length() - 4) + "-C.pdf"));

        document.open();

        // Adiciona conteudo ao PDF Carimbado.
        PdfContentByte cb = writer.getDirectContent();
        int i = 0;
        int p = 0;
        String caminhodestino = (caminhoarquivo.substring(0, caminhoarquivo.length() - BN.length()));

        // DESABILITADO PORQUE O MOVER NAO ESTAVA FUNCIONANDO.
        File destinooriginal = new File(caminhodestino + "ORIGINAL\\");
        if (!destinooriginal.exists()) {
            destinooriginal.mkdir();
        }

        caminhodestino = (caminhodestino + "ORIGINAL\\" + BN);

        //TESTANDO NOVA FORMA DE COPIAR

        File origem = new File(caminhoarquivo);
        File destino = new File(caminhodestino);

        FileInputStream fis = new FileInputStream(origem);
        FileOutputStream fos = new FileOutputStream(destino);

        FileChannel inChannel = fis.getChannel();
        FileChannel outChannel = fos.getChannel();

        long transferFrom = outChannel.transferFrom(inChannel, 0, inChannel.size());

        fis.close();
        fos.close();
        inChannel.close();
        outChannel.close();

        // Thread.sleep(10);

        BN = BN.substring(0, BN.length() - 4);

        while (i < n) {
            document.newPage();
            p++;
            i++;

            PdfContentByte under = writer.getDirectContentUnder();
            PdfImportedPage page1 = writer.getImportedPage(reader, i);
            cb.addTemplate(page1, 0, i * 0.2f);

            // Page 1: a rectangle
            /* RETANGULO DESATIVADO
            drawRectangle(under, 100, 50);
            under.setRGBColorFill(255, 220, 220);
            under.rectangle(width /50, 5, 118, 40);
            under.fill();
            */

            //CARIMBO DA BN

            BaseFont bf = BaseFont.createFont(BaseFont.COURIER_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
            cb.beginText();
            cb.setFontAndSize(bf, 14);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " ________________", width / 6, 44, 0);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |               |", width / 6, 32, 0);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |               |", width / 6, 22, 0);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " NR", width / 6, 28, 0);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " " + BN, width / 6, 16, 0);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |               |", width / 6, 12, 0);
            cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " ________________", width / 6, 14, 0);
            cb.endText();

        }

        document.close();
        writer.close();
        reader.close();
        origem.delete();

        /* PdfContentByte under = writer.getDirectContentUnder();
                 
         // Page 1: a rectangle
             drawRectangle(under, 20, 20);
             under.setRGBColorFill(0xFF, 0xD7, 0x00);
             under.rectangle(5, 5, 15, 15);
             under.fill(); */
        //document.newPage();

        //COPIANDO ARQUIVO CARIMBADO

        /* DESABILITADO PORQUE NAO ESTAVA FUNCIONANDO.
        boolean bool;
                
         //caminhoarquivo = caminhoarquivo.replace("\\", "\\\\");
         //caminhodestino = caminhodestino.replace("\\", "\\\\");
                    
        File origem = new File(caminhoarquivo);
        File destino = new File(caminhodestino);
                
                    
        bool = origem.renameTo(destino);
        System.out.println(origem);
        System.out.println(caminhodestino);
        */

    } catch (IOException | DocumentException ex) {
    }

}

From source file:gravabncertificado007.CarimboCertificado.java

public void aplicaCarimboBin(String BN, String caminhoarquivo)
        throws DocumentException, IOException, RuntimeException {

    PdfReader.unethicalreading = true;//w w w .  j  a v a2s. c  o m
    //Cria o reader para o primeiro PDF

    PdfReader reader = new PdfReader(caminhoarquivo);
    Rectangle psize = reader.getPageSize(1);
    float width = psize.getWidth();
    float height = psize.getHeight();

    Document document = new Document(new Rectangle(width, height));

    PdfWriter writer = PdfWriter.getInstance(document,
            new FileOutputStream(caminhoarquivo.substring(0, caminhoarquivo.length() - 4) + "-C.pdf"));

    document.open();

    int i = 0;
    BN = BN.substring(BN.length() - 13, BN.length() - 4);
    PdfContentByte cb = writer.getDirectContent();
    while (i < reader.getNumberOfPages()) {
        i++;

        document.newPage();

        PdfContentByte under = writer.getDirectContentUnder();
        PdfImportedPage page1 = writer.getImportedPage(reader, i);
        cb.addTemplate(page1, 0, i * 0.2f);

        //CARIMBO DA BN
        BaseFont bf = BaseFont.createFont(BaseFont.COURIER_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
        cb.beginText();
        cb.setFontAndSize(bf, 14);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " ________________", width / 6, 44, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |               |", width / 6, 32, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |               |", width / 6, 22, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " NR", width / 6, 28, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " " + BN, width / 6, 16, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |               |", width / 6, 12, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " ________________", width / 6, 14, 0);
        cb.endText();

    }

    document.close();
    writer.close();
    reader.close();

}

From source file:gravabncertificado007.CarimboCertificado.java

public void aplicaCariboGedi(String BN, String caminhoarquivo)
        throws DocumentException, IOException, RuntimeException {

    PdfReader.unethicalreading = true;//from   w w w  .  java  2s  .  co  m
    //Cria o reader para o primeiro PDF

    PdfReader reader = new PdfReader(caminhoarquivo);
    Rectangle psize = reader.getPageSize(1);
    float width = psize.getWidth();
    float height = psize.getHeight();

    Document document = new Document(new Rectangle(width, height));

    PdfWriter writer = PdfWriter.getInstance(document,
            new FileOutputStream(caminhoarquivo.substring(0, caminhoarquivo.length() - 4) + "-G.pdf"));

    document.open();

    int i = 0;
    BN = BN.substring(BN.length() - 13, BN.length() - 4);
    PdfContentByte cb = writer.getDirectContent();
    while (i < reader.getNumberOfPages()) {
        i++;

        document.newPage();

        PdfContentByte under = writer.getDirectContentUnder();
        PdfImportedPage page1 = writer.getImportedPage(reader, i);
        cb.addTemplate(page1, 0, i * 0.2f);

        BaseFont bf = BaseFont.createFont(BaseFont.COURIER_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED);
        cb.beginText();
        cb.setFontAndSize(bf, 14);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, "  _________________  ", width / 6, 44, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |                 |", width / 6, 32, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |                 |", width / 6, 22, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |Copia Controlada |", width / 6, 28, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |                 |", width / 6, 16, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |                 |", width / 6, 12, 0);
        cb.showTextAligned(PdfContentByte.ALIGN_CENTER, " |_________________|", width / 6, 14, 0);
        cb.endText();
    }

    document.close();
    writer.close();
    reader.close();

}

From source file:GUI.Carburant.java

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

    addEmptyLine(preface, 1);

    preface.add(new Paragraph(
            "Report generated by: " + System.getProperty("Car Fleet Management App") + ", " + new Date(),
            smallBold));
    addEmptyLine(preface, 3);

    preface.add(new Paragraph("Carburant details ", smallBold));

    int rowNumber = this.tableJT.getSelectedRow();

    // immatriculation
    preface.add(new Paragraph("Numero de souche : ", redFont));
    preface.add(new Paragraph(this.tableJT.getValueAt(rowNumber, 0).toString(), smallBold));

    //marque
    preface.add(new Paragraph("Immatriculation : ", redFont));
    preface.add(new Paragraph(this.tableJT.getValueAt(rowNumber, 1).toString(), smallBold));

    //etat
    preface.add(new Paragraph("Prix de bon : ", redFont));
    preface.add(new Paragraph(this.tableJT.getValueAt(rowNumber, 4).toString(), smallBold));

    addEmptyLine(preface, 3);
    preface.add(new Paragraph("Thank you for using Car Fleet Management App", smallBold));

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

From source file:GUI.Cars.java

private void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);//from w w  w  .ja va2 s .co  m
    // Lets write a big header
    preface.add(new Paragraph("Cars", catFont));

    addEmptyLine(preface, 1);

    preface.add(new Paragraph(
            "Report generated by: " + System.getProperty("Car Fleet Management App") + ", " + new Date(),
            smallBold));
    addEmptyLine(preface, 3);

    preface.add(new Paragraph("Car details ", smallBold));

    int rowNumber = this.tableJT.getSelectedRow();

    // immatriculation
    preface.add(new Paragraph("Immatriculation : ", redFont));
    preface.add(new Paragraph(this.tableJT.getValueAt(rowNumber, 0).toString(), smallBold));

    //marque
    preface.add(new Paragraph("Marque : ", redFont));
    preface.add(new Paragraph(this.tableJT.getValueAt(rowNumber, 2).toString(), smallBold));

    //etat
    preface.add(new Paragraph("Etat : ", redFont));
    preface.add(new Paragraph(this.tableJT.getValueAt(rowNumber, 9).toString(), smallBold));

    addEmptyLine(preface, 3);
    preface.add(new Paragraph("Thank you for using Car Fleet Management App", smallBold));

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

From source file:GUI.Fixings.java

private void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);/* www.  j  a  v a2  s.c  om*/
    // Lets write a big header
    preface.add(new Paragraph("Fixing", catFont));

    addEmptyLine(preface, 1);

    preface.add(new Paragraph(
            "Report generated by: " + System.getProperty("Car Fleet Management App") + ", " + new Date(),
            smallBold));
    addEmptyLine(preface, 3);

    preface.add(new Paragraph("Fixing details ", smallBold));

    int rowNumber = this.tableJT.getSelectedRow();

    // immatriculation
    preface.add(new Paragraph("Numero de souche : ", redFont));
    preface.add(new Paragraph(this.tableJT.getValueAt(rowNumber, 0).toString(), smallBold));

    //marque
    preface.add(new Paragraph("Fournisseur : ", redFont));
    preface.add(new Paragraph(this.tableJT.getValueAt(rowNumber, 1).toString(), smallBold));

    //etat
    preface.add(new Paragraph("Immatriculation : ", redFont));
    preface.add(new Paragraph(this.tableJT.getValueAt(rowNumber, 3).toString(), smallBold));

    addEmptyLine(preface, 3);
    preface.add(new Paragraph("Thank you for using Car Fleet Management App", smallBold));

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

From source file:GUI_StafKlinik.Panel_Penggajian.java

private void createPdf(List<Penggajian> list) {
    JFileChooser saveFile = new JFileChooser();
    saveFile.setSelectedFile(new File("D:/document/Slip Gaji.pdf"));
    String result = null;/*from w w w . j  a  v a 2 s .  c om*/
    if (saveFile.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
        result = saveFile.getSelectedFile().toString();
    } else {
        System.out.println("No Selection ");
    }
    try {
        Document document = new Document();
        try {
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(result));
            document.open();
            PdfContentByte canvas = writer.getDirectContent();

            for (int i = 0; i < list.size(); i++) {
                document.newPage();
                Rectangle rect = new Rectangle(50, 800, 550, 700);
                rect.setBorder(Rectangle.BOX);
                rect.setBorderWidth(0);
                rect.setBorderColor(BaseColor.BLACK);
                canvas.rectangle(rect);
                Paragraph preface;
                preface = getPreface("Slip Gaji");
                document.add(preface);
                document.add(Chunk.NEWLINE);
                document.add(Chunk.NEWLINE);
                document.add(createTableLaporan(list.get(i)));
            }
            document.close();
            open(result);
        } catch (DocumentException ex) {
            Logger.getLogger(Panel_Laporan_Keuangan.class.getName()).log(Level.SEVERE, null, ex);
        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(Panel_Laporan_Keuangan.class.getName()).log(Level.SEVERE, null, ex);
    }
}